Skip to content

Commit ace221d

Browse files
authored
Merge pull request #72 from laraibg786/refactor/remove_tests_from_src
Refactor/remove tests from src
1 parent c2509bd commit ace221d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+71
-106
lines changed

Taskfile.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ tasks:
99
lint:
1010
desc: Lints the code and reports on issues.
1111
cmds:
12-
- poetry run black --check lasso
13-
- poetry run ruff check
12+
- poetry run black --check .
13+
- poetry run ruff check .
1414

1515
build:
1616
desc: Builds the python package
@@ -21,7 +21,7 @@ tasks:
2121
desc: Runs tests on the code
2222
cmds:
2323
- >
24-
poetry run pytest
24+
poetry run pytest test
2525
--cov=lasso
2626
--cov-report=html
2727

test/__init__.py

Whitespace-only changes.

lasso/dimred/test_plot_creator.py renamed to test/plot_creator_helper.py

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lasso.dyna.d3plot import ArrayType, D3plot
99

1010

11+
# FIXME: there are no tests in this file. probably dead code.
1112
def create_fake_d3plots(
1213
path: str,
1314
element_shell_node_indexes: np.ndarray,
@@ -108,51 +109,9 @@ def create_element_shell_node_indexes(n_nodes_x: int = 500, n_nodes_y: int = 10)
108109
return new_shell_node_indexes
109110

110111

111-
def create_2_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5):
112+
def create_n_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5, n=50):
112113
"""
113-
creates 2 faked plots
114-
115-
Parameters
116-
----------
117-
folder: str
118-
folder path
119-
n_nodes_x: int
120-
how many nodes in x
121-
n_nodes_y: int
122-
how many nodes in y
123-
n_timesteps: int, default: 5
124-
how many timesteps
125-
"""
126-
127-
randy_random = random.Random("The_Seed")
128-
plot_name = "SVDTestPlot{i}"
129-
130-
element_shell_node_indexes = create_element_shell_node_indexes(
131-
n_nodes_x=n_nodes_x, n_nodes_y=n_nodes_y
132-
)
133-
134-
create_fake_d3plots(
135-
path=os.path.join(folder, plot_name.format(i="00")),
136-
element_shell_node_indexes=element_shell_node_indexes,
137-
bend_multiplicator=5 * (1 + randy_random.random()),
138-
n_nodes_x=n_nodes_x,
139-
n_nodes_y=n_nodes_y,
140-
n_timesteps=n_timesteps,
141-
)
142-
143-
create_fake_d3plots(
144-
path=os.path.join(folder, plot_name.format(i="01")),
145-
element_shell_node_indexes=element_shell_node_indexes,
146-
bend_multiplicator=5 * (1 + randy_random.random()),
147-
n_nodes_x=n_nodes_x,
148-
n_nodes_y=n_nodes_y,
149-
n_timesteps=n_timesteps,
150-
)
151-
152-
153-
def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5):
154-
"""
155-
creates 50 faked plots, 25 bending up, 25 bending down
114+
creates `n` fake plots, `n/2` bending up, `n/2` bending down
156115
157116
Parameters
158117
----------
@@ -164,6 +123,8 @@ def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timestep
164123
how many nodes in y
165124
n_timesteps: int, default: 5
166125
how many timesteps
126+
n: int, default: 50
127+
how many plots
167128
"""
168129

169130
# init random
@@ -176,24 +137,21 @@ def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timestep
176137
n_nodes_x=n_nodes_x, n_nodes_y=n_nodes_y
177138
)
178139

179-
# 25 plots bending up
180-
for i in range(25):
181-
nr = str(i)
182-
if i < 10:
183-
nr = "0" + str(i)
140+
# n plots bending up
141+
for i in range(int(n / 2)):
184142
create_fake_d3plots(
185-
path=os.path.join(folder, plot_name.format(i=nr)),
143+
path=os.path.join(folder, plot_name.format(i=f"{i:02d}")),
186144
element_shell_node_indexes=element_shell_node_indexes,
187145
bend_multiplicator=5 * (1 + randy_random.random()),
188146
n_nodes_x=n_nodes_x,
189147
n_nodes_y=n_nodes_y,
190148
n_timesteps=n_timesteps,
191149
)
192150

