Skip to content

Commit 5a7f089

Browse files
authored
move formats to submodule (#236) (#301)
1 parent 399a336 commit 5a7f089

16 files changed

+36
-36
lines changed

src/canmatrix/formats.py src/canmatrix/formats/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
for module in moduleList:
2020
try:
21-
import_module("canmatrix." + module)
21+
import_module("canmatrix.formats." + module)
2222
loadedFormats.append(module)
2323
except ImportError:
2424
logger.info("%s is not supported", module)
2525

2626
for loadedModule in loadedFormats:
2727
supportedFormats[loadedModule] = []
28-
moduleInstance = sys.modules["canmatrix." + loadedModule]
28+
moduleInstance = sys.modules["canmatrix.formats." + loadedModule]
2929
if "load" in dir(moduleInstance):
3030
supportedFormats[loadedModule].append("load")
3131
if "dump" in dir(moduleInstance):
@@ -69,7 +69,7 @@ def loadp(path, importType=None, key="", flatImport=None, **options):
6969

7070
def load(fileObject, importType, key="", flatImport=None, **options):
7171
dbs = {}
72-
moduleInstance = sys.modules["canmatrix." + importType]
72+
moduleInstance = sys.modules["canmatrix.formats." + importType]
7373
if "clusterImporter" in supportedFormats[importType]:
7474
dbs = moduleInstance.load(fileObject, **options)
7575
else:
@@ -83,7 +83,7 @@ def load(fileObject, importType, key="", flatImport=None, **options):
8383

8484

8585
def dump(canMatrixOrCluster, fileObject, exportType, **options):
86-
moduleInstance = sys.modules["canmatrix." + exportType]
86+
moduleInstance = sys.modules["canmatrix.formats." + exportType]
8787
if isinstance(canMatrixOrCluster, canmatrix.CanMatrix):
8888
moduleInstance.dump(canMatrixOrCluster, fileObject, **options)
8989
elif "clusterExporter" in supportedFormats[exportType]:
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/canmatrix/xls.py src/canmatrix/formats/xls.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import xlwt
3131
import canmatrix
32-
import canmatrix.xls_common
32+
import canmatrix.formats.xls_common
3333
import xlrd
3434
import decimal
3535

@@ -205,7 +205,7 @@ def dump(db, file, **options):
205205
# iterate over signals
206206
rowArray = []
207207
if len(sigHash) == 0: # Frames without signals
208-
rowArray += canmatrix.xls_common.get_frame_info(db, frame)
208+
rowArray += canmatrix.formats.xls_common.get_frame_info(db, frame)
209209
for item in range(5, head_start):
210210
rowArray.append("")
211211
tempCol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
@@ -233,7 +233,7 @@ def dump(db, file, **options):
233233
valstyle = sigstyle
234234
# iterate over values in valuetable
235235
for val in sorted(sig.values.keys()):
236-
rowArray = canmatrix.xls_common.get_frame_info(db, frame)
236+
rowArray = canmatrix.formats.xls_common.get_frame_info(db, frame)
237237
frontcol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
238238
if framestyle != sty_first_frame:
239239
worksheet.row(row).level = 1
@@ -242,7 +242,7 @@ def dump(db, file, **options):
242242
col = writeBuMatrix(buList, sig, frame, worksheet, row, col, framestyle)
243243

244244
# write Value
245-
(frontRow, backRow) = canmatrix.xls_common.get_signal(db, sig, motorolaBitFormat)
245+
(frontRow, backRow) = canmatrix.formats.xls_common.get_signal(db, sig, motorolaBitFormat)
246246
writeExcelLine(worksheet, row, frontcol, frontRow, sigstyle)
247247
backRow += additionalFrameInfo
248248
for item in additional_signal_colums:
@@ -262,15 +262,15 @@ def dump(db, file, **options):
262262
# loop over values ends here
263263
# no valuetable available
264264
else:
265-
rowArray = canmatrix.xls_common.get_frame_info(db, frame)
265+
rowArray = canmatrix.formats.xls_common.get_frame_info(db, frame)
266266
frontcol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
267267
if framestyle != sty_first_frame:
268268
worksheet.row(row).level = 1
269269

270270
col = head_start
271271
col = writeBuMatrix(
272272
buList, sig, frame, worksheet, row, col, framestyle)
273-
(frontRow,backRow) = canmatrix.xls_common.get_signal(db, sig, motorolaBitFormat)
273+
(frontRow,backRow) = canmatrix.formats.xls_common.get_signal(db, sig, motorolaBitFormat)
274274
writeExcelLine(worksheet, row, frontcol, frontRow, sigstyle)
275275

276276
if float(sig.min) != 0 or float(sig.max) != 1.0:
File renamed without changes.
File renamed without changes.

src/canmatrix/tests/test_arxml.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# -*- coding: utf-8 -*-
2-
import canmatrix.arxml
2+
import canmatrix.formats.arxml
33
import pathlib2
44

55

66
def test_ecu_extract():
77
here = pathlib2.Path(__file__).parent
88

9-
db = canmatrix.arxml.load(str(here / "MyECU.ecuc.arxml"))['']
9+
db = canmatrix.formats.arxml.load(str(here / "MyECU.ecuc.arxml"))['']
1010
assert db.frames is not None
1111
assert len(db.frames) == 2
1212
assert len(db.frames[0].signals) == 3

src/canmatrix/tests/test_dbc.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import string
55
import pytest
66

7-
import canmatrix.dbc
7+
import canmatrix.formats.dbc
88

99

1010
def test_long_signal_name_imports():
@@ -17,7 +17,7 @@ def test_long_signal_name_imports():
1717
BA_ "SystemSignalLongSymbol" SG_ 1 someShortenedDummyName "{}";
1818
''').format(long_signal_name).encode('utf-8'))
1919

20-
matrix = canmatrix.dbc.load(dbc)
20+
matrix = canmatrix.formats.dbc.load(dbc)
2121

2222
assert matrix.frames[0].signals[0].name == long_signal_name
2323
outdbc = io.BytesIO()
@@ -38,19 +38,19 @@ def test_long_signal_name_imports():
3838

3939
def test_create_define():
4040
defaults = {}
41-
test_string = canmatrix.dbc.create_define("my_data_type", canmatrix.Define('ENUM "A","B"'), "BA_", defaults)
41+
test_string = canmatrix.formats.dbc.create_define("my_data_type", canmatrix.Define('ENUM "A","B"'), "BA_", defaults)
4242
assert test_string == 'BA_DEF_ BA_ "my_data_type" ENUM "A","B";\n'
4343

4444

4545
def test_create_attribute_string():
46-
test_string = canmatrix.dbc.create_attribute_string("my_attribute", "BO_", "name", "value", True)
46+
test_string = canmatrix.formats.dbc.create_attribute_string("my_attribute", "BO_", "name", "value", True)
4747
assert test_string == 'BA_ "my_attribute" BO_ name "value";\n'
48-
test_string = canmatrix.dbc.create_attribute_string("my_attribute", "BO_", "name", 1.23, False)
48+
test_string = canmatrix.formats.dbc.create_attribute_string("my_attribute", "BO_", "name", 1.23, False)
4949
assert test_string == 'BA_ "my_attribute" BO_ name 1.23;\n'
5050

5151

5252
def test_create_comment_string():
53-
test_string = canmatrix.dbc.create_comment_string("BO_", "ident", "some comment", "utf8", "utf8")
53+
test_string = canmatrix.formats.dbc.create_comment_string("BO_", "ident", "some comment", "utf8", "utf8")
5454
assert test_string == b'CM_ BO_ ident "some comment";\n'
5555

5656

@@ -64,7 +64,7 @@ def test_long_frame_name_imports():
6464
BA_ "SystemMessageLongSymbol" BO_ 1 "{}";
6565
''').format(long_frame_name).encode('utf-8'))
6666

