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

improved rospy core logger test. #1144

Merged
merged 7 commits into from
Aug 28, 2017

Conversation

asmodehn
Copy link
Contributor

now allowing to customize out/err streams for RosStreamHandler.

This is still WIP to get feedback, and we should add test for named loggers.
Throttled loggers need node to be initialized (to get the time...) so we might test them in a rostest instead (unless we can somehow remove that constraint)

FYI : I also found a mix of unix/windows endlines in rospy.core... not addressing this issue here.

now allowing to customize out/err streams for RosStreamHandler
@asmodehn
Copy link
Contributor Author

I also modified the test_rospy_client_online to check logs without relying on changing values of sys.stdout (that can be modified by anybody, anywhere, for any other reason).
This test also checks named and throttled loggers.

Guideline : keep the core as pure (functional) as possible, push side-effects to the side.

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.

This is a nice improvement to the tests. Thank you for your effort.

Throttled loggers need node to be initialized (to get the time...) so we might test them in a rostest instead (unless we can somehow remove that constraint)

test_rosgraph might be a good location for such tests.

rospy.core.configure_logging("/")
self.fail("configure_logging should not accept a the root namespace as the node_name param")
except: pass
rospy.core.configure_logging("/node/name")
Copy link
Member

Choose a reason for hiding this comment

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

Why has this test been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I see the test has been moved here https://github.com/ros/ros_comm/pull/1144/files#diff-719224e090245a8163761263deeb3355R91 (slightly different line than the above link. LGTM.


import logging
import rosgraph.roslogging
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason for these imports to not be at module level?

Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not that I know of... imports were already done in the method, I just did the same. I ll change them...

Copy link
Member

Choose a reason for hiding this comment

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

This is still pending. Maybe you are still working on this. Please let me know when I should review the patch again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually missed these...
I also noticed the test_wait_for_service has a comment "lazy-import for coverage"... Is this something I should be concerned about ? I don't know how I can check coverage in this repo... any doc you could point me to, describing this ?

rospy.logout('out', logger_name="child1")
rospy.logerr('err', logger_name="child1")
rospy.logfatal('fatal', logger_name="child1")

Copy link
Member

Choose a reason for hiding this comment

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

Please avoid empty lines after def ...(...): or try: (PEP 8).

if filename[0] == '_':
filename = filename[1:]
if filename == suffix:
raise rospy.exceptions.ROSException('invalid configure_logging parameter: %s'%node_name)
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure that lines which haven't changed do not appear in the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah sorry this happens because of my editor switching to unix endlines by default...
I ll put back the windows endlines there to get a proper diff.


rosout_logger = logging.getLogger('rosout')

print("HANDLERS : " + str(rosout_logger.handlers))
Copy link
Member

Choose a reason for hiding this comment

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

Can this debug output be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep.

print("HANDLERS : " + str(rosout_logger.handlers))
self.assertTrue(len(rosout_logger.handlers) == 2)
self.assertTrue(rosout_logger.handlers[0], rosgraph.roslogging.RosStreamHandler)
# self.assertTrue(rosout_logger.handlers[1], rospy.impl.rosout.RosOutHandler)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be removed too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left it there to illustrate what the handlers should be. I might as well actually check it.


import logging
import rosgraph.roslogging
Copy link
Member

Choose a reason for hiding this comment

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

This is still pending. Maybe you are still working on this. Please let me know when I should review the patch again.

@asmodehn
Copy link
Contributor Author

I was actually thinking of leaving this PR like this (except minor changes), given that throttled and named loggers are already tested in test_rospy_client_online.py.
But let me know if you are aware of any related change that should be made in this PR, I can add them.

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.

Hopefully the last comment. Thanks for iterating on this.

@@ -39,9 +39,14 @@
import unittest
import time
import random
from StringIO import StringIO
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't work with Python 3. Please use the same conditional import as in the other files.

rospy.core.configure_logging("/")
self.fail("configure_logging should not accept a the root namespace as the node_name param")
except: pass
rospy.core.configure_logging("/node/name")
Copy link
Member

Choose a reason for hiding this comment

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

I see the test has been moved here https://github.com/ros/ros_comm/pull/1144/files#diff-719224e090245a8163761263deeb3355R91 (slightly different line than the above link. LGTM.

@dirk-thomas dirk-thomas merged commit 44bbbd1 into ros:lunar-devel Aug 28, 2017
@dirk-thomas
Copy link
Member

@asmodehn Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants