diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..dfeb0c3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +# Marks this as the root directory for all tests. +[tool.pytest.ini_options] diff --git a/tests/test_baseplate.py b/tests/test_baseplate.py index 9984310..f16ebee 100644 --- a/tests/test_baseplate.py +++ b/tests/test_baseplate.py @@ -3,114 +3,110 @@ Tests for gridfinity-rebuilt-baseplate.scad @Copyright Arthur Moore 2024 MIT License """ -import dataclasses -import json -import unittest from pathlib import Path -from tempfile import NamedTemporaryFile +import pytest from openscad_runner import * -class TestBasePlateHoles(unittest.TestCase): +@pytest.fixture(scope="class") +def default_parameters(pytestconfig): + parameter_file_path = pytestconfig.rootpath.joinpath("tests/gridfinity-rebuilt-baseplate.json") + parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) + return parameter_file_data.parameterSets["Default"] + +@pytest.fixture +def openscad_runner(pytestconfig, default_parameters) -> OpenScadRunner: + scad_path = pytestconfig.rootpath.joinpath('gridfinity-rebuilt-baseplate.scad') + scad_runner = OpenScadRunner(scad_path) + scad_runner.image_folder_base = pytestconfig.rootpath.joinpath('images/baseplate/') + scad_runner.parameters = default_parameters.copy() + scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) + return scad_runner + +class TestBasePlateHoles: """ Test creating a single base in "gridfinity-spiral-vase.scad" Currently only makes sure code runs, and outputs pictures for manual verification. """ - @classmethod - def setUpClass(cls): - parameter_file_path = Path("gridfinity-rebuilt-baseplate.json") - parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) - cls.default_parameters = parameter_file_data.parameterSets["Default"] - - def setUp(self): - self.scad_runner = OpenScadRunner(Path('../gridfinity-rebuilt-baseplate.scad')) - self.scad_runner.image_folder_base = Path('../images/baseplate/') - self.scad_runner.parameters = self.default_parameters.copy() - self.scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) - - def test_no_holes(self): - vars = self.scad_runner.parameters + def test_no_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = False vars["style_hole"] = 0 - self.scad_runner.create_image([], Path('no_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('no_holes_top.png')) + openscad_runner.create_image([], Path('no_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('no_holes_top.png')) - def test_plain_magnet_holes(self): - vars = self.scad_runner.parameters + def test_plain_magnet_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["style_hole"] = 0 vars["chamfer_holes"] = False vars["crush_ribs"] = False - self.scad_runner.create_image([], Path('magnet_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('plain_magnet_holes_top.png')) + openscad_runner.create_image([], Path('magnet_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('plain_magnet_holes_top.png')) - def test_chamfered_magnet_holes(self): - vars = self.scad_runner.parameters + def test_chamfered_magnet_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["style_hole"] = 0 vars["chamfer_holes"] = True vars["crush_ribs"] = False - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('chamfered_magnet_holes.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('chamfered_magnet_holes.png')) - def test_ribbed_magnet_holes(self): - vars = self.scad_runner.parameters + def test_ribbed_magnet_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["style_hole"] = 0 vars["chamfer_holes"] = False vars["crush_ribs"] = True - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('ribbed_magnet_holes.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('ribbed_magnet_holes.png')) - def test_chamfered_and_ribbed_magnet_holes(self): - vars = self.scad_runner.parameters + def test_chamfered_and_ribbed_magnet_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["style_hole"] = 0 vars["chamfer_holes"] = True vars["crush_ribs"] = True - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('chamfered_and_ribbed_magnet_holes.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('chamfered_and_ribbed_magnet_holes.png')) - def test_only_countersunk_screw_holes(self): - vars = self.scad_runner.parameters + def test_only_countersunk_screw_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = False vars["style_hole"] = 1 - self.scad_runner.create_image([], Path('only_countersunk_screw_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('only_countersunk_screw_holes_top.png')) + openscad_runner.create_image([], Path('only_countersunk_screw_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('only_countersunk_screw_holes_top.png')) - def test_only_counterbored_screw_holes(self): - vars = self.scad_runner.parameters + def test_only_counterbored_screw_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = False vars["style_hole"] = 2 - self.scad_runner.create_image([], Path('only_counterbored_screw_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('only_counterbored_screw_holes_top.png')) + openscad_runner.create_image([], Path('only_counterbored_screw_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('only_counterbored_screw_holes_top.png')) - def test_magnet_and_countersunk_screw_holes(self): - vars = self.scad_runner.parameters + def test_magnet_and_countersunk_screw_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["chamfer_holes"] = False vars["crush_ribs"] = False vars["style_hole"] = 1 - self.scad_runner.create_image([], Path('magnet_and_countersunk_screw_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('magnet_and_countersunk_screw_holes_top.png')) + openscad_runner.create_image([], Path('magnet_and_countersunk_screw_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('magnet_and_countersunk_screw_holes_top.png')) - def test_magnet_and_counterbored_screw_holes(self): - vars = self.scad_runner.parameters + def test_magnet_and_counterbored_screw_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["enable_magnet"] = True vars["chamfer_holes"] = False vars["crush_ribs"] = False vars["style_hole"] = 2 - self.scad_runner.create_image([], Path('magnet_and_counterbored_screw_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) - self.scad_runner.create_image([], Path('magnet_and_counterbored_screw_holes_top.png')) - - -if __name__ == '__main__': - unittest.main() + openscad_runner.create_image([], Path('magnet_and_counterbored_screw_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledTop) + openscad_runner.create_image([], Path('magnet_and_counterbored_screw_holes_top.png')) diff --git a/tests/test_bins.py b/tests/test_bins.py index 8959eea..a293649 100644 --- a/tests/test_bins.py +++ b/tests/test_bins.py @@ -3,15 +3,27 @@ Tests for gridfinity-rebuilt-bins.scad @Copyright Arthur Moore 2024 MIT License """ -import dataclasses -import json -import unittest from pathlib import Path -from tempfile import NamedTemporaryFile +import pytest from openscad_runner import * -class TestBinHoles(unittest.TestCase): +@pytest.fixture(scope="class") +def default_parameters(pytestconfig): + parameter_file_path = pytestconfig.rootpath.joinpath("tests/gridfinity-rebuilt-bins.json") + parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) + return parameter_file_data.parameterSets["Default"] + +@pytest.fixture +def openscad_runner(pytestconfig, default_parameters) -> OpenScadRunner: + scad_path = pytestconfig.rootpath.joinpath('gridfinity-rebuilt-bins.scad') + scad_runner = OpenScadRunner(scad_path) + scad_runner.image_folder_base = pytestconfig.rootpath.joinpath('images/base_hole_options/') + scad_runner.parameters = default_parameters.copy() + scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) + return scad_runner + +class TestBinHoles: """ Test how a single base looks with holes cut out. @@ -24,127 +36,124 @@ class TestBinHoles(unittest.TestCase): parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) cls.default_parameters = parameter_file_data.parameterSets["Default"] - def setUp(self): - self.scad_runner = OpenScadRunner(Path('../gridfinity-rebuilt-bins.scad')) - self.scad_runner.image_folder_base = Path('../images/base_hole_options/') - self.scad_runner.parameters = self.default_parameters.copy() - self.scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) + def setUp(self, openscad_runner): + openscad_runner = OpenScadRunner(Path('../src/core/gridfinity-rebuilt-bins.scad')) + openscad_runner.image_folder_base = Path('../images/base_hole_options/') + openscad_runner.parameters = self.default_parameters.copy() + openscad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) - def test_no_holes(self): - vars = self.scad_runner.parameters + def test_no_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = False vars["screw_holes"] = False - self.scad_runner.create_image([], Path('no_holes.png')) + openscad_runner.create_image([], Path('no_holes.png')) - def test_only_corner_holes(self): - vars = self.scad_runner.parameters + def test_only_corner_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = True vars["magnet_holes"] = False vars["screw_holes"] = False vars["only_corners"] = True - self.scad_runner.create_image([], Path('only_corner_holes.png')) + openscad_runner.create_image([], Path('only_corner_holes.png')) - def test_refined_holes(self): - vars = self.scad_runner.parameters + def test_refined_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = True vars["magnet_holes"] = False vars["screw_holes"] = False - self.scad_runner.create_image([], Path('refined_holes.png')) + openscad_runner.create_image([], Path('refined_holes.png')) - def test_refined_and_screw_holes(self): - vars = self.scad_runner.parameters + def test_refined_and_screw_holes(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = True vars["magnet_holes"] = False vars["screw_holes"] = True vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('refined_and_screw_holes.png')) + openscad_runner.create_image([], Path('refined_and_screw_holes.png')) - def test_screw_holes_plain(self): - vars = self.scad_runner.parameters + def test_screw_holes_plain(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = False vars["screw_holes"] = True vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('screw_holes_plain.png')) + openscad_runner.create_image([], Path('screw_holes_plain.png')) - def test_screw_holes_printable(self): - vars = self.scad_runner.parameters + def test_screw_holes_printable(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = False vars["screw_holes"] = True vars["printable_hole_top"] = True - self.scad_runner.create_image([], Path('screw_holes_printable.png')) + openscad_runner.create_image([], Path('screw_holes_printable.png')) - def test_magnet_holes_plain(self): - vars = self.scad_runner.parameters + def test_magnet_holes_plain(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = False vars["crush_ribs"] = False vars["chamfer_holes"] = False vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('magnet_holes_plain.png')) + openscad_runner.create_image([], Path('magnet_holes_plain.png')) - def test_magnet_holes_chamfered(self): - vars = self.scad_runner.parameters + def test_magnet_holes_chamfered(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = False vars["crush_ribs"] = False vars["chamfer_holes"] = True vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('magnet_holes_chamfered.png')) + openscad_runner.create_image([], Path('magnet_holes_chamfered.png')) - def test_magnet_holes_printable(self): - vars = self.scad_runner.parameters + def test_magnet_holes_printable(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = False vars["crush_ribs"] = False vars["chamfer_holes"] = False vars["printable_hole_top"] = True - self.scad_runner.create_image([], Path('magnet_holes_printable.png')) + openscad_runner.create_image([], Path('magnet_holes_printable.png')) - def test_magnet_holes_with_crush_ribs(self): - vars = self.scad_runner.parameters + def test_magnet_holes_with_crush_ribs(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = False vars["crush_ribs"] = True vars["chamfer_holes"] = False vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('magnet_holes_with_crush_ribs.png')) + openscad_runner.create_image([], Path('magnet_holes_with_crush_ribs.png')) - def test_magnet_and_screw_holes_plain(self): - vars = self.scad_runner.parameters + def test_magnet_and_screw_holes_plain(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = True vars["crush_ribs"] = False vars["chamfer_holes"] = False vars["printable_hole_top"] = False - self.scad_runner.create_image([], Path('magnet_and_screw_holes_plain.png')) + openscad_runner.create_image([], Path('magnet_and_screw_holes_plain.png')) - def test_magnet_and_screw_holes_printable(self): - vars = self.scad_runner.parameters + def test_magnet_and_screw_holes_printable(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = True vars["crush_ribs"] = False vars["chamfer_holes"] = False vars["printable_hole_top"] = True - self.scad_runner.create_image([], Path('magnet_and_screw_holes_printable.png')) + openscad_runner.create_image([], Path('magnet_and_screw_holes_printable.png')) - def test_magnet_and_screw_holes_all(self): - vars = self.scad_runner.parameters + def test_magnet_and_screw_holes_all(self, openscad_runner): + vars = openscad_runner.parameters vars["refined_holes"] = False vars["magnet_holes"] = True vars["screw_holes"] = True vars["crush_ribs"] = True vars["chamfer_holes"] = True vars["printable_hole_top"] = True - self.scad_runner.create_image([], Path('magnet_and_screw_holes_all.png')) - -if __name__ == '__main__': - unittest.main() + openscad_runner.create_image([], Path('magnet_and_screw_holes_all.png')) diff --git a/tests/test_holes.py b/tests/test_holes.py index 70e9bbf..ad55356 100644 --- a/tests/test_holes.py +++ b/tests/test_holes.py @@ -4,75 +4,75 @@ Tests for gridfinity-rebuilt-holes.scad """ from pathlib import Path +import pytest + from openscad_runner import * -import unittest +@pytest.fixture +def openscad_runner(pytestconfig) -> OpenScadRunner: + scad_path = pytestconfig.rootpath.joinpath('gridfinity-rebuilt-holes.scad') + scad_runner = OpenScadRunner(scad_path) + scad_runner.image_folder_base = pytestconfig.rootpath.joinpath('images/hole_cutouts/') + scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledTop, 50) + return scad_runner -class TestHoleCutouts(unittest.TestCase): +class TestHoleCutouts: """ Test Hole Cutouts. The negatives used with `difference()` to create a hole. Currently only makes sure code runs, and outputs pictures for manual verification. """ - def setUp(self): - self.scad_runner = OpenScadRunner(Path('../gridfinity-rebuilt-holes.scad')) - self.scad_runner.image_folder_base = Path('../images/hole_cutouts/') - self.scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledTop, 50) - - def test_refined_hole(self): + def test_refined_hole(self, openscad_runner): """ refined_hole() is special, since top_angle_camera is not appropriate for it. """ - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.AngledBottom) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.AngledBottom) test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=true, magnet_hole=false, screw_hole=false, crush_ribs=false, chamfer=false, supportless=false)') - self.scad_runner.create_image(test_args, Path('refined_hole.png')) + openscad_runner.create_image(test_args, Path('refined_hole.png')) - def test_plain_magnet_hole(self): + def test_plain_magnet_hole(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=false, crush_ribs=false, chamfer=false, supportless=false)') - self.scad_runner.create_image(test_args, Path('magnet_hole.png')) + openscad_runner.create_image(test_args, Path('magnet_hole.png')) - def test_plain_screw_hole(self): + def test_plain_screw_hole(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=false, screw_hole=true, crush_ribs=false, chamfer=false, supportless=false)') - self.scad_runner.create_image(test_args, Path('screw_hole.png')) + openscad_runner.create_image(test_args, Path('screw_hole.png')) - def test_magnet_and_screw_hole(self): + def test_magnet_and_screw_hole(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=true, crush_ribs=false, chamfer=false, supportless=false)') - self.scad_runner.create_image(test_args, Path('magnet_and_screw_hole.png')) + openscad_runner.create_image(test_args, Path('magnet_and_screw_hole.png')) - def test_chamfered_magnet_hole(self): + def test_chamfered_magnet_hole(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=false, crush_ribs=false, chamfer=true, supportless=false)') - self.scad_runner.create_image(test_args, Path('chamfered_magnet_hole.png')) + openscad_runner.create_image(test_args, Path('chamfered_magnet_hole.png')) - def test_magnet_hole_crush_ribs(self): + def test_magnet_hole_crush_ribs(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=false, crush_ribs=true, chamfer=false, supportless=false)') - self.scad_runner.create_image(test_args, Path('magnet_hole_crush_ribs.png')) + openscad_runner.create_image(test_args, Path('magnet_hole_crush_ribs.png')) - def test_magnet_hole_supportless(self): + def test_magnet_hole_supportless(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=false, crush_ribs=false, chamfer=false, supportless=true)') - self.scad_runner.create_image(test_args, Path('magnet_hole_supportless.png')) + openscad_runner.create_image(test_args, Path('magnet_hole_supportless.png')) - def test_magnet_and_screw_hole_supportless(self): + def test_magnet_and_screw_hole_supportless(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=true, crush_ribs=false, chamfer=false, supportless=true)') - self.scad_runner.create_image(test_args, Path('magnet_and_screw_hole_supportless.png')) + openscad_runner.create_image(test_args, Path('magnet_and_screw_hole_supportless.png')) - def test_all_hole_options(self): + def test_all_hole_options(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=true, screw_hole=true, crush_ribs=true, chamfer=true, supportless=true)') - self.scad_runner.create_image(test_args, Path('all_hole_options.png')) + openscad_runner.create_image(test_args, Path('all_hole_options.png')) - def test_no_hole(self): + def test_no_hole(self, openscad_runner): test_args = set_variable_argument('test_options', 'bundle_hole_options(refined_hole=false, magnet_hole=false, screw_hole=false, crush_ribs=true, chamfer=true, supportless=true)') - self.scad_runner.create_image(test_args, Path('no_hole.png')) - -if __name__ == '__main__': - unittest.main() + openscad_runner.create_image(test_args, Path('no_hole.png')) diff --git a/tests/test_spiral_vase.py b/tests/test_spiral_vase.py index 8c7d84a..a65b1e2 100644 --- a/tests/test_spiral_vase.py +++ b/tests/test_spiral_vase.py @@ -3,48 +3,45 @@ Tests for gridfinity-spiral-vase.scad @Copyright Arthur Moore 2024 MIT License """ -import dataclasses -import json -import unittest from pathlib import Path -from tempfile import NamedTemporaryFile +import pytest from openscad_runner import * -class TestSpiralVaseBase(unittest.TestCase): +@pytest.fixture(scope="class") +def default_parameters(pytestconfig): + parameter_file_path = pytestconfig.rootpath.joinpath("tests/gridfinity-spiral-vase.json") + parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) + return parameter_file_data.parameterSets["Default"] + +@pytest.fixture +def openscad_runner(pytestconfig, default_parameters) -> OpenScadRunner: + scad_path = pytestconfig.rootpath.joinpath('gridfinity-spiral-vase.scad') + scad_runner = OpenScadRunner(scad_path) + scad_runner.image_folder_base = pytestconfig.rootpath.joinpath('images/spiral_vase_base/') + scad_runner.parameters = default_parameters.copy() + scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) + return scad_runner + +class TestSpiralVaseBase: """ Test creating a single base in "gridfinity-spiral-vase.scad" Currently only makes sure code runs, and outputs pictures for manual verification. """ - @classmethod - def setUpClass(cls): - parameter_file_path = Path("gridfinity-spiral-vase.json") - parameter_file_data = ParameterFile.from_json(parameter_file_path.read_text()) - cls.default_parameters = parameter_file_data.parameterSets["Default"] - - def setUp(self): - self.scad_runner = OpenScadRunner(Path('../gridfinity-spiral-vase.scad')) - self.scad_runner.image_folder_base = Path('../images/spiral_vase_base/') - self.scad_runner.parameters = self.default_parameters.copy() - self.scad_runner.parameters["type"] = 1 # Create a Base - self.scad_runner.camera_arguments = CameraArguments(Vec3(0,0,0), CameraRotations.AngledBottom, 150) - - def test_no_holes(self): - vars = self.scad_runner.parameters + def test_no_holes(self, openscad_runner): + vars = openscad_runner.parameters + vars["type"] = 1 # Create a Base vars["enable_holes"] = False - self.scad_runner.create_image([], Path('no_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.Top) - self.scad_runner.create_image([], Path('no_holes_top.png')) + openscad_runner.create_image([], Path('no_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.Top) + openscad_runner.create_image([], Path('no_holes_top.png')) - def test_refined_holes(self): - vars = self.scad_runner.parameters + def test_holes(self, openscad_runner): + vars = openscad_runner.parameters + vars["type"] = 1 # Create a Base vars["enable_holes"] = True - self.scad_runner.create_image([], Path('with_holes_bottom.png')) - self.scad_runner.camera_arguments = self.scad_runner.camera_arguments.with_rotation(CameraRotations.Top) - self.scad_runner.create_image([], Path('with_holes_top.png')) - - -if __name__ == '__main__': - unittest.main() + openscad_runner.create_image([], Path('with_holes_bottom.png')) + openscad_runner.camera_arguments = openscad_runner.camera_arguments.with_rotation(CameraRotations.Top) + openscad_runner.create_image([], Path('with_holes_top.png'))