Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

improved rospy core logger test.#1144

Merged
dirk-thomas merged 7 commits intoros:lunar-develfrom
asmodehn:rospy_logger_tests
Aug 28, 2017
Merged

improved rospy core logger test.#1144
dirk-thomas merged 7 commits intoros:lunar-develfrom
asmodehn:rospy_logger_tests

Conversation

@asmodehn
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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.

real_stderr = sys.stderr

import logging
import rosgraph.roslogging
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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).

@asmodehn asmodehn force-pushed the rospy_logger_tests branch from fb66356 to d38c534 Compare August 18, 2017 09:33
if filename[0] == '_':
filename = filename[1:]
if filename == suffix:
raise rospy.exceptions.ROSException('invalid configure_logging parameter: %s'%node_name)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

real_stderr = sys.stderr

import logging
import rosgraph.roslogging
Copy link
Copy Markdown
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 asmodehn force-pushed the rospy_logger_tests branch from 11ab850 to 7ee680d Compare August 23, 2017 09:06
@asmodehn
Copy link
Copy Markdown
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
Copy Markdown
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.

import unittest
import time
import random
from StringIO import StringIO
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

@asmodehn Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants