Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info verb for ros2topic #88

Merged
merged 9 commits into from
May 11, 2018
Merged

Info verb for ros2topic #88

merged 9 commits into from
May 11, 2018

Conversation

Nickolaim
Copy link
Contributor

@Nickolaim Nickolaim commented Apr 9, 2018

Counts publishers and subscribers. The second part of #60.

Connects to #60

Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API itself should be tested on a lower level and this case "only" ensures that the script is printing three lines. I am not sure how valuable the test will be.


from ros2topic.verb.info import InfoVerb

NODE_NAME = 'bar'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable doesn't seem to be used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is unused, deleted. Interesting that flake8 did not detect it.

Now why this code existed at some point and addressing the comment on the value of the test. So this test is not super valuable, but still useful. It will fail if node.count_subscribers() fails. That's useful. Also having a test that documents expected output is also useful. It is a reminder that changing output format will break users who do text parsing.

I tried to come with more complicated test (NODE_NAME is a leftover), but creating publisher, subscriber and calling info verb will require 2 additional threads + syncronization, and it was just too much for such trivial thing(or I just don't know how to do it simpier). Better testing is available in PR in rclpy.

count_subscribers = node.count_subscribers(topic_name)
print('Topic: %s' % topic_name)
print('Publishers count: %d' % count_publishers)
print('Subscribers count: %d' % count_subscribers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be "Publisher count" / "Subscriber count" (singular instead of plural).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

from ros2topic.verb.info import InfoVerb

NODE_NAME = 'bar'
TOPIC_NAME = '/foo'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a topic name which is specific to this test, e.g. "test_ros2_topic_cli".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@dirk-thomas dirk-thomas added in progress Actively being worked on (Kanban column) requires-changes enhancement New feature or request labels Apr 12, 2018
- Update the output text
- Rename the test topic name
- Delete obsolete code
@Nickolaim
Copy link
Contributor Author

Anything else I should do for this PR and for ros2/rclpy#183?

string_io_stdout = StringIO()
sys.stdout = string_io_stdout
yield string_io_stdout
sys.stdout = real_stdout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be replaced with contextlib.redirect_stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nickolaim
Copy link
Contributor Author

Comment addressed.

@dirk-thomas dirk-thomas added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) requires-changes labels Apr 30, 2018
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Depends on ros2/rclpy#183.

@Nickolaim
Copy link
Contributor Author

FYI: ros2/rclpy#183 has been merged.

@dirk-thomas
Copy link
Member

Thank you for adding this feature.

@dirk-thomas dirk-thomas merged commit 7e22e5e into ros2:master May 11, 2018
@dirk-thomas dirk-thomas removed the in review Waiting for review (Kanban column) label May 11, 2018
@Nickolaim Nickolaim deleted the pubsub_count3 branch June 3, 2018 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants