Skip to content

Refactor/remove tests from src #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ tasks:
lint:
desc: Lints the code and reports on issues.
cmds:
- poetry run black --check lasso
- poetry run ruff check
- poetry run black --check .
- poetry run ruff check .

build:
desc: Builds the python package
Expand All @@ -21,7 +21,7 @@ tasks:
desc: Runs tests on the code
cmds:
- >
poetry run pytest
poetry run pytest test
--cov=lasso
--cov-report=html

Expand Down
Empty file added test/__init__.py
Empty file.
64 changes: 11 additions & 53 deletions lasso/dimred/test_plot_creator.py → test/plot_creator_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from lasso.dyna.d3plot import ArrayType, D3plot


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


def create_2_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5):
def create_n_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5, n=50):
"""
creates 2 faked plots

Parameters
----------
folder: str
folder path
n_nodes_x: int
how many nodes in x
n_nodes_y: int
how many nodes in y
n_timesteps: int, default: 5
how many timesteps
"""

randy_random = random.Random("The_Seed")
plot_name = "SVDTestPlot{i}"

element_shell_node_indexes = create_element_shell_node_indexes(
n_nodes_x=n_nodes_x, n_nodes_y=n_nodes_y
)

create_fake_d3plots(
path=os.path.join(folder, plot_name.format(i="00")),
element_shell_node_indexes=element_shell_node_indexes,
bend_multiplicator=5 * (1 + randy_random.random()),
n_nodes_x=n_nodes_x,
n_nodes_y=n_nodes_y,
n_timesteps=n_timesteps,
)

create_fake_d3plots(
path=os.path.join(folder, plot_name.format(i="01")),
element_shell_node_indexes=element_shell_node_indexes,
bend_multiplicator=5 * (1 + randy_random.random()),
n_nodes_x=n_nodes_x,
n_nodes_y=n_nodes_y,
n_timesteps=n_timesteps,
)


def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timesteps=5):
"""
creates 50 faked plots, 25 bending up, 25 bending down
creates `n` fake plots, `n/2` bending up, `n/2` bending down

Parameters
----------
Expand All @@ -164,6 +123,8 @@ def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timestep
how many nodes in y
n_timesteps: int, default: 5
how many timesteps
n: int, default: 50
how many plots
"""

# init random
Expand All @@ -176,24 +137,21 @@ def create_50_fake_plots(folder: str, n_nodes_x: int, n_nodes_y: int, n_timestep
n_nodes_x=n_nodes_x, n_nodes_y=n_nodes_y
)

# 25 plots bending up
for i in range(25):
nr = str(i)
if i < 10:
nr = "0" + str(i)
# n plots bending up
for i in range(int(n / 2)):
create_fake_d3plots(
path=os.path.join(folder, plot_name.format(i=nr)),
path=os.path.join(folder, plot_name.format(i=f"{i:02d}")),
element_shell_node_indexes=element_shell_node_indexes,
bend_multiplicator=5 * (1 + randy_random.random()),
n_nodes_x=n_nodes_x,
n_nodes_y=n_nodes_y,
n_timesteps=n_timesteps,
)

# 25 plots bending down
for i in range(25):
# n plots bending down
for i in range(int(n / 2)):
create_fake_d3plots(
path=os.path.join(folder, plot_name.format(i=i + 25)),
path=os.path.join(folder, plot_name.format(i=f"{i+int(n/2):02d}")),
element_shell_node_indexes=element_shell_node_indexes,
bend_multiplicator=-5 * (1 + randy_random.random()),
n_nodes_x=n_nodes_x,
Expand Down
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.
Empty file added test/unit_tests/__init__.py
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

from lasso.dimred.svd.subsampling_methods import create_reference_subsample, remap_random_subsample
from lasso.dimred.test_plot_creator import create_2_fake_plots
from test.plot_creator_helper import create_n_fake_plots


class TestSubsampling(TestCase):
Expand All @@ -15,7 +15,7 @@ def test_create_reference_sample(self):

with tempfile.TemporaryDirectory() as tmp_dir:

create_2_fake_plots(tmp_dir, 500, 10)
create_n_fake_plots(tmp_dir, 500, 10, n=2)
load_path = os.path.join(tmp_dir, "SVDTestPlot00/plot")
n_nodes = 200

Expand Down Expand Up @@ -55,7 +55,7 @@ def test_remap_random_subsample(self):

with tempfile.TemporaryDirectory() as tmp_dir:

create_2_fake_plots(tmp_dir, 500, 10)
create_n_fake_plots(tmp_dir, 500, 10, n=2)
ref_path = os.path.join(tmp_dir, "SVDTestPlot00/plot")
sample_path = os.path.join(tmp_dir, "SVDTestPlot01/plot")
n_nodes = 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
import numpy as np

from lasso.dimred.dimred_run import DIMRED_STAGES, DimredRun, DimredRunError, HDF5FileNames
from lasso.dimred.test_plot_creator import create_50_fake_plots
from test.plot_creator_helper import create_n_fake_plots


class TestDimredRun(TestCase):
def test_run(self):
"""Verifies correct function of DimredRun.py"""
verification_hdf5_file = h5py.File("test/DimredRunTest/verificationFile.hdf5", "r")
verification_hdf5_file = h5py.File(
"test/test_data/DimredRunTest/verificationFile.hdf5", "r"
)

with tempfile.TemporaryDirectory() as tmpdir:

# create simulation runs
create_50_fake_plots(folder=tmpdir, n_nodes_x=500, n_nodes_y=10)
create_n_fake_plots(folder=tmpdir, n_nodes_x=500, n_nodes_y=10)

# collect all simulation runs
# sim_dir = "test/dimredTestPlots"
Expand All @@ -33,7 +35,7 @@ def test_run(self):
start_stage=DIMRED_STAGES[0],
end_stage="CLUSTERING",
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
cluster_args=["kmeans"],
)
Expand Down Expand Up @@ -138,7 +140,7 @@ def test_run(self):
simulation_runs=os.path.join(tmpdir, "SVDTestPlot*/plot"),
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[0],
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
console=None,
)

