File tree Expand file tree Collapse file tree 3 files changed +14
-8
lines changed Expand file tree Collapse file tree 3 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 4
4
import canopen
5
5
from canopen .objectdictionary .eds import _signed_int_from_hex
6
6
from canopen .utils import pretty_index
7
- from .util import SAMPLE_EDS , DATATYPES_EDS
7
+ from .util import SAMPLE_EDS , DATATYPES_EDS , tmp_file
8
8
9
9
10
10
class TestEDS (unittest .TestCase ):
@@ -223,10 +223,9 @@ def test_comments(self):
223
223
""" .strip ())
224
224
225
225
def test_export_eds_to_file (self ):
226
- import tempfile
227
226
for suffix in ".eds" , ".dcf" :
228
227
for implicit in True , False :
229
- with tempfile . NamedTemporaryFile (suffix = suffix ) as tmp :
228
+ with tmp_file (suffix = suffix ) as tmp :
230
229
dest = tmp .name
231
230
doctype = None if implicit else suffix [1 :]
232
231
with self .subTest (dest = dest , doctype = doctype ):
@@ -235,9 +234,8 @@ def test_export_eds_to_file(self):
235
234
236
235
def test_export_eds_to_file_unknown_extension (self ):
237
236
import io
238
- import tempfile
239
237
for suffix in ".txt" , "" :
240
- with tempfile . NamedTemporaryFile (suffix = suffix ) as tmp :
238
+ with tmp_file (suffix = suffix ) as tmp :
241
239
dest = tmp .name
242
240
with self .subTest (dest = dest , doctype = None ):
243
241
canopen .export_od (self .od , dest )
Original file line number Diff line number Diff line change 1
1
import unittest
2
2
3
3
import canopen
4
- from .util import SAMPLE_EDS
4
+ from .util import SAMPLE_EDS , tmp_file
5
5
6
6
7
7
class TestPDO (unittest .TestCase ):
@@ -64,14 +64,13 @@ def test_pdo_save(self):
64
64
self .node .rpdo .save ()
65
65
66
66
def test_pdo_export (self ):
67
- import tempfile
68
67
try :
69
68
import canmatrix
70
69
except ImportError :
71
70
raise unittest .SkipTest ("The PDO export API requires canmatrix" )
72
71
73
72
for pdo in "tpdo" , "rpdo" :
74
- with tempfile . NamedTemporaryFile (suffix = ".csv" ) as tmp :
73
+ with tmp_file (suffix = ".csv" ) as tmp :
75
74
fn = tmp .name
76
75
with self .subTest (filename = fn , pdo = pdo ):
77
76
getattr (self .node , pdo ).export (fn )
Original file line number Diff line number Diff line change
1
+ import contextlib
1
2
import os
3
+ import tempfile
2
4
3
5
4
6
DATATYPES_EDS = os .path .join (os .path .dirname (__file__ ), "datatypes.eds" )
5
7
SAMPLE_EDS = os .path .join (os .path .dirname (__file__ ), "sample.eds" )
8
+
9
+
10
+ @contextlib .contextmanager
11
+ def tmp_file (* args , ** kwds ):
12
+ with tempfile .NamedTemporaryFile (* args , ** kwds ) as tmp :
13
+ tmp .close ()
14
+ yield tmp
You can’t perform that action at this time.
0 commit comments