-
Notifications
You must be signed in to change notification settings - Fork 197
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
Save the passed node ID to the resulting OD in import_od()
#484
Save the passed node ID to the resulting OD in import_od()
#484
Conversation
import_od()
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #484 +/- ##
==========================================
+ Coverage 67.82% 67.84% +0.02%
==========================================
Files 26 26
Lines 3105 3107 +2
Branches 522 524 +2
==========================================
+ Hits 2106 2108 +2
Misses 859 859
Partials 140 140
|
Note: I deliberately changed the value of |
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.
Wouldn't it make sense to stick with the node_id
parameter in places where it's used? Just in addition, override the od.node_id
attribute if the argument was given. I think it's safer not having to remember the od.
prefix in any later usage within the function.
That would absolutely reduce the diff, but I generally don't like shadowing parameters/variables, which is why I went for the I don't have a strong opinion about this; I'll change it as you wish. |
Yea I prefer overriding the |
Addressed in 8a22e7e. But, there's a case we're not testing: if the passed |
An |
For the case described in #484 (comment), of course the node ID ends up being |
Thanks for the insight! |
I still would consider adding this patch to the PR before merging: diff --git a/test/test_eds.py b/test/test_eds.py
index f46cc0e..00d5013 100644
--- a/test/test_eds.py
+++ b/test/test_eds.py
@@ -4,7 +4,8 @@ import canopen
from canopen.objectdictionary.eds import _signed_int_from_hex
from canopen.utils import pretty_index
-EDS_PATH = os.path.join(os.path.dirname(__file__), 'sample.eds')
+SAMPLE_EDS = os.path.join(os.path.dirname(__file__), 'sample.eds')
+DATATYPES_EDS = os.path.join(os.path.dirname(__file__), 'datatypes.eds')
class TestEDS(unittest.TestCase):
@@ -48,7 +49,7 @@ class TestEDS(unittest.TestCase):
}
def setUp(self):
- self.od = canopen.import_od(EDS_PATH, 2)
+ self.od = canopen.import_od(SAMPLE_EDS, 2)
def test_load_nonexisting_file(self):
with self.assertRaises(IOError):
@@ -59,17 +60,22 @@ class TestEDS(unittest.TestCase):
canopen.import_od(__file__)
def test_load_file_object(self):
- with open(EDS_PATH) as fp:
+ with open(SAMPLE_EDS) as fp:
od = canopen.import_od(fp)
self.assertTrue(len(od) > 0)
def test_load_implicit_nodeid(self):
# sample.eds has a DeviceComissioning section with NodeID set to 0x10.
- od = canopen.import_od(EDS_PATH)
+ od = canopen.import_od(SAMPLE_EDS)
self.assertEqual(od.node_id, 16)
+ def test_load_implicit_nodeid_no_devicecomissioning_section(self):
+ # datatypes.eds has no DeviceComissioning section.
+ od = canopen.import_od(DATATYPES_EDS)
+ self.assertIsNone(od.node_id)
+
def test_load_explicit_nodeid(self):
- od = canopen.import_od(EDS_PATH, node_id=3)
+ od = canopen.import_od(SAMPLE_EDS, node_id=3)
self.assertEqual(od.node_id, 3)
def test_variable(self): |
Sure, go ahead. The separate sample EDS files were introduced recently for the PDO stuff IIRC. |
Thanks for the review! |
Fixes #478