|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 |
|
8 | | -from snap7.tags import Tag, load_csv, load_json, load_tia_xml |
| 8 | +from snap7.tags import Tag, from_browse, load_csv, load_json, load_tia_xml |
9 | 9 | from snap7.type import Area |
10 | 10 |
|
11 | 11 |
|
@@ -197,6 +197,37 @@ def test_from_file(self, tmp_path: Path) -> None: |
197 | 197 | assert "Tank.Level" in tags |
198 | 198 |
|
199 | 199 |
|
| 200 | +class TestFromBrowse: |
| 201 | + """from_browse converts browse results to Tag dicts.""" |
| 202 | + |
| 203 | + def test_classic_browse_result(self) -> None: |
| 204 | + variables = [ |
| 205 | + {"name": "Motor.Speed", "db_number": 1, "byte_offset": 0, "data_type": "REAL"}, |
| 206 | + {"name": "Motor.Running", "db_number": 1, "byte_offset": 4, "data_type": "BOOL"}, |
| 207 | + ] |
| 208 | + tags = from_browse(variables) |
| 209 | + assert "Motor.Speed" in tags |
| 210 | + assert tags["Motor.Speed"].byte_offset == 0 |
| 211 | + assert tags["Motor.Speed"].datatype == "REAL" |
| 212 | + assert tags["Motor.Speed"].is_symbolic is False |
| 213 | + |
| 214 | + def test_symbolic_browse_result(self) -> None: |
| 215 | + """When browse includes LID, produce symbolic Tags.""" |
| 216 | + variables = [ |
| 217 | + {"name": "Motor.Speed", "db_number": 1, "byte_offset": 0, |
| 218 | + "data_type": "REAL", "lid": 0xA, "symbol_crc": 0x12345678}, |
| 219 | + ] |
| 220 | + tags = from_browse(variables) |
| 221 | + assert tags["Motor.Speed"].is_symbolic is True |
| 222 | + assert tags["Motor.Speed"].access_sequence == [0xA] |
| 223 | + assert tags["Motor.Speed"].symbol_crc == 0x12345678 |
| 224 | + |
| 225 | + def test_skips_unnamed(self) -> None: |
| 226 | + variables = [{"name": "", "db_number": 1, "byte_offset": 0, "data_type": "BYTE"}] |
| 227 | + tags = from_browse(variables) |
| 228 | + assert len(tags) == 0 |
| 229 | + |
| 230 | + |
200 | 231 | class TestSymbolicAccess: |
201 | 232 | """Tag.from_access_string and symbolic access fields.""" |
202 | 233 |
|
|
0 commit comments