niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

Break on Error fix, Zigbee Test fix, Comments fix. #18

Closed jamesleesaunders closed 8 years ago

jamesleesaunders commented 8 years ago

This PR has been raised to fix a few little niggles:

  1. Do not break on error. Commented out the 'break' statement in base.py on _error_callback. I have done this as it is not thread safe and meant that threads would hang (break) and the main code is not aware, this in turn appears like the thread has hung (but no error messages are presented to the user). Further information on this issue can be seen here: http://axotron.se/blog/problems-with-python-xbee-2-2-3-package/
  2. Correcting header comment filenames. There are a couple of headers with the wrong filename. Correcting base.py and test_base.py.
  3. Fixing broken test_zigbee test. Fixing test_parse_dio_adc_supply_voltage_not_clamped test which is complaining that adc-7 does not equal 280.
  4. Correcting XBee/XBee-PRO S2C ZigBee document link Fixing broken link to XBee documentation in relation to the recently added Route Record Indicator packets PR16. Was: http://ftp1.digi.com/support/documentation/90002002.pdf Now: http://www.digi.com/resources/documentation/digidocs/pdfs/90002002.pdf
hansmosh commented 8 years ago

@jamesleesaunders: All of these were small so it's easy enough here, but I would prefer for each PR to fix only one issue. That way we don't hold up any features from getting merged while discussing others that may not be quite ready.

Thanks again for the contributions!

hansmosh commented 8 years ago

@jamesleesaunders: I actually reverted this as the unit test that you modified didn't pass on Travis CI.

I added Travis CI between the time that you created the PR and merging it so I wasn't able to see the failed results until after I merged. The next PR will run those tests right away so we will know before merging.

jamesleesaunders commented 8 years ago

Cool, no worries I will try to keep code changes small and linked to only one feature / fix.

Sorry the test failed and you had to revert it. I have now also attached Travis CI to my repo so can check before hand. I am still a little confused as the reason I made that test_zigbee.pl test change is because the test was failing when I ran it on the command line (perhaps I am doing it wrong?):

MacBook-Pro:tests jim$ pwd
/Users/jim/hive/python-xbee/xbee/tests
MacBook-Pro:tests jim$ sudo python -m unittest test_zigbee
Password:
.F.........
======================================================================
FAIL: test_parse_dio_adc_supply_voltage_not_clamped (test_zigbee.TestParseZigBeeIOData)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_zigbee.py", line 248, in test_parse_dio_adc_supply_voltage_not_clamped
    self.assertEqual(results, expected_results)
AssertionError: Lists differ: [{'adc-7': 280}] != [{'adc-7': 3352}]

First differing element 0:
{'adc-7': 280}
{'adc-7': 3352}

- [{'adc-7': 280}]
?             --

+ [{'adc-7': 3352}]
?            +++

----------------------------------------------------------------------
Ran 11 tests in 0.002s

FAILED (failures=1)
MacBook-Pro:tests jim$ 

Which is why I modified the test from: expected_results = [{'adc-7':0xD18}] to: expected_results = [{'adc-7':280}]

Perhaps I am running these tests in the wrong way as I also notice test_base.py fails in eve more a dramatic manner:

MacBook-Pro:tests jim$ sudo python -m unittest test_base
EE....EEEEEE
======================================================================
ERROR: test_provide_callback (test_base.TestAsyncCallback)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_base.py", line 167, in test_provide_callback
    error_callback=self.error_callback)
  File "/Library/Python/2.7/site-packages/xbee/base.py", line 79, in __init__
    self.start()
...
...
RuntimeError: maximum recursion depth exceeded in cmp

======================================================================
ERROR: test_provide_callback (test_base.TestAsyncCallback)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_base.py", line 159, in tearDown
    self.xbee.halt()
AttributeError: 'NoneType' object has no attribute 'halt'
...
======================================================================
ERROR: test_read (test_base.TestReadFromDevice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_base.py", line 74, in test_read
    frame = xbee._wait_for_frame()
  File "/Library/Python/2.7/site-packages/xbee/base.py", line 212, in _wait_for_frame
    byte = self.serial.read()
AttributeError: 'NoneType' object has no attribute 'read'
...
======================================================================
ERROR: test_write (test_base.TestWriteToDevice)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_base.py", line 28, in test_write
    xbee._write(b'\x00')
  File "/Library/Python/2.7/site-packages/xbee/base.py", line 123, in _write
    self.serial.write(frame)
AttributeError: 'NoneType' object has no attribute 'write'

----------------------------------------------------------------------
Ran 11 tests in 0.005s

FAILED (failures=8)
MacBook-Pro:tests jim$ 

Should I be running these a different way?

jamesleesaunders commented 8 years ago

Ah, ha! Ignore the failed tests I mentioned in the previous comment. I started afresh with a newly checked out version and installed afresh and all is now well :-)

Sorry again for the confusion.