193-
# 25 plots bending down
194-
for i in range(25):
151+
# n plots bending down
152+
for i in range(int(n / 2)):
195153
create_fake_d3plots(
196-
path=os.path.join(folder, plot_name.format(i=i + 25)),
154+
path=os.path.join(folder, plot_name.format(i=f"{i+int(n/2):02d}")),
197155
element_shell_node_indexes=element_shell_node_indexes,
198156
bend_multiplicator=-5 * (1 + randy_random.random()),
199157
n_nodes_x=n_nodes_x,
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/unit_tests/__init__.py

Whitespace-only changes.

test/unit_tests/dimred/__init__.py

Whitespace-only changes.

test/unit_tests/dimred/svd/__init__.py

Whitespace-only changes.

lasso/dimred/svd/test_subsampling_methods.py renamed to test/unit_tests/dimred/svd/test_subsampling_methods.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import numpy as np
77

88
from lasso.dimred.svd.subsampling_methods import create_reference_subsample, remap_random_subsample
9-
from lasso.dimred.test_plot_creator import create_2_fake_plots
9+
from test.plot_creator_helper import create_n_fake_plots
1010

1111

1212
class TestSubsampling(TestCase):
@@ -15,7 +15,7 @@ def test_create_reference_sample(self):
1515

1616
with tempfile.TemporaryDirectory() as tmp_dir:
1717

18-
create_2_fake_plots(tmp_dir, 500, 10)
18+
create_n_fake_plots(tmp_dir, 500, 10, n=2)
1919
load_path = os.path.join(tmp_dir, "SVDTestPlot00/plot")
2020
n_nodes = 200
2121

@@ -55,7 +55,7 @@ def test_remap_random_subsample(self):
5555

5656
with tempfile.TemporaryDirectory() as tmp_dir:
5757

58-
create_2_fake_plots(tmp_dir, 500, 10)
58+
create_n_fake_plots(tmp_dir, 500, 10, n=2)
5959
ref_path = os.path.join(tmp_dir, "SVDTestPlot00/plot")
6060
sample_path = os.path.join(tmp_dir, "SVDTestPlot01/plot")
6161
n_nodes = 200

lasso/dimred/test_dimred_run.py renamed to test/unit_tests/dimred/test_dimred_run.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
import numpy as np
77

88
from lasso.dimred.dimred_run import DIMRED_STAGES, DimredRun, DimredRunError, HDF5FileNames
9-
from lasso.dimred.test_plot_creator import create_50_fake_plots
9+
from test.plot_creator_helper import create_n_fake_plots
1010

1111

1212
class TestDimredRun(TestCase):
1313
def test_run(self):
1414
"""Verifies correct function of DimredRun.py"""
15-
verification_hdf5_file = h5py.File("test/DimredRunTest/verificationFile.hdf5", "r")
15+
verification_hdf5_file = h5py.File(
16+
"test/test_data/DimredRunTest/verificationFile.hdf5", "r"
17+
)
1618

1719
with tempfile.TemporaryDirectory() as tmpdir:
1820

1921
# create simulation runs
20-
create_50_fake_plots(folder=tmpdir, n_nodes_x=500, n_nodes_y=10)
22+
create_n_fake_plots(folder=tmpdir, n_nodes_x=500, n_nodes_y=10)
2123

2224
# collect all simulation runs
2325
# sim_dir = "test/dimredTestPlots"
@@ -33,7 +35,7 @@ def test_run(self):
3335
start_stage=DIMRED_STAGES[0],
3436
end_stage="CLUSTERING",
3537
console=None,
36-
project_dir="test/DimredRunTest",
38+
project_dir="test/test_data/DimredRunTest",
3739
n_processes=5,
3840
cluster_args=["kmeans"],
3941
)
@@ -138,7 +140,7 @@ def test_run(self):
138140
simulation_runs=os.path.join(tmpdir, "SVDTestPlot*/plot"),
139141
start_stage=DIMRED_STAGES[0],
140142
end_stage=DIMRED_STAGES[0],
141-
project_dir="test/DimredRunTest",
143+
project_dir="test/test_data/DimredRunTest",
142144
console=None,
143145
)
144146

