Skip to content

Commit

Permalink
move formats to submodule (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker committed Feb 26, 2019
1 parent cf8e53e commit 1376ab5
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

for module in moduleList:
try:
import_module("canmatrix." + module)
import_module("canmatrix.formats." + module)
loadedFormats.append(module)
except ImportError:
logger.info("%s is not supported", module)

for loadedModule in loadedFormats:
supportedFormats[loadedModule] = []
moduleInstance = sys.modules["canmatrix." + loadedModule]
moduleInstance = sys.modules["canmatrix.formats." + loadedModule]
if "load" in dir(moduleInstance):
supportedFormats[loadedModule].append("load")
if "dump" in dir(moduleInstance):
Expand Down Expand Up @@ -69,7 +69,7 @@ def loadp(path, importType=None, key="", flatImport=None, **options):

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


def dump(canMatrixOrCluster, fileObject, exportType, **options):
moduleInstance = sys.modules["canmatrix." + exportType]
moduleInstance = sys.modules["canmatrix.formats." + exportType]
if isinstance(canMatrixOrCluster, canmatrix.CanMatrix):
moduleInstance.dump(canMatrixOrCluster, fileObject, **options)
elif "clusterExporter" in supportedFormats[exportType]:
Expand Down
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.
12 changes: 6 additions & 6 deletions src/canmatrix/xls.py → src/canmatrix/formats/xls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import xlwt
import canmatrix
import canmatrix.xls_common
import canmatrix.formats.xls_common
import xlrd
import decimal

Expand Down Expand Up @@ -205,7 +205,7 @@ def dump(db, file, **options):
# iterate over signals
rowArray = []
if len(sigHash) == 0: # Frames without signals
rowArray += canmatrix.xls_common.get_frame_info(db, frame)
rowArray += canmatrix.formats.xls_common.get_frame_info(db, frame)
for item in range(5, head_start):
rowArray.append("")
tempCol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
Expand Down Expand Up @@ -233,7 +233,7 @@ def dump(db, file, **options):
valstyle = sigstyle
# iterate over values in valuetable
for val in sorted(sig.values.keys()):
rowArray = canmatrix.xls_common.get_frame_info(db, frame)
rowArray = canmatrix.formats.xls_common.get_frame_info(db, frame)
frontcol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
if framestyle != sty_first_frame:
worksheet.row(row).level = 1
Expand All @@ -242,7 +242,7 @@ def dump(db, file, **options):
col = writeBuMatrix(buList, sig, frame, worksheet, row, col, framestyle)

# write Value
(frontRow, backRow) = canmatrix.xls_common.get_signal(db, sig, motorolaBitFormat)
(frontRow, backRow) = canmatrix.formats.xls_common.get_signal(db, sig, motorolaBitFormat)
writeExcelLine(worksheet, row, frontcol, frontRow, sigstyle)
backRow += additionalFrameInfo
for item in additional_signal_colums:
Expand All @@ -262,15 +262,15 @@ def dump(db, file, **options):
# loop over values ends here
# no valuetable available
else:
rowArray = canmatrix.xls_common.get_frame_info(db, frame)
rowArray = canmatrix.formats.xls_common.get_frame_info(db, frame)
frontcol = writeExcelLine(worksheet, row, 0, rowArray, framestyle)
if framestyle != sty_first_frame:
worksheet.row(row).level = 1

col = head_start
col = writeBuMatrix(
buList, sig, frame, worksheet, row, col, framestyle)
(frontRow,backRow) = canmatrix.xls_common.get_signal(db, sig, motorolaBitFormat)
(frontRow,backRow) = canmatrix.formats.xls_common.get_signal(db, sig, motorolaBitFormat)
writeExcelLine(worksheet, row, frontcol, frontRow, sigstyle)

if float(sig.min) != 0 or float(sig.max) != 1.0:
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/canmatrix/tests/test_arxml.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
import canmatrix.arxml
import canmatrix.formats.arxml
import pathlib2


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

db = canmatrix.arxml.load(str(here / "MyECU.ecuc.arxml"))['']
db = canmatrix.formats.arxml.load(str(here / "MyECU.ecuc.arxml"))['']
assert db.frames is not None
assert len(db.frames) == 2
assert len(db.frames[0].signals) == 3
Expand Down
30 changes: 15 additions & 15 deletions src/canmatrix/tests/test_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import string
import pytest

import canmatrix.dbc
import canmatrix.formats.dbc


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

matrix = canmatrix.dbc.load(dbc)
matrix = canmatrix.formats.dbc.load(dbc)

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

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


def test_create_attribute_string():
test_string = canmatrix.dbc.create_attribute_string("my_attribute", "BO_", "name", "value", True)
test_string = canmatrix.formats.dbc.create_attribute_string("my_attribute", "BO_", "name", "value", True)
assert test_string == 'BA_ "my_attribute" BO_ name "value";\n'
test_string = canmatrix.dbc.create_attribute_string("my_attribute", "BO_", "name", 1.23, False)
test_string = canmatrix.formats.dbc.create_attribute_string("my_attribute", "BO_", "name", 1.23, False)
assert test_string == 'BA_ "my_attribute" BO_ name 1.23;\n'


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


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

matrix = canmatrix.dbc.load(dbc)
matrix = canmatrix.formats.dbc.load(dbc)
long_name_found = False
name_found = False

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

matrix = canmatrix.dbc.load(dbc)
matrix = canmatrix.formats.dbc.load(dbc)
long_name_found = False
name_found = False

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

matrix = canmatrix.dbc.load(dbc)
matrix = canmatrix.formats.dbc.load(dbc)

assert list(matrix.env_vars)[0] == long_envvar_name
outdbc = io.BytesIO()
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_enum_with_comma():
BA_DEF_DEF_ "example3" ",";
BA_DEF_DEF_ "example4" ",";
''').encode('utf-8'))
matrix = canmatrix.dbc.load(dbc, dbcImportEncoding="utf8")
matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")

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


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

db.add_signal_defines("LongName", 'STR')
for (dataType, define) in db.signal_defines.items():
orig_definition = define.definition
canmatrix.dbc.check_define(define)
canmatrix.formats.dbc.check_define(define)
assert orig_definition != define.definition
frame = canmatrix.Frame("someFrame")
signal = canmatrix.Signal("SomeSignal")
Expand All @@ -201,13 +201,13 @@ def test_export_of_unknown_defines():
db.add_ecu_defines("someName", 'STRING')
for (dataType, define) in db.ecu_defines.items():
orig_definition = define.definition
canmatrix.dbc.check_define(define)
canmatrix.formats.dbc.check_define(define)
assert orig_definition == define.definition

db.add_global_defines("someGlobaName", 'BOOL')
for (dataType, define) in db.global_defines.items():
orig_definition = define.definition
canmatrix.dbc.check_define(define)
canmatrix.formats.dbc.check_define(define)
assert orig_definition != define.definition

outdbc = io.BytesIO()
Expand Down
12 changes: 6 additions & 6 deletions src/canmatrix/tests/test_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

import canmatrix.canmatrix
import canmatrix.sym
import canmatrix.formats.sym


def test_colliding_mux_values():
Expand Down Expand Up @@ -32,13 +32,13 @@ def test_colliding_mux_values():
).encode('utf-8'),
)

matrix = canmatrix.sym.load(f)
matrix = canmatrix.formats.sym.load(f)
error, = matrix.load_errors
line_number = 16

assert len(matrix.load_errors) == 1

assert isinstance(error, canmatrix.sym.DuplicateMuxIdError)
assert isinstance(error, canmatrix.formats.sym.DuplicateMuxIdError)

assert error.line_number == line_number

Expand Down Expand Up @@ -67,7 +67,7 @@ def test_parse_longname_with_colon():
).encode('utf-8'),
)

matrix = canmatrix.sym.load(f)
matrix = canmatrix.formats.sym.load(f)
frame = matrix.frames[0]
signal = frame.signals[0]
assert signal.attributes['LongName'] == 'Access Level : Password'
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_export_default_decimal_places(is_float, value, expected):
signal.add_attribute('GenSigStartValue', value)
frame.add_signal(signal)

s = canmatrix.sym.create_signal(db=matrix, signal=signal)
s = canmatrix.formats.sym.create_signal(db=matrix, signal=signal)

start = '/d:'

Expand Down Expand Up @@ -137,7 +137,7 @@ def tests_parse_float(variable_type, bit_length):
).encode('utf-8'),
)

matrix = canmatrix.sym.load(f)
matrix = canmatrix.formats.sym.load(f)
assert matrix.load_errors == []
frame = matrix.frames[0]
signal = frame.signals[0]
Expand Down
6 changes: 3 additions & 3 deletions src/canmatrix/tests/test_xls.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import canmatrix.xls
import canmatrix.formats.xls
import decimal


def test_parse_value_name_collumn():
value_column = "1..5"
(mini, maxi, offset, value_table) = canmatrix.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
(mini, maxi, offset, value_table) = canmatrix.formats.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
assert maxi == 5
assert mini == 1
assert offset == 1
assert value_table == dict()

value_column = "LabelX"
(mini, maxi, offset, value_table) = canmatrix.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
(mini, maxi, offset, value_table) = canmatrix.formats.xls.parse_value_name_column(value_column, "5", 4, decimal.Decimal)
assert maxi == 15
assert mini == 0
assert offset == 0
Expand Down

0 comments on commit 1376ab5

Please sign in to comment.