|
19 | 19 | import tempfile
|
20 | 20 |
|
21 | 21 | from spawnwind.nrel.nrel_input_line import NrelInputLine
|
22 |
| -from spawnwind.nrel import TurbsimInput, AerodynInput, FastInput, NRELSimulationInput |
| 22 | +from spawnwind.nrel import TurbsimInput, AerodynInput, NRELSimulationInput, Fast7Input, Fast8Input, TurbsimSpawner |
23 | 23 |
|
24 | 24 |
|
25 |
| -@pytest.mark.parametrize('cls,file,key', [ |
26 |
| - (TurbsimInput, 'TurbSim.inp', 'CTStartTime'), |
27 |
| - (AerodynInput, 'NRELOffshrBsline5MW_AeroDyn.ipt', 'BldNodes'), |
28 |
| - (FastInput, 'NRELOffshrBsline5MW_Onshore.fst', 'NBlGages') |
| 25 | +@pytest.fixture(scope='function') |
| 26 | +def turbsim_input(turbsim_input_file): |
| 27 | + return TurbsimInput.from_file(turbsim_input_file) |
| 28 | + |
| 29 | +@pytest.fixture(scope='function') |
| 30 | +def aerodyn_input(turbsim_input_file, base_fast_input_folder): |
| 31 | + input_file = path.join(base_fast_input_folder, 'v7', 'NRELOffshrBsline5MW_AeroDyn.ipt') |
| 32 | + return AerodynInput.from_file(input_file, TurbsimSpawner(TurbsimInput.from_file(turbsim_input_file))) |
| 33 | + |
| 34 | +@pytest.fixture(scope='function') |
| 35 | +def fast7_input(base_fast_input_folder): |
| 36 | + input_file = path.join(base_fast_input_folder, 'v7', 'NRELOffshrBsline5MW_Onshore.fst') |
| 37 | + return Fast7Input.from_file(input_file) |
| 38 | + |
| 39 | +@pytest.fixture(scope='function') |
| 40 | +def fast8_input(base_fast_input_folder): |
| 41 | + input_file = path.join(base_fast_input_folder, 'v8', 'NREL5MW.fst') |
| 42 | + return Fast8Input.from_file(input_file) |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.parametrize('input_fixture,key', [ |
| 46 | + ('turbsim_input', 'CTStartTime'), |
| 47 | + ('fast7_input', 'NBlGages'), |
| 48 | + ('fast8_input', 'TMax') |
29 | 49 | ])
|
30 |
| -def test_read_write_round_trip(examples_folder, cls, file, key): |
31 |
| - _input = cls.from_file(path.join(examples_folder, file)) |
| 50 | +def test_read_write_round_trip(input_fixture, key, request): |
| 51 | + _input = request.getfixturevalue(input_fixture) |
32 | 52 | with tempfile.TemporaryDirectory() as outfile:
|
33 | 53 | name = path.join(outfile, 'temp.txt')
|
34 | 54 | _input.to_file(name)
|
35 |
| - _input2 = cls.from_file(name) |
| 55 | + _input2 = _input.__class__.from_file(name) |
36 | 56 | assert _input[key] == _input2[key]
|
37 | 57 |
|
38 | 58 |
|
39 |
| -@pytest.mark.parametrize('cls,file,key,value', [ |
40 |
| - (TurbsimInput, 'TurbSim.inp', 'URef', 11.0), |
41 |
| - (AerodynInput, 'NRELOffshrBsline5MW_AeroDyn.ipt', 'WindFile', 'Other.wnd'), |
42 |
| - (FastInput, 'NRELOffshrBsline5MW_Onshore.fst', 'TMax', 300.0) |
| 59 | +@pytest.mark.parametrize('input_fixture,key,value', [ |
| 60 | + ('turbsim_input', 'URef', 11.0), |
| 61 | + ('fast7_input', 'TMax', 300.0), |
| 62 | + ('fast8_input', 'DT', 0.001) |
43 | 63 | ])
|
44 |
| -def test_writes_edited_Specification(examples_folder, cls, file, key, value): |
45 |
| - _input = cls.from_file(path.join(examples_folder, file)) |
| 64 | +def test_writes_edited_Specification(input_fixture, key, value, request): |
| 65 | + _input = request.getfixturevalue(input_fixture) |
46 | 66 | _input[key] = value
|
47 | 67 | with tempfile.TemporaryDirectory() as outfile:
|
48 | 68 | name = path.join(outfile, 'temp.txt')
|
49 | 69 | _input.to_file(name)
|
50 |
| - _input2 = cls.from_file(name) |
| 70 | + _input2 = _input.__class__.from_file(name) |
51 | 71 | assert _input2[key] == str(value)
|
52 | 72 |
|
53 | 73 |
|
54 |
| -@pytest.mark.parametrize('cls,file,keys', [ |
55 |
| - (AerodynInput, 'NRELOffshrBsline5MW_AeroDyn.ipt', ['FoilNm']), |
56 |
| - (FastInput, 'NRELOffshrBsline5MW_Onshore.fst', ['BldFile(1)', 'BldFile(3)', 'TwrFile']) |
| 74 | +@pytest.mark.parametrize('input_fixture,keys', [ |
| 75 | + ('aerodyn_input', ['FoilNm']), |
| 76 | + ('fast7_input', ['BldFile(1)', 'BldFile(3)', 'TwrFile']), |
| 77 | + ('fast8_input', ['EDFile', 'InflowFile', 'ServoFile', 'AeroFile']) |
57 | 78 | ])
|
58 |
| -def test_paths_are_absolute(examples_folder, cls, file, keys): |
59 |
| - _input = cls.from_file(path.join(examples_folder, file)) |
| 79 | +def test_paths_are_absolute(input_fixture, keys, request): |
| 80 | + _input = request.getfixturevalue(input_fixture) |
60 | 81 | for k in keys:
|
61 | 82 | f = _input[k]
|
62 | 83 | #sanitise windows paths
|
63 | 84 | assert path.isfile(path.sep.join(f.split('\\')))
|
64 | 85 |
|
65 | 86 |
|
66 |
| -@pytest.mark.parametrize('cls,file,key', [ |
67 |
| - (AerodynInput, 'NRELOffshrBsline5MW_AeroDyn.ipt', 'WindFile'), |
68 |
| - (FastInput, 'NRELOffshrBsline5MW_Onshore.fst', 'TwrFile') |
| 87 | +@pytest.mark.parametrize('input_fixture,key', [ |
| 88 | + ('aerodyn_input', 'WindFile'), |
| 89 | + ('fast7_input', 'TwrFile'), |
| 90 | + ('fast8_input', 'EDFile') |
69 | 91 | ])
|
70 |
| -def test_can_handle_spaces_in_paths(examples_folder, cls, file, key): |
71 |
| - _input = cls.from_file(path.join(examples_folder, file)) |
| 92 | +def test_can_handle_spaces_in_paths(input_fixture, key, request): |
| 93 | + _input = request.getfixturevalue(input_fixture) |
72 | 94 | spacey_path = '"C:/this is a spacey/path.ipt"'
|
73 | 95 | _input[key] = spacey_path
|
74 | 96 | assert spacey_path.strip('"') == _input[key].strip('"')
|
|
0 commit comments