Expand All @@ -161,7 +163,7 @@ def test_for_errors(self):
start_stage="INVALID_START",
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)

Expand All @@ -174,7 +176,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage="INVALID_END",
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)

Expand All @@ -187,7 +189,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[-1],
end_stage=DIMRED_STAGES[0],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)

Expand All @@ -199,7 +201,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)

Expand All @@ -211,7 +213,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
cluster_args=["noMeans"],
)
Expand All @@ -224,7 +226,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
cluster_args=["kmeans"],
outlier_args=["DoesNotExist"],
Expand All @@ -239,7 +241,7 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)
# check for empty simulation runs
Expand All @@ -250,13 +252,13 @@ def test_for_errors(self):
start_stage=DIMRED_STAGES[0],
end_stage=DIMRED_STAGES[-1],
console=None,
project_dir="test/DimredRunTest",
project_dir="test/test_data/DimredRunTest",
n_processes=5,
)

def tearDown(self):
# cleanup of created files
test_files = os.listdir("test/DimredRunTest")
test_files = os.listdir("test/test_data/DimredRunTest")
test_files.pop(test_files.index("verificationFile.hdf5"))
for entry in test_files:
os.remove(os.path.join("test/DimredRunTest", entry))
os.remove(os.path.join("test/test_data/DimredRunTest", entry))
Empty file.
30 changes: 15 additions & 15 deletions lasso/dyna/test_d3plot.py → test/unit_tests/dyna/test_d3plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_init(self):
# settings
self.maxDiff = None

filepath = "test/simple_d3plot/d3plot"
filepath = "test/test_data/simple_d3plot/d3plot"

geometry_array_shapes = {
"node_coordinates": (4915, 3),
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_header(self):
"neipb": 0,
}

d3plot = D3plot("test/simple_d3plot/d3plot")
d3plot = D3plot("test/test_data/simple_d3plot/d3plot")
header = d3plot.header

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

self.maxDiff = None

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

def test_correct_sort_of_more_than_100_state_files(self):

filepath = "test/order_d3plot/d3plot"
filepath = "test/test_data/order_d3plot/d3plot"

d3plot = D3plot(filepath)

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

self.maxDiff = None

filepath1 = "test/femzip/d3plot.fz"
filepath2 = "test/femzip/d3plot"
filepath1 = "test/test_data/femzip/d3plot.fz"
filepath2 = "test/test_data/femzip/d3plot"

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

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

self.maxDiff = None

filepath1 = "test/femzip/d3plot.fz"
filepath2 = "test/femzip/d3plot"
filepath1 = "test/test_data/femzip/d3plot.fz"
filepath2 = "test/test_data/femzip/d3plot"

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

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

self.maxDiff = None

filepath = "test/simple_d3plot/d3plot"
filepath = "test/test_data/simple_d3plot/d3plot"
part_ids = [1]

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

def test_read_solid_integration_points(self):

filepath = "test/d3plot_solid_int/d3plot"
filepath = "test/test_data/d3plot_solid_int/d3plot"

# data from META
stress_valid = np.array(
Expand Down Expand Up @@ -345,10 +345,10 @@ def test_write(self):
self.maxDiff = None

filepaths = [
"test/simple_d3plot/d3plot",
"test/d3plot_beamip/d3plot",
"test/d3plot_node_temperature/d3plot",
"test/d3plot_solid_int/d3plot",
"test/test_data/simple_d3plot/d3plot",
"test/test_data/d3plot_beamip/d3plot",
"test/test_data/d3plot_node_temperature/d3plot",
"test/test_data/d3plot_solid_int/d3plot",
]

d3plot_kwargs_list = [
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_append_4_shell_hists_then_read_bug(self):
def test_reading_selected_states(self):

# read all states
filepath = "test/d3plot_solid_int/d3plot"
filepath = "test/test_data/d3plot_solid_int/d3plot"

d3plot = D3plot(filepath)
d3plot2 = D3plot(filepath, state_filter=np.arange(0, 22))
Expand Down
Loading