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
Update, document and test SerialData #180
Conversation
it much more thoroughly. Updated the calls accordingly. Increased test coverage of SerialData.
Codecov Report
@@ Coverage Diff @@
## develop #180 +/- ##
===========================================
+ Coverage 80.39% 81.27% +0.87%
===========================================
Files 37 37
Lines 2642 2654 +12
Branches 330 330
===========================================
+ Hits 2124 2157 +33
+ Misses 409 392 -17
+ Partials 109 105 -4
Continue to review full report at Codecov.
|
I'm perplexed about the lack of coverage of pocs/utils/rs232.py. Running coverage.py locally, I see coverage of it, but codecov doesn't show it here. The .coveragerc file does not mark it to be omitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving because I might have limited availability and don't want to block you. Thanks for adding a bunch of missing docstrings.
pocs/mount/serial.py
Outdated
# This won't be triggered because SerialData is created even if the mount port | ||
# can't be opened. We can't tell the difference between not currently present | ||
# and totally invalid (e.g. com1: on a Linux box, or /dev/tty7 on Windows), | ||
# TODO(wtgee): What would you like to do about this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I was a little skeptical about creating the SerialData
object regardless. The error.BadSerialConnection
is a good replacement, but it is a big annoying when in use via pocs_shell
, because the error right here will trigger before anything else is set up and tell the user to use a simulator.
However, I think that could also be handled in a better manner. I think we could simple remove the try/except
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed that (and will send another PR).
I'll create an issue to discuss the issue you raise.
pocs/tests/test_rs232.py
Outdated
@@ -32,9 +50,16 @@ def test_detect_bogus_scheme(handler): | |||
rs232.SerialData(port='bogus://') | |||
|
|||
|
|||
def test_detect_bogus_scheme(handler): | |||
"""When our handlers are installed, will still detect unknown scheme.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are valid schemes? Have we documented these handlers and schemes as they apply to us?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than document all of those (mostly provided by PySerial), I documented what the scheme must be, and then violated that so that the exception will be raised.
# never produces any output. | ||
assert '' == ser.read(retry_delay=0.01, retry_limit=2) | ||
assert b'' == ser.read_bytes(size=1) | ||
assert 0 == ser.write('abcdef') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does write
ever return a valid number or is it always 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The no_op handler never returns anything, but other handles do report the size written.
or to force a reset, this wrapper may or may not have an open connection to the underlying | ||
serial device. Note that for most devices, is_connected will return true if the device is | ||
turned off/unplugged after a connection is opened; the code will only discover there is a | ||
problem when we attempt to interact with the device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is the case we should have a method on pocs
or observatory
that tests the connections and can be checked from the ready state. We can wait to do this when we write the methods that actually do the shutting down (probably in the housekeeping state.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted #185 to track this issue.
pocs/utils/rs232.py
Outdated
BadSerialConnection if unable to open the connection. | ||
""" | ||
if self.is_connected: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it generate too much noise if we have a log message here saying connection was already open?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added appropriate message.
pocs/utils/rs232.py
Outdated
try: | ||
# Get the timestamp after the read so that a long delay on reading doesn't make it | ||
# appear that the read happened much earlier than it did. | ||
line = self.read() | ||
ts = time.strftime('%Y-%m-%dT%H:%M:%S %Z', time.gmtime()) | ||
info = (ts, self.read()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be line
instead of another self.read()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Test added that detected this bug, and bug fixed.
pocs/utils/rs232.py
Outdated
ts = time.strftime('%Y-%m-%dT%H:%M:%S %Z', time.gmtime()) | ||
info = (ts, self.read()) | ||
except IndexError: | ||
# TODO(wtgee): When might this occur? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question but I think it was when dealing the threaded
and reading from a queue
. Not entirely sure though so perhaps we should remove until becomes a problem. Or at least add a log message such that we can easily find when it does happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed try/except.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Approving before laptop battery dies.
|
||
|
||
def test_basic_io(handler): | ||
protocol_buffers.ResetBuffers(b'abc\r\n') | ||
ser = rs232.SerialData(port='buffers://', open_delay=0, threaded=False) | ||
protocol_buffers.ResetBuffers(b'abc\r\ndef\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this consume either \r\n
or \n
?
Make the API of rs232.SerialData a bit more regular, and document
it much more thoroughly. Updated the calls accordingly.
Increased test coverage of SerialData.