Skip to content
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

Fix assert raises tests #681

Merged
merged 3 commits into from
Jan 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_parametric_components/test_CuttingWedgeFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,32 @@ 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,
)

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

Expand Down
16 changes: 8 additions & 8 deletions tests/test_parametric_components/test_Plasma.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import os
import unittest
import pytest
from pathlib import Path

import paramak
Expand Down Expand Up @@ -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)
37 changes: 28 additions & 9 deletions tests/test_parametric_components/test_PoloidalFieldCoilCaseSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
36 changes: 19 additions & 17 deletions tests/test_parametric_components/test_PoloidalFieldCoilCaseSetFC.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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."""

Expand Down
42 changes: 25 additions & 17 deletions tests/test_parametric_components/test_PoloidalFieldCoilSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,54 +75,62 @@ 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],
center_points=[(100, 100), (200, 200), (300, 300)])

self.assertRaises(
ValueError,
test_incorrect_height)
make_PoloidalFieldCoilSet_incorrect_height
)

def test_incorrect_width():
"""Checks PoloidalFieldCoilSet with width as the wrong type."""
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,
center_points=[(100, 100), (200, 200), (300, 300)])

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],
center_points=100)

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],
center_points=[(100, 100), (200, 200), (300, 300)])

self.assertRaises(
ValueError,
test_incorrect_width_length)
make_PoloidalFieldCoilSet_incorrect_width_length
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
)