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

Update, document and test SerialData #180

Merged
merged 5 commits into from Dec 11, 2017
Merged

Conversation

jamessynge
Copy link
Contributor

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.

it much more thoroughly. Updated the calls accordingly.
Increased test coverage of SerialData.
@codecov
Copy link

codecov bot commented Dec 9, 2017

Codecov Report

Merging #180 into develop will increase coverage by 0.87%.
The diff coverage is 86.36%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
pocs/utils/rs232.py 92.85% <86.36%> (+25.41%) ⬆️

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 25b4cc7...75aedeb. Read the comment docs.

@jamessynge
Copy link
Contributor Author

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.

@jamessynge jamessynge requested a review from wtgee December 9, 2017 22:54
wtgee
wtgee previously approved these changes Dec 10, 2017
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.

Approving because I might have limited availability and don't want to block you. Thanks for adding a bunch of missing docstrings.

# 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?
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 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.

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've removed that (and will send another PR).

I'll create an issue to discuss the issue you raise.

@@ -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."""
Copy link
Member

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?

Copy link
Contributor Author

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')
Copy link
Member

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?

Copy link
Contributor Author

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

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.)

Copy link
Contributor Author

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.

BadSerialConnection if unable to open the connection.
"""
if self.is_connected:
return
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added appropriate message.

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())
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 line instead of another self.read()?

Copy link
Contributor Author

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.

ts = time.strftime('%Y-%m-%dT%H:%M:%S %Z', time.gmtime())
info = (ts, self.read())
except IndexError:
# TODO(wtgee): When might this occur?
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed try/except.

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.

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')
Copy link
Member

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?

@jamessynge jamessynge merged commit f1124a6 into panoptes:develop Dec 11, 2017
@jamessynge jamessynge deleted the rs232 branch December 11, 2017 15:21
@wtgee wtgee mentioned this pull request Dec 29, 2017
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.

None yet

2 participants