Skip to content

Commit 687e848

Browse files
author
Fabian Beitler
authored
Rebase on master (#254)
Remove trailing whitespace Workaround,otherwise KeyError is raised before assertRaises checks if Error is raised Check each error individual Fix wrong Error Add indented and commented test spec Add test for multiple indent formats Add support for indented DB layout specifications Fix for #133 Remove asserts from non tests (#250) * Replace assert statements with if/else statements Fix for #215 * Change ValueErrors to better type TypeErrors * Fix wrong isinstance request back to "not in" check Fix tests to await correct Error * Fix wrong Error types Replace "is False" with a better "not" statement * Fix wrong errortype * Use Snap7Exception to use unified error messages * Fix expected exception to Snap7Exception to be consistent. * Replace TypeError with Snap7Exception to seperate python- and snap7 type errors * Replace Snap7Exceptions with better ValueError * Change Snap7Exception with excepted ValueError * Remove unuesed imports replace Snap7Exception with ValueError
1 parent f525d35 commit 687e848

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

snap7/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def parse_specification(db_specification: str) -> OrderedDict:
403403
parsed_db_specification = OrderedDict()
404404

405405
for line in db_specification.split('\n'):
406-
if line and not (line.isspace() or line[0] == '#'):
406+
if line and not line.lstrip().startswith('#'):
407407
index, var_name, _type = line.split('#')[0].split()
408408
parsed_db_specification[var_name] = (index, _type)
409409

test/test_util.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@
2727
44 testsint0 SINT
2828
"""
2929

30+
test_spec_indented = """
31+
32+
4 ID INT
33+
6 NAME STRING[4]
34+
35+
12.0 testbool1 BOOL
36+
12.1 testbool2 BOOL
37+
12.2 testbool3 BOOL
38+
# 12.3 testbool4 BOOL
39+
# 12.4 testbool5 BOOL
40+
# 12.5 testbool6 BOOL
41+
# 12.6 testbool7 BOOL
42+
12.7 testbool8 BOOL
43+
13 testReal REAL
44+
17 testDword DWORD
45+
21 testint2 INT
46+
23 testDint DINT
47+
27 testWord WORD
48+
29 tests5time S5TIME
49+
31 testdateandtime DATE_AND_TIME
50+
43 testusint0 USINT
51+
44 testsint0 SINT
52+
"""
53+
54+
3055
_bytearray = bytearray([
3156
0, 0, # test int
3257
4, 4, ord('t'), ord('e'), ord('s'), ord('t'), # test string
@@ -252,6 +277,30 @@ def test_export(self):
252277
self.assertIn('testbool1', data)
253278
self.assertEqual(data['testbool5'], 0)
254279

280+
def test_indented_layout(self):
281+
test_array = bytearray(_bytearray)
282+
row = util.DB_Row(test_array, test_spec_indented, layout_offset=4)
283+
x = row['ID']
284+
y_single_space = row['testbool1']
285+
y_multi_space = row['testbool2']
286+
y_single_indent = row['testint2']
287+
y_multi_indent = row['testbool8']
288+
289+
with self.assertRaises(KeyError):
290+
fail_single_space = row['testbool4']
291+
with self.assertRaises(KeyError):
292+
fail_multiple_spaces = row['testbool5']
293+
with self.assertRaises(KeyError):
294+
fail_single_indent = row['testbool6']
295+
with self.assertRaises(KeyError):
296+
fail_multiple_indent = row['testbool7']
297+
298+
self.assertEqual(x, 0)
299+
self.assertEqual(y_single_space, True)
300+
self.assertEqual(y_multi_space, True)
301+
self.assertEqual(y_single_indent, 0)
302+
self.assertEqual(y_multi_indent, 0)
303+
255304

256305
def print_row(data):
257306
"""print a single db row in chr and str

0 commit comments

Comments
 (0)