From e9bfdee8a130f77d4b98676bcbf5595d480f3e94 Mon Sep 17 00:00:00 2001 From: billingsley-john Date: Fri, 15 Jan 2021 11:33:46 +0000 Subject: [PATCH 1/3] added new test --- tests/test_parametric_components/test_Plasma.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_parametric_components/test_Plasma.py b/tests/test_parametric_components/test_Plasma.py index 9771be5e8..b8bd3dd21 100644 --- a/tests/test_parametric_components/test_Plasma.py +++ b/tests/test_parametric_components/test_Plasma.py @@ -1,6 +1,7 @@ import os import unittest +import pytest from pathlib import Path import paramak @@ -223,12 +224,11 @@ def test_export_plasma_from_points_export(self): assert Path("plasma.stp").exists() os.system("rm plasma.stp") - # TODO: fix issue #435 - # def test_plasma_relative_volume(self): - # """Creates plasmas using the Plasma parametric component and checks that - # the relative volumes of the solids created are correct""" + def test_plasma_relative_volume(self): + """Creates plasmas using the Plasma parametric component and checks that + the relative volumes of the solids created are correct""" - # test_plasma = paramak.Plasma() - # test_plasma_volume = test_plasma.volume - # test_plasma.rotation_angle = 180 - # assert test_plasma.volume == pytest.approx(test_plasma_volume * 0.5) + test_plasma = paramak.Plasma() + test_plasma_volume = test_plasma.volume + test_plasma.rotation_angle = 180 + assert test_plasma.volume == pytest.approx(test_plasma_volume * 0.5) From c45ce20ee5bda7a61a1f5de95cc72949cf451596 Mon Sep 17 00:00:00 2001 From: billingsley-john Date: Fri, 15 Jan 2021 16:06:23 +0000 Subject: [PATCH 2/3] updated tests to ensure assertions are tested correctly --- .../test_CenterColumnShieldCylinder.py | 10 ++--- ...test_CenterColumnShieldFlatTopHyperbola.py | 8 ++-- .../test_CenterColumnShieldHyperbola.py | 2 + .../test_CenterColumnShieldPlasmaHyperbola.py | 3 +- .../test_CuttingWedgeFS.py | 13 +++--- .../test_PoloidalFieldCoilCaseSet.py | 37 ++++++++++++---- .../test_PoloidalFieldCoilCaseSetFC.py | 38 ++++++++-------- .../test_PoloidalFieldCoilSet.py | 44 +++++++++++-------- .../test_ToroidalFieldCoilRectangle.py | 23 +++++++--- 9 files changed, 111 insertions(+), 67 deletions(-) diff --git a/tests/test_parametric_components/test_CenterColumnShieldCylinder.py b/tests/test_parametric_components/test_CenterColumnShieldCylinder.py index 51d323dd4..ea33f9482 100644 --- a/tests/test_parametric_components/test_CenterColumnShieldCylinder.py +++ b/tests/test_parametric_components/test_CenterColumnShieldCylinder.py @@ -106,16 +106,14 @@ def test_center_column_shield_cylinder_invalid_parameters_errors(self): as shape parameters.""" def incorrect_inner_radius(): - self.test_shape.inner_radius = self.test_shape.outer_radius + 1 - self.test_shape.outer_radius = 20 - self.test_shape.inner_radius = 40 + self.test_shape.inner_radius = 250 def incorrect_outer_radius(): - self.test_shape.outer_radius = self.test_shape.inner_radius + 1 - self.test_shape.inner_radius = 40 - self.test_shape.outer_radius = 20 + self.test_shape.inner_radius = 100 + self.test_shape.outer_radius = 50 def incorrect_height(): + self.test_shape.outer_radius = 200 self.test_shape.height = None self.assertRaises(ValueError, incorrect_inner_radius) diff --git a/tests/test_parametric_components/test_CenterColumnShieldFlatTopHyperbola.py b/tests/test_parametric_components/test_CenterColumnShieldFlatTopHyperbola.py index b6ba864ee..3dc8180fd 100644 --- a/tests/test_parametric_components/test_CenterColumnShieldFlatTopHyperbola.py +++ b/tests/test_parametric_components/test_CenterColumnShieldFlatTopHyperbola.py @@ -38,8 +38,7 @@ def test_creation(self): assert self.test_shape.solid is not None assert self.test_shape.volume > 1000 - def test_invalid_parameters_errors( - self): + def test_invalid_parameters_errors(self): """Checks that the correct errors are raised when invalid arguments are input as shape parameters.""" @@ -48,14 +47,17 @@ def incorrect_inner_radius(): self.test_shape.solid def incorrect_mid_radius(): - self.test_shape.mid_radius = 220 + self.test_shape.inner_radius = 100 + self.test_shape.mid_radius = 250 self.test_shape.solid def incorrect_outer_radius(): + self.test_shape.mid_radius = 150 self.test_shape.outer_radius = 130 self.test_shape.solid def incorrect_arc_height(): + self.test_shape.outer_radius = 200 self.test_shape.arc_height = 700 self.test_shape.solid diff --git a/tests/test_parametric_components/test_CenterColumnShieldHyperbola.py b/tests/test_parametric_components/test_CenterColumnShieldHyperbola.py index b9fe61704..907765702 100644 --- a/tests/test_parametric_components/test_CenterColumnShieldHyperbola.py +++ b/tests/test_parametric_components/test_CenterColumnShieldHyperbola.py @@ -48,10 +48,12 @@ def incorrect_inner_radius(): self.test_shape.solid def incorrect_mid_radius(): + self.test_shape.inner_radius = 100 self.test_shape.mid_radius = 80 self.test_shape.solid def incorrect_outer_radius(): + self.test_shape.mid_radius = 150 self.test_shape.outer_radius = 130 self.test_shape.solid diff --git a/tests/test_parametric_components/test_CenterColumnShieldPlasmaHyperbola.py b/tests/test_parametric_components/test_CenterColumnShieldPlasmaHyperbola.py index 480688183..c376b5b8b 100644 --- a/tests/test_parametric_components/test_CenterColumnShieldPlasmaHyperbola.py +++ b/tests/test_parametric_components/test_CenterColumnShieldPlasmaHyperbola.py @@ -52,7 +52,8 @@ def incorrect_inner_radius(): self.test_shape.solid def incorrect_height(): - self.test_shape.height = 301 + self.test_shape.inner_radius = 100 + self.test_shape.height = 300 self.test_shape.solid self.assertRaises(ValueError, incorrect_inner_radius) diff --git a/tests/test_parametric_components/test_CuttingWedgeFS.py b/tests/test_parametric_components/test_CuttingWedgeFS.py index b199cb04c..126a4cd76 100644 --- a/tests/test_parametric_components/test_CuttingWedgeFS.py +++ b/tests/test_parametric_components/test_CuttingWedgeFS.py @@ -24,14 +24,16 @@ def test_shape_construction_and_volume(self): assert cutter.volume > hoop_shape.volume - def test_error(self): - """Checks that errors are raised when invalid arguments are set - """ + def test_invalid_parameters_errors(self): + """Checks that the correct errors are raised when invalid arguments are input as + shape parameters.""" + shape = paramak.ExtrudeStraightShape( - 1, + distance=1, points=[(0, 0), (0, 1), (1, 1)], rotation_angle=180 ) + cutter = paramak.CuttingWedgeFS( shape=shape, azimuth_placement_angle=0, @@ -39,16 +41,15 @@ def test_error(self): def incorrect_rotation_angle(): shape.rotation_angle = 360 - print(cutter.shape.rotation_angle) cutter.solid def incorrect_shape_points(): shape.rotation_angle = 180 cutter.shape.points = [(0, 0, 'straight')] - print(shape.points) cutter.solid def incorrect_shape_rotation_angle(): + cutter.shape.points = [(0, 0), (0, 1), (1, 1)] shape.rotation_angle = 360 cutter.shape = shape diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py index 7a2b1d638..0fe41042e 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py @@ -114,20 +114,39 @@ def test_absolute_areas(self): assert self.test_shape.areas.count( pytest.approx(40 * math.pi * 2 * 80)) == 1 - def test_invalid_args(self): - """Creates PoloidalFieldCoilCaseSets with invalid arguments and checks - that the correct errors are raised.""" + def test_PoloidalFieldCoilCaseSet_incorrect_thicknesses_1(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSet is made + with the wrong number of casing thicknesses.""" - def test_invalid_casing_thicknesses_1(): + def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_1(): self.test_shape.casing_thicknesses = [5, 5, 10] self.test_shape.solid - def test_invalid_casing_thicknesses_2(): + self.assertRaises( + ValueError, + make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_1 + ) + + def test_PoloidalFieldCoil_incorrect_thicknesses_2(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSet is made + with invalid casing thicknesses.""" + + def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_2(): self.test_shape.casing_thicknesses = [5, 5, 5, 'ten'] - def test_invalid_casing_thicknesses_3(): + self.assertRaises( + ValueError, + make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_2 + ) + + def test_PoloidalFieldCoil_incorrect_thicknesses_3(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSet is made + with invalid casing thicknesses.""" + + def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_3(): self.test_shape.casing_thicknesses = "ten" - self.assertRaises(ValueError, test_invalid_casing_thicknesses_1) - self.assertRaises(ValueError, test_invalid_casing_thicknesses_2) - self.assertRaises(ValueError, test_invalid_casing_thicknesses_3) + self.assertRaises( + ValueError, + make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_3 + ) diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py index a5f9d4a51..fa81d6c97 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py @@ -114,25 +114,24 @@ def test_from_pf_coil_set_absolute_areas(self): assert self.test_shape.areas.count( pytest.approx(40 * math.pi * 2 * 80)) == 1 - def test_incorrect_args(self): - """Creates a solid using the PoloidalFieldCoilCaseSet with incorrect - args""" - - def test_PoloidalFieldCoilSet_incorrect_lengths_FC(): - """Checks PoloidalFieldCoilSet with the wrong number of casing - thicknesses (3) using a coil set object with 4 pf_coils.""" + def test_PoloidalFieldCoilCaseSetFC_incorrect_lengths_FC(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSetFC is made + with the wrong number of casing thicknesses using a coil set object.""" + def make_PoloidalFieldCoilCaseSetFC_incorrect_lengths_FC(): self.test_shape.casing_thicknesses = [5, 5, 10] self.test_shape.solid self.assertRaises( ValueError, - test_PoloidalFieldCoilSet_incorrect_lengths_FC) + make_PoloidalFieldCoilCaseSetFC_incorrect_lengths_FC + ) - def test_PoloidalFieldCoilSet_incorrect_lengths(): - """Checks PoloidalFieldCoilSet with the wrong number of casing - thicknesses using a list.""" + def test_PoloidalFieldCoilCaseSetFC_incorrect_lengths(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSetFC is made + with the wrong number of casing thicknesses using a list.""" + def make_PoloidalFieldCoilCaseSetFC_incorrect_lengths(): self.pf_coils_set.height = 10 self.pf_coils_set.width = 10 self.pf_coils_set.center_point = (100, 100) @@ -142,18 +141,21 @@ def test_PoloidalFieldCoilSet_incorrect_lengths(): self.assertRaises( ValueError, - test_PoloidalFieldCoilSet_incorrect_lengths) + make_PoloidalFieldCoilCaseSetFC_incorrect_lengths + ) - def test_PoloidalFieldCoilSet_incorrect_pf_coil(): - """Checks PoloidalFieldCoilSet with the pf_coils as an incorrect - entry.""" + def test_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil(self): + """Checks that an error is raised when a PoloidalFieldCoilCaseSetFC is made + with the pf_coils as an incorrect entry.""" + def make_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil(): self.test_shape.pf_coils = 20 self.test_shape.solid - + self.assertRaises( ValueError, - test_PoloidalFieldCoilSet_incorrect_pf_coil) + make_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil + ) def test_from_list(self): """Creates a set of PF coil cases from a list of PF coils with a list @@ -183,7 +185,7 @@ def test_from_list(self): assert test_shape.solid is not None assert len(test_shape.solid.Solids()) == 4 - def test_PoloidalFieldCoilCaseFC_with_number_thickness(self): + def test_PoloidalFieldCoilCaseSetFC_with_number_thickness(self): """Creates a set of PF coil cases from a list of PF coils with a single numerical thicknesses.""" diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilSet.py b/tests/test_parametric_components/test_PoloidalFieldCoilSet.py index 1e03f0486..c77729436 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilSet.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilSet.py @@ -75,13 +75,11 @@ def test_absolute_areas(self): assert self.test_shape.areas.count( pytest.approx(5 * math.pi * (2 * 315))) == 1 - def test_incorrect_args(self): - """Creates a solid using the PoloidalFieldCoilSet parametric component - and checks that a cadquery solid is created.""" - - def test_incorrect_height(): - """Checks PoloidalFieldCoilSet with height as the wrong type.""" + def test_PoloidalFieldCoilSet_incorrect_height(self): + """Checks that an error is raised when a PoloidalFieldCoilSet is made + with height passed as the wrong type.""" + def make_PoloidalFieldCoilSet_incorrect_height(): paramak.PoloidalFieldCoilSet( heights=10, widths=[20, 20, 20], @@ -89,11 +87,14 @@ def test_incorrect_height(): self.assertRaises( ValueError, - test_incorrect_height) - - def test_incorrect_width(): - """Checks PoloidalFieldCoilSet with width as the wrong type.""" + make_PoloidalFieldCoilSet_incorrect_height + ) + + def test_PoloidalFieldCoilSet_incorrect_width(self): + """Checks that an error is raised when a PoloidalFieldCoilSet is made + with width passed as the wrong type.""" + def make_PoloidalFieldCoilSet_incorrect_width(): paramak.PoloidalFieldCoilSet( heights=[10, 10, 10], widths=20, @@ -101,12 +102,14 @@ def test_incorrect_width(): self.assertRaises( ValueError, - test_incorrect_width) + make_PoloidalFieldCoilSet_incorrect_width + ) - def test_incorrect_center_points(): - """Checks PoloidalFieldCoilSet with center_points as the wrong - type.""" + def test_PoloidalFieldCoilSet_incorrect_center_points(self): + """Checks that an error is raised when a PoloidalFieldCoilSet is made + with center_points passed as the wrong type.""" + def make_PoloidalFieldCoilSet_incorrect_center_points(): paramak.PoloidalFieldCoilSet( heights=[10, 10, 10], widths=[20, 20, 20], @@ -114,10 +117,14 @@ def test_incorrect_center_points(): self.assertRaises( ValueError, - test_incorrect_center_points) + make_PoloidalFieldCoilSet_incorrect_center_points + ) - def test_incorrect_width_length(): - """Checks PoloidalFieldCoilSet with not enough entries in width.""" + def test_PoloidalFieldCoilSet_incorrect_width_length(self): + """Checks that an error is raised when a PoloidalFieldCoilSet is made + with the incorrect number of widths.""" + + def make_PoloidalFieldCoilSet_incorrect_width_length(): paramak.PoloidalFieldCoilSet( heights=[10, 10, 10], widths=[20, 20], @@ -125,4 +132,5 @@ def test_incorrect_width_length(): self.assertRaises( ValueError, - test_incorrect_width_length) + make_PoloidalFieldCoilSet_incorrect_width_length + ) diff --git a/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py b/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py index 14c3ff4e7..9d6a306a2 100644 --- a/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py +++ b/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py @@ -140,19 +140,30 @@ def test_rotation_angle(self): self.test_shape.rotation_angle = 180 assert self.test_shape.volume == pytest.approx(test_volume * 0.5) - def test_error(self): - """Checks errors are raised with invalid arguments.""" + def test_ToroidalFieldCoilRectangle_incorrect_horizonal_start_point(self): + """Checks that an error is raised when a ToroidalFieldCoilRectangle is made + with an incorrect horizontal_start_point.""" - def incorrect_horizontal_start_point(): + def make_ToroidalFieldCoilRectangle_incorrect_horizontal_start_point(): self.test_shape.vertical_mid_point = (800, 0) self.test_shape.horizontal_start_point = (801, 700) self.test_shape.solid - self.assertRaises(ValueError, incorrect_horizontal_start_point) + self.assertRaises( + ValueError, + make_ToroidalFieldCoilRectangle_incorrect_horizontal_start_point + ) + + def test_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point(self): + """Checks that an error is raised when a ToroidalFieldCoilRectangle is made + with an incorrect vertical_mid_point.""" - def incorrect_vertical_mid_point(): + def make_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point(): self.test_shape.horizontal_start_point = (100, 700) self.test_shape.vertical_mid_point = (800, 701) self.test_shape.solid - self.assertRaises(ValueError, incorrect_vertical_mid_point) + self.assertRaises( + ValueError, + make_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point + ) From 9299e0131cb6a95cebd5007a10b2245cf72a12b7 Mon Sep 17 00:00:00 2001 From: autopep8 Date: Fri, 15 Jan 2021 16:10:00 +0000 Subject: [PATCH 3/3] Automated autopep8 fixes --- tests/test_parametric_components/test_CuttingWedgeFS.py | 2 +- .../test_PoloidalFieldCoilCaseSet.py | 6 +++--- .../test_PoloidalFieldCoilCaseSetFC.py | 4 ++-- .../test_parametric_components/test_PoloidalFieldCoilSet.py | 2 +- .../test_ToroidalFieldCoilRectangle.py | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_parametric_components/test_CuttingWedgeFS.py b/tests/test_parametric_components/test_CuttingWedgeFS.py index 126a4cd76..3d3a793fd 100644 --- a/tests/test_parametric_components/test_CuttingWedgeFS.py +++ b/tests/test_parametric_components/test_CuttingWedgeFS.py @@ -27,7 +27,7 @@ def test_shape_construction_and_volume(self): def test_invalid_parameters_errors(self): """Checks that the correct errors are raised when invalid arguments are input as shape parameters.""" - + shape = paramak.ExtrudeStraightShape( distance=1, points=[(0, 0), (0, 1), (1, 1)], diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py index 0fe41042e..5061740c9 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py @@ -123,7 +123,7 @@ def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_1(): self.test_shape.solid self.assertRaises( - ValueError, + ValueError, make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_1 ) @@ -138,11 +138,11 @@ def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_2(): ValueError, make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_2 ) - + def test_PoloidalFieldCoil_incorrect_thicknesses_3(self): """Checks that an error is raised when a PoloidalFieldCoilCaseSet is made with invalid casing thicknesses.""" - + def make_PoloidalFieldCoilCaseSet_incorrect_thicknesses_3(): self.test_shape.casing_thicknesses = "ten" diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py index fa81d6c97..de20e5924 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py @@ -128,7 +128,7 @@ def make_PoloidalFieldCoilCaseSetFC_incorrect_lengths_FC(): ) def test_PoloidalFieldCoilCaseSetFC_incorrect_lengths(self): - """Checks that an error is raised when a PoloidalFieldCoilCaseSetFC is made + """Checks that an error is raised when a PoloidalFieldCoilCaseSetFC is made with the wrong number of casing thicknesses using a list.""" def make_PoloidalFieldCoilCaseSetFC_incorrect_lengths(): @@ -151,7 +151,7 @@ def test_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil(self): def make_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil(): self.test_shape.pf_coils = 20 self.test_shape.solid - + self.assertRaises( ValueError, make_PoloidalFieldCoilCaseSetFC_incorrect_pf_coil diff --git a/tests/test_parametric_components/test_PoloidalFieldCoilSet.py b/tests/test_parametric_components/test_PoloidalFieldCoilSet.py index c77729436..f6df4e89d 100644 --- a/tests/test_parametric_components/test_PoloidalFieldCoilSet.py +++ b/tests/test_parametric_components/test_PoloidalFieldCoilSet.py @@ -89,7 +89,7 @@ def make_PoloidalFieldCoilSet_incorrect_height(): ValueError, make_PoloidalFieldCoilSet_incorrect_height ) - + def test_PoloidalFieldCoilSet_incorrect_width(self): """Checks that an error is raised when a PoloidalFieldCoilSet is made with width passed as the wrong type.""" diff --git a/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py b/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py index 9d6a306a2..30a469ea7 100644 --- a/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py +++ b/tests/test_parametric_components/test_ToroidalFieldCoilRectangle.py @@ -150,10 +150,10 @@ def make_ToroidalFieldCoilRectangle_incorrect_horizontal_start_point(): self.test_shape.solid self.assertRaises( - ValueError, + ValueError, make_ToroidalFieldCoilRectangle_incorrect_horizontal_start_point ) - + def test_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point(self): """Checks that an error is raised when a ToroidalFieldCoilRectangle is made with an incorrect vertical_mid_point.""" @@ -164,6 +164,6 @@ def make_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point(): self.test_shape.solid self.assertRaises( - ValueError, + ValueError, make_ToroidalFieldCoilRectangle_incorrect_vertical_mid_point )