1
-
2
- from snap7 .s7util import db
3
1
import unittest
4
2
import re
5
3
4
+ from snap7 import util
5
+
6
+
6
7
test_spec = """
7
8
8
9
4 ID INT
@@ -38,38 +39,38 @@ def test_get_string(self):
38
39
"""
39
40
test_array = bytearray (_bytearray )
40
41
41
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
42
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
42
43
self .assertTrue (row ['NAME' ] == 'test' )
43
44
44
45
def test_write_string (self ):
45
46
test_array = bytearray (_bytearray )
46
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
47
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
47
48
row ['NAME' ] = 'abc'
48
49
self .assertTrue (row ['NAME' ] == 'abc' )
49
50
row ['NAME' ] = ''
50
51
self .assertTrue (row ['NAME' ] == '' )
51
52
52
53
def test_get_int (self ):
53
54
test_array = bytearray (_bytearray )
54
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
55
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
55
56
x = row ['ID' ]
56
57
self .assertTrue (x == 0 )
57
58
58
59
def test_set_int (self ):
59
60
test_array = bytearray (_bytearray )
60
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
61
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
61
62
row ['ID' ] = 259
62
63
self .assertTrue (row ['ID' ] == 259 )
63
64
64
65
def test_get_bool (self ):
65
66
test_array = bytearray (_bytearray )
66
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
67
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
67
68
self .assertTrue (row ['testbool1' ] == 1 )
68
69
self .assertTrue (row ['testbool8' ] == 0 )
69
70
70
71
def test_set_bool (self ):
71
72
test_array = bytearray (_bytearray )
72
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
73
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
73
74
row ['testbool8' ] = 1
74
75
row ['testbool1' ] = 0
75
76
@@ -79,7 +80,7 @@ def test_set_bool(self):
79
80
def test_db_creation (self ):
80
81
test_array = bytearray (_bytearray * 10 )
81
82
82
- test_db = db .DB (1 , test_array , test_spec ,
83
+ test_db = util .DB (1 , test_array , test_spec ,
83
84
row_size = len (_bytearray ),
84
85
size = 10 ,
85
86
layout_offset = 4 ,
@@ -102,29 +103,29 @@ def test_db_creation(self):
102
103
103
104
def test_get_real (self ):
104
105
test_array = bytearray (_bytearray )
105
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
106
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
106
107
self .assertTrue (0.01 > (row ['testReal' ] - 827.3 ) > - 0.1 )
107
108
108
109
def test_set_real (self ):
109
110
test_array = bytearray (_bytearray )
110
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
111
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
111
112
row ['testReal' ] = 1337.1337
112
113
self .assertTrue (0.01 > (row ['testReal' ] - 1337.1337 ) > - 0.01 )
113
114
114
115
def test_set_dword (self ):
115
116
test_array = bytearray (_bytearray )
116
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
117
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
117
118
row ['testDword' ] = 9999999
118
119
self .assertTrue (row ['testDword' ] == 9999999 )
119
120
120
121
def test_get_dword (self ):
121
122
test_array = bytearray (_bytearray )
122
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
123
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
123
124
self .assertTrue (row ['testDword' ] == 869486148 )
124
125
125
126
def test_export (self ):
126
127
test_array = bytearray (_bytearray )
127
- row = db .DB_Row (test_array , test_spec , layout_offset = 4 )
128
+ row = util .DB_Row (test_array , test_spec , layout_offset = 4 )
128
129
data = row .export ()
129
130
self .assertTrue ('testDword' in data )
130
131
self .assertTrue ('testbool1' in data )
0 commit comments