From cf377bdd4882f10272f627840fb5a270f6f6e097 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Thu, 17 Oct 2024 02:57:57 -0400 Subject: [PATCH 1/2] Switch test framework from unittest to pytest Allows running tests from both root director and the tests directory. --- pyproject.toml | 2 + tests/test_baseplate.py | 122 ++++++++++++++++++-------------------- tests/test_bins.py | 113 +++++++++++++++++++---------------- tests/test_holes.py | 62 +++++++++---------- tests/test_spiral_vase.py | 61 +++++++++---------- 5 files changed, 182 insertions(+), 178 deletions(-) create mode 100644 pyproject.toml 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')) From 2216f766e5a78532500b87f1bbce512829e97a9c Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Thu, 17 Oct 2024 03:01:38 -0400 Subject: [PATCH 2/2] Move scad files not meant for end users to "src" directory --- gridfinity-rebuilt-baseplate.scad | 9 +++++---- gridfinity-rebuilt-bins.scad | 5 +++-- gridfinity-rebuilt-lite.scad | 7 +++++-- gridfinity-spiral-vase.scad | 6 ++++-- .../core/gridfinity-rebuilt-holes.scad | 2 +- .../core/gridfinity-rebuilt-utility.scad | 4 ++-- standard.scad => src/core/standard.scad | 0 {external => src/external}/threads-scad/threads.scad | 0 generic-helpers.scad => src/helpers/generic-helpers.scad | 0 tests/test_holes.py | 2 +- 10 files changed, 21 insertions(+), 14 deletions(-) rename gridfinity-rebuilt-holes.scad => src/core/gridfinity-rebuilt-holes.scad (99%) rename gridfinity-rebuilt-utility.scad => src/core/gridfinity-rebuilt-utility.scad (99%) rename standard.scad => src/core/standard.scad (100%) rename {external => src/external}/threads-scad/threads.scad (100%) rename generic-helpers.scad => src/helpers/generic-helpers.scad (100%) diff --git a/gridfinity-rebuilt-baseplate.scad b/gridfinity-rebuilt-baseplate.scad index d850272..05d82e2 100644 --- a/gridfinity-rebuilt-baseplate.scad +++ b/gridfinity-rebuilt-baseplate.scad @@ -1,7 +1,3 @@ -include -include -use - // ===== INFORMATION ===== // /* IMPORTANT: rendering will be better for analyzing the model if fast-csg is enabled. As of writing, this feature is only available in the development builds and not the official release of OpenSCAD, but it makes rendering only take a couple seconds, even for comically large bins. Enable it in Edit > Preferences > Features > fast-csg @@ -10,6 +6,11 @@ https://github.com/kennetek/gridfinity-rebuilt-openscad */ +include +use +use +use + // ===== PARAMETERS ===== // /* [Setup Parameters] */ diff --git a/gridfinity-rebuilt-bins.scad b/gridfinity-rebuilt-bins.scad index c1dc147..9ff0de0 100644 --- a/gridfinity-rebuilt-bins.scad +++ b/gridfinity-rebuilt-bins.scad @@ -1,5 +1,3 @@ -include - // ===== INFORMATION ===== // /* IMPORTANT: rendering will be better for analyzing the model if fast-csg is enabled. As of writing, this feature is only available in the development builds and not the official release of OpenSCAD, but it makes rendering only take a couple seconds, even for comically large bins. Enable it in Edit > Preferences > Features > fast-csg @@ -26,6 +24,9 @@ https://github.com/kennetek/gridfinity-rebuilt-openscad */ +use +use + // ===== PARAMETERS ===== // /* [Setup Parameters] */ diff --git a/gridfinity-rebuilt-lite.scad b/gridfinity-rebuilt-lite.scad index 43194af..543f471 100644 --- a/gridfinity-rebuilt-lite.scad +++ b/gridfinity-rebuilt-lite.scad @@ -1,5 +1,3 @@ -include - // ===== INFORMATION ===== // /* IMPORTANT: rendering will be better for analyzing the model if fast-csg is enabled. As of writing, this feature is only available in the development builds and not the official release of OpenSCAD, but it makes rendering only take a couple seconds, even for comically large bins. Enable it in Edit > Preferences > Features > fast-csg @@ -8,6 +6,11 @@ https://github.com/kennetek/gridfinity-rebuilt-openscad */ +include +use +use +use + // ===== PARAMETERS ===== // /* [Setup Parameters] */ diff --git a/gridfinity-spiral-vase.scad b/gridfinity-spiral-vase.scad index 93ac20c..b5fdd9c 100644 --- a/gridfinity-spiral-vase.scad +++ b/gridfinity-spiral-vase.scad @@ -1,5 +1,3 @@ -include - // ===== INFORMATION ===== // /* IMPORTANT: rendering will be better for analyzing the model if fast-csg is enabled. As of writing, this feature is only available in the development builds and not the official release of OpenSCAD, but it makes rendering only take a couple seconds, even for comically large bins. Enable it in Edit > Preferences > Features > fast-csg @@ -8,6 +6,10 @@ https://github.com/kennetek/gridfinity-rebuilt-openscad */ +include +use +use + // ===== PARAMETERS ===== // /* [Special Variables] */ diff --git a/gridfinity-rebuilt-holes.scad b/src/core/gridfinity-rebuilt-holes.scad similarity index 99% rename from gridfinity-rebuilt-holes.scad rename to src/core/gridfinity-rebuilt-holes.scad index 5aa3efd..7e40729 100644 --- a/gridfinity-rebuilt-holes.scad +++ b/src/core/gridfinity-rebuilt-holes.scad @@ -4,7 +4,7 @@ */ include -use +use <../helpers/generic-helpers.scad> /** * @brief Determines the number of fragments in a circle. Aka, Circle resolution. diff --git a/gridfinity-rebuilt-utility.scad b/src/core/gridfinity-rebuilt-utility.scad similarity index 99% rename from gridfinity-rebuilt-utility.scad rename to src/core/gridfinity-rebuilt-utility.scad index c87e486..9084fb3 100644 --- a/gridfinity-rebuilt-utility.scad +++ b/src/core/gridfinity-rebuilt-utility.scad @@ -5,9 +5,9 @@ */ include -use use -use +use <../helpers/generic-helpers.scad> +use <../external/threads-scad/threads.scad> // ===== User Modules ===== // diff --git a/standard.scad b/src/core/standard.scad similarity index 100% rename from standard.scad rename to src/core/standard.scad diff --git a/external/threads-scad/threads.scad b/src/external/threads-scad/threads.scad similarity index 100% rename from external/threads-scad/threads.scad rename to src/external/threads-scad/threads.scad diff --git a/generic-helpers.scad b/src/helpers/generic-helpers.scad similarity index 100% rename from generic-helpers.scad rename to src/helpers/generic-helpers.scad diff --git a/tests/test_holes.py b/tests/test_holes.py index ad55356..e153318 100644 --- a/tests/test_holes.py +++ b/tests/test_holes.py @@ -10,7 +10,7 @@ from openscad_runner import * @pytest.fixture def openscad_runner(pytestconfig) -> OpenScadRunner: - scad_path = pytestconfig.rootpath.joinpath('gridfinity-rebuilt-holes.scad') + scad_path = pytestconfig.rootpath.joinpath('src/core/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)