@@ -161,7 +163,7 @@ def test_for_errors(self):
161163
start_stage="INVALID_START",
162164
end_stage=DIMRED_STAGES[-1],
163165
console=None,
164-
project_dir="test/DimredRunTest",
166+
project_dir="test/test_data/DimredRunTest",
165167
n_processes=5,
166168
)
167169

@@ -174,7 +176,7 @@ def test_for_errors(self):
174176
start_stage=DIMRED_STAGES[0],
175177
end_stage="INVALID_END",
176178
console=None,
177-
project_dir="test/DimredRunTest",
179+
project_dir="test/test_data/DimredRunTest",
178180
n_processes=5,
179181
)
180182

@@ -187,7 +189,7 @@ def test_for_errors(self):
187189
start_stage=DIMRED_STAGES[-1],
188190
end_stage=DIMRED_STAGES[0],
189191
console=None,
190-
project_dir="test/DimredRunTest",
192+
project_dir="test/test_data/DimredRunTest",
191193
n_processes=5,
192194
)
193195

@@ -199,7 +201,7 @@ def test_for_errors(self):
199201
start_stage=DIMRED_STAGES[0],
200202
end_stage=DIMRED_STAGES[-1],
201203
console=None,
202-
project_dir="test/DimredRunTest",
204+
project_dir="test/test_data/DimredRunTest",
203205
n_processes=5,
204206
)
205207

@@ -211,7 +213,7 @@ def test_for_errors(self):
211213
start_stage=DIMRED_STAGES[0],
212214
end_stage=DIMRED_STAGES[-1],
213215
console=None,
214-
project_dir="test/DimredRunTest",
216+
project_dir="test/test_data/DimredRunTest",
215217
n_processes=5,
216218
cluster_args=["noMeans"],
217219
)
@@ -224,7 +226,7 @@ def test_for_errors(self):
224226
start_stage=DIMRED_STAGES[0],
225227
end_stage=DIMRED_STAGES[-1],
226228
console=None,
227-
project_dir="test/DimredRunTest",
229+
project_dir="test/test_data/DimredRunTest",
228230
n_processes=5,
229231
cluster_args=["kmeans"],
230232
outlier_args=["DoesNotExist"],
@@ -239,7 +241,7 @@ def test_for_errors(self):
239241
start_stage=DIMRED_STAGES[0],
240242
end_stage=DIMRED_STAGES[-1],
241243
console=None,
242-
project_dir="test/DimredRunTest",
244+
project_dir="test/test_data/DimredRunTest",
243245
n_processes=5,
244246
)
245247
# check for empty simulation runs
@@ -250,13 +252,13 @@ def test_for_errors(self):
250252
start_stage=DIMRED_STAGES[0],
251253
end_stage=DIMRED_STAGES[-1],
252254
console=None,
253-
project_dir="test/DimredRunTest",
255+
project_dir="test/test_data/DimredRunTest",
254256
n_processes=5,
255257
)
256258

257259
def tearDown(self):
258260
# cleanup of created files
259-
test_files = os.listdir("test/DimredRunTest")
261+
test_files = os.listdir("test/test_data/DimredRunTest")
260262
test_files.pop(test_files.index("verificationFile.hdf5"))
261263
for entry in test_files:
262-
os.remove(os.path.join("test/DimredRunTest", entry))
264+
os.remove(os.path.join("test/test_data/DimredRunTest", entry))

test/unit_tests/dyna/__init__.py

Whitespace-only changes.

lasso/dyna/test_d3plot.py renamed to test/unit_tests/dyna/test_d3plot.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_init(self):
1717
# settings
1818
self.maxDiff = None
1919

20-
filepath = "test/simple_d3plot/d3plot"
20+
filepath = "test/test_data/simple_d3plot/d3plot"
2121

