Coverage for fixtures\msw_fixture.py: 16%

1 import pytest

2

3

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")

7 def fixed_format_parser():

8 def function(file, metadata_dict):

9 results = {}

10 for key in metadata_dict:

11 results[key] = []

12

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

28

29 return function