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

Add testing of rs232.SerialData #147

Closed
wants to merge 9 commits into from

Conversation

jamessynge
Copy link
Contributor

The latest test, test_unthreaded_io, isn't working yet, probably because of the module being loaded twice (i.e. two separate paths), and thus the global variables in the module aren't shared between the two distinct loads of the module.

feature that allows a handler to be used based on the url of the
serial "device".
I think that the module is being loaded twice, once by test_rs232.py,
and another time by serial.serial_for_url(). As a result, the buffers
set by the test aren't visible to the BuffersSerial instance.
@jamessynge jamessynge requested a review from wtgee November 29, 2017 03:04
Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

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

I haven't yet read over all the handler items for pySerial so don't fully grok what is going on here but gave some comments anyway.

self.process.daemon = True
self.process.name = "PANOPTES_{}".format(name)

# TODO(jamessynge): Consider eliminating this sleep period, or making
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you did make this configurable. Is comment still necessary?

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 if you're comfortable with the configurable behavior.

And can you tell me what problem you were working around with the 2 second delay?

if self.is_threaded:
self._serial_io = TextIOWrapper(BufferedRWPair(self.ser, self.ser),
newline='\r\n', encoding='ascii', line_buffering=True)
self.ser = serial.serial_for_url(port, do_not_open=True)
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 documentation says to consider using this but don't understand what the advantage is.

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 sure what "this" refers to. If you mean do_not_open, the advantage is that you set all of the properties (e.g. baud rate and byte size) before opening the port. Depending on the device, it may require effectively closing and reopening to change properties (_reconfigure_port is called for this).

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, bad comment on my part. This was in reference to using serial_for_url. I reviewed this out of order, starting with this file, so after looking at how the tests are set up this makes more sense.

self.process.daemon = True
self.process.name = "PANOPTES_{}".format(name)
# Properties have been set to reasonable values, ready to open the port.
self.ser.open()
Copy link
Member

Choose a reason for hiding this comment

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

How come we've lost the exception handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we don't have any "open on write" behavior, this means that we have a completely useless SerialData instance if we ignore the failure. And since we use exceptions elsewhere for failures, I didn't see the point in hiding this failure. All the tests passed after making that change.

except Exception as err:
self.ser = None
self.logger.critical('Could not set up serial port {} {}'.format(port, err))
if self.is_threaded:
Copy link
Member

Choose a reason for hiding this comment

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

I understand this is not your focus here necessarily, but I see that pySerial now has support for threaded and asyncio. I haven't looked into them but perhaps we should consider?

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 too haven't looked at that. While probably worth looking into, I don't want to entangle these issues.

def read(self, retry_limit=5, retry_delay=0.5):
"""Reads next line of input using readline.

If no response is given, delay for retry_delay and then try to read
Copy link
Member

Choose a reason for hiding this comment

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

Better than previous docstring, but we have explicit Args section. Need to start enforcing docstring standards. I have a plugin for Sublime that fills out all the boilerplate.

http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html#example-google

self._ri = False
self._ri = False
self._ri = False
self._ri = False
Copy link
Member

Choose a reason for hiding this comment

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

Probably don't need 4 of these.

if self.logger:
self.logger.info('ignored setBreak({!r})'.format(level))

def setRTS(self, level=True):
Copy link
Member

Choose a reason for hiding this comment

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

All these method names are deprecated in favor of properties. Should we still be using?

@@ -0,0 +1,81 @@
import pytest
import serial # PySerial, from https://github.com/pyserial/pyserial
Copy link
Member

Choose a reason for hiding this comment

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

Why the github comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need, removing.

print(str(ser.ser))
# Open is automatically called by SerialData.
assert ser.is_connected
# Not using threading.
Copy link
Member

Choose a reason for hiding this comment

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

threaded=True is the default on SerialData. Does this get unset in one of the serial_handler files above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake, I misunderstood.

# Not using threading.
assert not ser.is_listening

# no_op handler doesn't do any reading or writing.
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment valid here?

@wtgee
Copy link
Member

wtgee commented Nov 30, 2017

In meetings for a bit now, so quick comment: I don't think we are using the threaded anywhere so maybe look at scrapping it. More in a few.


# Assert how much is written, which unfortunately isn't consistent.
Copy link
Member

Choose a reason for hiding this comment

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

I guess that's a bit concerning. Do you know why this is?

…rial.

This shows how we can develop mock serial devices for testing.
@jamessynge jamessynge changed the title DO NOT COMMIT - Steps towards serial testing Add testing of rs232.SerialData Dec 1, 2017
@jamessynge
Copy link
Contributor Author

Still need to review your comments.

@codecov
Copy link

codecov bot commented Dec 1, 2017

Codecov Report

Merging #147 into develop will decrease coverage by 3.81%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop    #147      +/-   ##
==========================================
- Coverage    84.42%   80.6%   -3.82%     
==========================================
  Files           37      36       -1     
  Lines         2414    2527     +113     
  Branches       287     319      +32     
==========================================
- Hits          2038    2037       -1     
- Misses         294     386      +92     
- Partials        82     104      +22
Impacted Files Coverage Δ
pocs/utils/images.py 54.98% <0%> (-37.48%) ⬇️
pocs/state/states/default/__init__.py

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2ff144...37a6be2. Read the comment docs.

@jamessynge
Copy link
Contributor Author

Superseded by a later PR

@jamessynge jamessynge closed this Dec 3, 2017
@jamessynge jamessynge deleted the pyserial-test-handler branch December 20, 2017 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants