Skip to content

Commit 2b900a9

Browse files
committed
Test to cover _revert_variable() branches (without default_raw).
1 parent 417ace5 commit 2b900a9

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

test/test_eds.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import os
23
import unittest
34
from configparser import RawConfigParser
@@ -71,8 +72,6 @@ def test_load_implicit_nodeid(self):
7172
self.assertEqual(od.node_id, 16)
7273

7374
def test_load_implicit_nodeid_fallback(self):
74-
import io
75-
7675
# First, remove the NodeID option from DeviceComissioning.
7776
with open(SAMPLE_EDS) as f:
7877
lines = [L for L in f.readlines() if not L.startswith("NodeID=")]
@@ -94,8 +93,6 @@ def test_load_baudrate(self):
9493
self.assertEqual(od.bitrate, 500_000)
9594

9695
def test_load_baudrate_fallback(self):
97-
import io
98-
9996
# Remove the Baudrate option.
10097
with open(SAMPLE_EDS) as f:
10198
lines = [L for L in f.readlines() if not L.startswith("Baudrate=")]
@@ -277,7 +274,6 @@ def test_read_domain_subobject(self):
277274

278275
def test_roundtrip_domain_objects(self):
279276
# ObjectType==DOMAIN survive an EDS export/import round-trip
280-
import io
281277
with io.StringIO() as dest:
282278
canopen.export_od(self.od, dest, 'eds')
283279
dest.name = 'mock.eds'
@@ -288,6 +284,17 @@ def test_roundtrip_domain_objects(self):
288284
self.assertTrue(od2[0x3063].is_domain)
289285
self.assertTrue(od2[0x3064][1].is_domain)
290286

287+
def test_export_without_raw_default_values(self):
288+
od = canopen.import_od(DATATYPES_EDS)
289+
# Make sure the values are not cached in raw form
290+
for var in od.values():
291+
try:
292+
delattr(var, 'default_raw')
293+
except AttributeError:
294+
pass
295+
with io.StringIO() as dest:
296+
canopen.export_od(od, dest, 'eds')
297+
291298

292299
def test_comments(self):
293300
self.assertEqual(self.od.comments,
@@ -308,7 +315,6 @@ def test_export_eds_to_file(self):
308315
self.verify_od(dest, doctype)
309316

310317
def test_export_eds_to_file_unknown_extension(self):
311-
import io
312318
for suffix in ".txt", "":
313319
with tmp_file(suffix=suffix) as tmp:
314320
dest = tmp.name
@@ -331,7 +337,6 @@ def test_export_eds_to_file_unknown_extension(self):
331337
self.verify_od(buf, "eds")
332338

333339
def test_export_eds_unknown_doctype(self):
334-
import io
335340
filelike_object = io.StringIO()
336341
self.addCleanup(filelike_object.close)
337342
for dest in "filename", None, filelike_object:
@@ -344,7 +349,6 @@ def test_export_eds_unknown_doctype(self):
344349
os.stat(dest)
345350

346351
def test_export_eds_to_filelike_object(self):
347-
import io
348352
for doctype in "eds", "dcf":
349353
with io.StringIO() as dest:
350354
with self.subTest(dest=dest, doctype=doctype):
@@ -358,7 +362,6 @@ def test_export_eds_to_filelike_object(self):
358362

359363
def test_export_eds_to_stdout(self):
360364
import contextlib
361-
import io
362365
with contextlib.redirect_stdout(io.StringIO()) as f:
363366
ret = canopen.export_od(self.od, None, "eds")
364367
self.assertIsNone(ret)

0 commit comments

Comments
 (0)