-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
115 lines (95 loc) · 4.32 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# spawn
# Copyright (C) 2018, Simmovation Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from os import path, pardir
import pytest
import luigi.configuration
from spawn.plugins import PluginLoader
from spawn.config import DefaultConfiguration, CompositeConfiguration, CommandLineConfiguration
from spawnwind.nrel import TurbsimInput, Fast7Input, Fast8Input, TurbsimSpawner, FastSimulationSpawner
__home_dir = path.dirname(path.realpath(__file__))
_example_data_folder = path.join(__home_dir, pardir, 'example_data')
_fast_exe_paths = {
'v7': path.join(_example_data_folder, 'bin', 'FASTv7.0.2.exe'),
'v8': path.join(_example_data_folder, 'bin', 'FASTv8.16_Win32.exe')
}
@pytest.fixture(scope='session')
def turbsim_exe():
return path.join(_example_data_folder, 'bin', 'TurbSim.exe')
@pytest.fixture(scope='session', autouse=True)
def configure_luigi(turbsim_exe):
luigi.configuration.get_config().set('WindGenerationTask', '_runner_type', 'process')
luigi.configuration.get_config().set('WindGenerationTask', '_exe_path', turbsim_exe)
luigi.configuration.get_config().set('FastSimulationTask', '_runner_type', 'process')
@pytest.fixture(params=['v7', 'v8'], scope='module')
def fast_version(request):
luigi.configuration.get_config().set('FastSimulationTask', '_exe_path', _fast_exe_paths[request.param])
return request.param
@pytest.fixture(scope='module')
def exe_paths(turbsim_exe, fast_version):
return {
'turbsim': turbsim_exe,
'fast': _fast_exe_paths[fast_version]
}
@pytest.fixture()
def fast_exe(exe_paths):
return exe_paths['fast']
@pytest.fixture(scope='module')
def turbsim_input_file():
return path.join(_example_data_folder, 'fast_input_files', 'TurbSim.inp')
@pytest.fixture(scope='module')
def inflowwind_input_file():
return path.join(_example_data_folder, 'fast_input_files', 'v8', 'InflowWind.inp')
@pytest.fixture(scope='module')
def base_fast_input_folder():
return path.join(_example_data_folder, 'fast_input_files')
@pytest.fixture(scope='module')
def fast_input_folder(fast_version):
return path.join(_example_data_folder, 'fast_input_files', fast_version)
@pytest.fixture(scope='module')
def fast_input_file(fast_version, fast_input_folder):
if fast_version == 'v7':
return path.join(fast_input_folder, 'NRELOffshrBsline5MW_Onshore.fst')
elif fast_version == 'v8':
return path.join(fast_input_folder, 'NREL5MW.fst')
@pytest.fixture(scope='function')
def fast_input(fast_version, fast_input_file):
if fast_version == 'v7':
return Fast7Input.from_file(fast_input_file)
elif fast_version == 'v8':
return Fast8Input.from_file(fast_input_file)
@pytest.fixture(scope='module')
def example_data_folder():
return _example_data_folder
@pytest.fixture
def wind_gen_spawner(turbsim_input_file):
return TurbsimSpawner(TurbsimInput.from_file(turbsim_input_file))
@pytest.fixture
def spawner(wind_gen_spawner, fast_v7_input_file, tmpdir):
return FastSimulationSpawner(Fast7Input.from_file(fast_v7_input_file), wind_gen_spawner, tmpdir)
@pytest.fixture
def plugin_loader(tmpdir, fast_version, fast_input_file, exe_paths, turbsim_input_file):
default_config = DefaultConfiguration()
command_line_configuration = CommandLineConfiguration(
turbsim_exe=exe_paths['turbsim'], fast_exe=exe_paths['fast'],
turbsim_base_file=turbsim_input_file,
fast_base_file=fast_input_file,
fast_version=fast_version,
turbsim_working_dir=path.join(_example_data_folder, 'bin'),
fast_working_dir=path.join(_example_data_folder, 'bin'),
outdir=str(tmpdir)
)
return PluginLoader(CompositeConfiguration(command_line_configuration, default_config))