Skip to content

Improved Fake Serial device used by unit tests#25

Merged
hansmosh merged 4 commits intoniolabs:masterfrom
jamesleesaunders:fake-serial
Jan 10, 2017
Merged

Improved Fake Serial device used by unit tests#25
hansmosh merged 4 commits intoniolabs:masterfrom
jamesleesaunders:fake-serial

Conversation

@jamesleesaunders
Copy link
Copy Markdown
Collaborator

@jamesleesaunders jamesleesaunders commented Sep 4, 2016

This PR proposes a number of improvements to the Fake Serial device which is used by the python-xbee unit tests to simulate a serial device.

  • Merged FakeDevice and FakeReadDevice into one.
  • Added defaults for port, baudrate, timeout, xonxoff etc.
  • Added readline() function.
  • Added set_read_data() to set the data to be used by read() and readline().
  • Added get_settings() Get a dictionary with port settings.
  • Added get_data_written() returns data passed to write().
  • Added further docstring comments.

The reason for these improvements are to support PR #27 which I am which adds support to base.py to attempt to recover from serial failure or unplug. In order for this to work I needed to embellish the Fake.py test device.

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

I was also considering whether it would also be appropriate to rename the file 'Fake.py' to 'fakeSerial.py' (along with all its refs) to make it more obvious what it is. If you think this a good idea I can do this in a subsequent PR.

* Merged FakeDevice and FakeReadDevice into one.
* Added defaults for port, baudrate, timeout, xonxoff etc.
* Added readline() function.
* Added set_read_data() to set the data to be used by read() and readline().
* Added get_data_written() returns data passed to write().
* Added getSettingsDict() Get a dictionary with port settings.
* Added further docstring comments.
* Replaced the previous FakeDevice and FakeReadDevice with the new fake Serial class.
* Use of get_data_written().
* Modify BadReadDevice accordingly.
* Adding default second argument 'length' to BadReadDevice().
* Removed test_read_too_many() test as no longer required.
@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

Hi @hansmosh Please consider this PR for inclusion upstream. This PR improves (and simplifies some of the python-xbee tests.

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

Hi @pmalmsten This PR may be of interest to you also?

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

Chris?

@hansmosh hansmosh self-assigned this Oct 26, 2016
@hansmosh
Copy link
Copy Markdown
Contributor

@jamesleesaunders: My bad, I wasn't getting notifications from GitHub about this. I'll take a look this week.

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

Did you get a chance to review?

Copy link
Copy Markdown
Contributor

@hansmosh hansmosh left a comment

Choose a reason for hiding this comment

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

Just one simple little fix and then I'll go ahead and merge this in.

I appreciate you taking the time to clean this up a little. I definitely like the merging of those two test devices into one.

I actually think that if we were to keep going with this exercise, it would make sense to get rid of that fake device entirely and use a MagicMock.

Comment thread xbee/tests/test_ieee.py Outdated
self.set_read_data(data)

def inWaiting(self):
def in_waiting(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is never called. I don't think it should have been changed from inWaiting. The test passes either way so I'm not sure why this is even here. I say either delete it or change it back.

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

@hansmosh Thanks for looking at this PR, I am glad you like the merging of the fake serial devices. I have made the requested changes.

The reason for this, was that I did start to replace a couple of the now deprecated pySerial functions with their newer counterparts (https://pythonhosted.org/pyserial/pyserial_api.html?highlight=inwaiting#serial.Serial.inWaiting)...

  • inWaiting() -> in_waiting()
  • getSettingsDict() -> get_settings()
    ...but then I thought better of it and that I had best not meddle too much, and to ensure python-xbee is backwards compatible with pre pySerial 3.0 we should stick with the older function names. The one you spotted was one I forgot to revert back (good spot!).

@jamesleesaunders
Copy link
Copy Markdown
Collaborator Author

@hansmosh Happy New Year!
I have made the requested change, can this be merged in now?

@hansmosh hansmosh merged commit 100db22 into niolabs:master Jan 10, 2017
@jamesleesaunders jamesleesaunders deleted the fake-serial branch January 10, 2017 22:52
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