Coverage for fixtures\msw_fixture.py: 95%
19 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-08 14:15 +0200
1import pytest
4# Seperate function from the one in fixed_format module. This one fails if not
5# able to read value for tests.
6@pytest.fixture(scope="session")
7def fixed_format_parser():
8 def function(file, metadata_dict):
9 results = {}
10 for key in metadata_dict:
11 results[key] = []
13 with open(file) as f:
14 lines = f.readlines()
15 for line in lines:
16 if line == "\n":
17 continue
18 for varname, metadata in metadata_dict.items():
19 # Take first part of line
20 value = line[: metadata.column_width]
21 # Convert to correct type
22 converted_value = metadata.dtype(value)
23 # Add to results
24 results[varname].append(converted_value)
25 # Truncate line
26 line = line[metadata.column_width :]
27 return results
29 return function