2222
geometry_array_shapes = {
2323
"node_coordinates": (4915, 3),
@@ -152,7 +152,7 @@ def test_header(self):
152152
"neipb": 0,
153153
}
154154

155-
d3plot = D3plot("test/simple_d3plot/d3plot")
155+
d3plot = D3plot("test/test_data/simple_d3plot/d3plot")
156156
header = d3plot.header
157157

158158
for name, value in test_header_data.items():
@@ -162,7 +162,7 @@ def test_beam_integration_points(self):
162162

163163
self.maxDiff = None
164164

165-
filepath = "test/d3plot_beamip/d3plot"
165+
filepath = "test/test_data/d3plot_beamip/d3plot"
166166
maxmin_test_values = {
167167
# "element_beam_shear_stress": (-0.007316963, 0.),
168168
"element_beam_shear_stress": (0.0, 0.0056635854),
@@ -188,7 +188,7 @@ def test_beam_integration_points(self):
188188

189189
def test_correct_sort_of_more_than_100_state_files(self):
190190

191-
filepath = "test/order_d3plot/d3plot"
191+
filepath = "test/test_data/order_d3plot/d3plot"
192192

193193
d3plot = D3plot(filepath)
194194

@@ -199,8 +199,8 @@ def test_femzip_basic(self):
199199

200200
self.maxDiff = None
201201

202-
filepath1 = "test/femzip/d3plot.fz"
203-
filepath2 = "test/femzip/d3plot"
202+
filepath1 = "test/test_data/femzip/d3plot.fz"
203+
filepath2 = "test/test_data/femzip/d3plot"
204204

205205
d3plot_kwargs_list = [{}, {"buffered_reading": True}, {"state_filter": [0]}]
206206

@@ -220,8 +220,8 @@ def test_femzip_extended(self):
220220

221221
self.maxDiff = None
222222

223-
filepath1 = "test/femzip/d3plot.fz"
224-
filepath2 = "test/femzip/d3plot"
223+
filepath1 = "test/test_data/femzip/d3plot.fz"
224+
filepath2 = "test/test_data/femzip/d3plot"
225225

226226
d3plot_kwargs_list = [{}, {"buffered_reading": True}, {"state_filter": [0]}]
227227

@@ -245,7 +245,7 @@ def test_part_filter(self):
245245

246246
self.maxDiff = None
247247

248-
filepath = "test/simple_d3plot/d3plot"
248+
filepath = "test/test_data/simple_d3plot/d3plot"
249249
part_ids = [1]
250250

251251
d3plot = D3plot(filepath)
@@ -260,7 +260,7 @@ def test_part_filter(self):
260260

261261
def test_read_solid_integration_points(self):
262262

263-
filepath = "test/d3plot_solid_int/d3plot"
263+
filepath = "test/test_data/d3plot_solid_int/d3plot"
264264

265265
# data from META
266266
stress_valid = np.array(
@@ -345,10 +345,10 @@ def test_write(self):
345345
self.maxDiff = None
346346

347347
filepaths = [
348-
"test/simple_d3plot/d3plot",
349-
"test/d3plot_beamip/d3plot",
350-
"test/d3plot_node_temperature/d3plot",
351-
"test/d3plot_solid_int/d3plot",
348+
"test/test_data/simple_d3plot/d3plot",
349+
"test/test_data/d3plot_beamip/d3plot",
350+
"test/test_data/d3plot_node_temperature/d3plot",
351+
"test/test_data/d3plot_solid_int/d3plot",
352352
]
353353

354354
d3plot_kwargs_list = [
@@ -457,7 +457,7 @@ def test_append_4_shell_hists_then_read_bug(self):
457457
def test_reading_selected_states(self):
458458

459459
# read all states
460-
filepath = "test/d3plot_solid_int/d3plot"
460+
filepath = "test/test_data/d3plot_solid_int/d3plot"
461461

462462
d3plot = D3plot(filepath)
463463
d3plot2 = D3plot(filepath, state_filter=np.arange(0, 22))

0 commit comments

Comments
 (0)