3
3
import os
4
4
import shutil
5
5
from collections .abc import Generator
6
- from packaging .version import Version
7
6
8
7
import pytest
8
+ from packaging .version import Version
9
9
10
10
11
11
@contextlib .contextmanager
@@ -61,7 +61,7 @@ def load_component(entry_point):
61
61
Bmi = None
62
62
else :
63
63
Bmi = load_component (class_to_test )
64
- INPUT_FILE = os .environ .get ("BMITEST_INPUT_FILE" , None )
64
+ INPUT_FILE = os .environ .get ("BMITEST_INPUT_FILE" )
65
65
# BMI_VERSION_STRING = os.environ.get("BMI_VERSION_STRING", "1.1")
66
66
BMI_VERSION_STRING = os .environ .get ("BMI_VERSION_STRING" , "2.0" )
67
67
BMI_VERSION = Version (BMI_VERSION_STRING )
@@ -87,9 +87,9 @@ def get_test_parameters(infile=None, count=0):
87
87
infile = infile or INPUT_FILE
88
88
89
89
try :
90
- with open (".ROOT_DIR" , "r" ) as fp :
90
+ with open (".ROOT_DIR" ) as fp :
91
91
root_dir = fp .read ()
92
- except IOError :
92
+ except OSError :
93
93
root_dir = "."
94
94
if count > 1 :
95
95
raise RuntimeError ()
@@ -127,7 +127,7 @@ def bmi():
127
127
128
128
@pytest .fixture (scope = "session" )
129
129
def initialized_bmi (tmpdir_factory , infile = None , manifest = None ):
130
- infile = os .environ .get ("BMITEST_INPUT_FILE" , None )
130
+ infile = os .environ .get ("BMITEST_INPUT_FILE" )
131
131
manifest = os .environ .get ("BMITEST_MANIFEST" , infile or "" ).splitlines ()
132
132
133
133
tmp = tmpdir_factory .mktemp ("data" )
@@ -145,12 +145,13 @@ def initialized_bmi(tmpdir_factory, infile=None, manifest=None):
145
145
146
146
@pytest .fixture (scope = "function" )
147
147
def staged_tmpdir (tmpdir , infile = None , manifest = None ):
148
- infile = os .environ .get ("BMITEST_INPUT_FILE" , None )
148
+ infile = os .environ .get ("BMITEST_INPUT_FILE" )
149
149
manifest = os .environ .get ("BMITEST_MANIFEST" , infile or "" ).splitlines ()
150
150
with tmpdir .as_cwd () as prev :
151
151
for file_ in [fname .strip () for fname in manifest ]:
152
152
if file_ :
153
- cp (os .path .join (str (prev ), file_ ), tmpdir / file_ , create_dirs = True )
153
+ os .makedirs (tmpdir / os .path .dirname (file_ ), exist_ok = True )
154
+ shutil .copy2 (prev / file_ , tmpdir / file_ )
154
155
return tmpdir
155
156
156
157
0 commit comments