67-
matrix = canmatrix.dbc.load(dbc)
67+
matrix = canmatrix.formats.dbc.load(dbc)
6868
long_name_found = False
6969
name_found = False
7070

@@ -93,7 +93,7 @@ def test_long_ecu_name_imports():
9393
BA_ "SystemNodeLongSymbol" BU_ SoMEShortenedEcuName "{}";
9494
''').format(long_ecu_name).encode('utf-8'))
9595

96-
matrix = canmatrix.dbc.load(dbc)
96+
matrix = canmatrix.formats.dbc.load(dbc)
9797
long_name_found = False
9898
name_found = False
9999

@@ -123,7 +123,7 @@ def test_long_envvar_name_imports():
123123
BA_ "SystemEnvVarLongSymbol" EV_ someShortendEnvVar "{}";
124124
''').format(long_envvar_name).encode('utf-8'))
125125

126-
matrix = canmatrix.dbc.load(dbc)
126+
matrix = canmatrix.formats.dbc.load(dbc)
127127

128128
assert list(matrix.env_vars)[0] == long_envvar_name
129129
outdbc = io.BytesIO()
@@ -155,7 +155,7 @@ def test_enum_with_comma():
155155
BA_DEF_DEF_ "example3" ",";
156156
BA_DEF_DEF_ "example4" ",";
157157
''').encode('utf-8'))
158-
matrix = canmatrix.dbc.load(dbc, dbcImportEncoding="utf8")
158+
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
159159

160160
assert matrix.frame_defines[u'example1'].values == ["Val 1", "", ""] + list(" '()[]/-|{};:<>.?!@#$%^&=`~")
161161
assert matrix.signal_defines[u'example2'].values == ['Val1', ',']
@@ -173,7 +173,7 @@ def test_enum_with_special_character(character):
173173
dbc = io.BytesIO(textwrap.dedent(u'''\
174174
BA_DEF_ BO_ "example1" ENUM "Val 1","{}";
175175
''').format(character[0]).encode('utf-8'))
176-
matrix = canmatrix.dbc.load(dbc, dbcImportEncoding="utf8")
176+
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
177177
assert matrix.frame_defines[u'example1'].values == ["Val 1", character[0]]
178178

179179

@@ -184,13 +184,13 @@ def test_export_of_unknown_defines():
184184
db.add_frame_defines("Sendable", 'BOOL False True')
185185
for (dataType, define) in db.frame_defines.items():
186186
orig_definition = define.definition
187-
canmatrix.dbc.check_define(define)
187+
canmatrix.formats.dbc.check_define(define)
188188
assert orig_definition != define.definition
189189

190190
db.add_signal_defines("LongName", 'STR')
191191
for (dataType, define) in db.signal_defines.items():
192192
orig_definition = define.definition
193-
canmatrix.dbc.check_define(define)
193+
canmatrix.formats.dbc.check_define(define)
194194
assert orig_definition != define.definition
195195
frame = canmatrix.Frame("someFrame")
196196
signal = canmatrix.Signal("SomeSignal")
@@ -201,13 +201,13 @@ def test_export_of_unknown_defines():
201201
db.add_ecu_defines("someName", 'STRING')
202202
for (dataType, define) in db.ecu_defines.items():
203203
orig_definition = define.definition
204-
canmatrix.dbc.check_define(define)
204+
canmatrix.formats.dbc.check_define(define)
205205
assert orig_definition == define.definition
206206

207207
db.add_global_defines("someGlobaName", 'BOOL')
208208
for (dataType, define) in db.global_defines.items():
209209
orig_definition = define.definition
210-
canmatrix.dbc.check_define(define)
210+
canmatrix.formats.dbc.check_define(define)
211211
assert orig_definition != define.definition
212212

213213
outdbc = io.BytesIO()

src/canmatrix/tests/test_sym.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55

66
import canmatrix.canmatrix
7-
import canmatrix.sym
7+
import canmatrix.formats.sym
88

99

1010
def test_colliding_mux_values():
@@ -32,13 +32,13 @@ def test_colliding_mux_values():
3232
).encode('utf-8'),
3333
)
3434

35-
matrix = canmatrix.sym.load(f)
35+
matrix = canmatrix.formats.sym.load(f)
3636
error, = matrix.load_errors
3737
line_number = 16
3838

3939
assert len(matrix.load_errors) == 1
4040

41-
assert isinstance(error, canmatrix.sym.DuplicateMuxIdError)
41+
assert isinstance(error, canmatrix.formats.sym.DuplicateMuxIdError)
4242

4343
assert error.line_number == line_number
4444

@@ -67,7 +67,7 @@ def test_parse_longname_with_colon():
6767
).encode('utf-8'),
6868
)
6969

70-
matrix = canmatrix.sym.load(f)
70+
matrix = canmatrix.formats.sym.load(f)
7171
frame = matrix.frames[0]
7272
signal = frame.signals[0]
7373
assert signal.attributes['LongName'] == 'Access Level : Password'
@@ -96,7 +96,7 @@ def test_export_default_decimal_places(is_float, value, expected):
9696
signal.add_attribute('GenSigStartValue', value)
9797
frame.add_signal(signal)
9898

99-
s = canmatrix.sym.create_signal(db=matrix, signal=signal)
99+
s = canmatrix.formats.sym.create_signal(db=matrix, signal=signal)
100100

101101
start = '/d:'
102102

@@ -137,7 +137,7 @@ def tests_parse_float(variable_type, bit_length):
137137
).encode('utf-8'),
138138
)
139139

140-
matrix = canmatrix.sym.load(f)
140+
matrix = canmatrix.formats.sym.load(f)
141141
assert matrix.load_errors == []
142142
frame = matrix.frames[0]
143143
signal = frame.signals[0]

src/canmatrix/tests/test_xls.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import canmatrix.xls
1+
import canmatrix.formats.xls
22
import decimal
33

44

55
def test_parse_value_name_collumn():
66
value_column = "1..5"
7-
(mini, maxi, offset, value_table) = canmatrix.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
7+
(mini, maxi, offset, value_table) = canmatrix.formats.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
88
assert maxi == 5
99
assert mini == 1
1010
assert offset == 1
1111
assert value_table == dict()
1212

1313
value_column = "LabelX"
14-
(mini, maxi, offset, value_table) = canmatrix.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
14+
(mini, maxi, offset, value_table) = canmatrix.formats.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
1515
assert maxi == 15
1616
assert mini == 0
1717
assert offset == 0

0 commit comments

Comments
 (0)