Skip to content

Commit

Permalink
Every test with raises
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Feb 8, 2024
1 parent 190d3e4 commit db00b9d
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 181 deletions.
10 changes: 2 additions & 8 deletions GHEtool/test/general_tests/test_GHEtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,12 @@ def test_value_error_cooling_dom_temp_gradient():
borefield.set_borefield(borefield_pyg)
borefield.set_Rb(0.2)

try:
with raises(MaximumNumberOfIterations):
borefield.size()
assert False # pragma: no cover
except MaximumNumberOfIterations:
assert True

borefield.calculation_setup(max_nb_of_iterations=500)
try:
with raises(UnsolvableDueToTemperatureGradient):
borefield.size()
assert False # pragma: no cover
except UnsolvableDueToTemperatureGradient:
assert True


def test_borefield_with_constant_peaks(borefield):
Expand Down
6 changes: 2 additions & 4 deletions GHEtool/test/general_tests/test_GHEtool_two.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from GHEtool import *
from GHEtool.VariableClasses.BaseClass import UnsolvableDueToTemperatureGradient


data = GroundConstantTemperature(3, 10)
data_ground_flux = GroundFluxTemperature(3, 10)

Expand Down Expand Up @@ -174,11 +175,8 @@ def test_no_possible_solution():
borefield.set_max_avg_fluid_temperature(14)
borefield.set_min_avg_fluid_temperature(2)
borefield.load.baseload_heating = borefield.load.baseload_heating * 5
try:
with pytest.raises(UnsolvableDueToTemperatureGradient):
borefield.size(L3_sizing=True)
assert False # pragma: no cover
except UnsolvableDueToTemperatureGradient:
assert True


def test_problem_with_gfunction_calc_obj():
Expand Down
15 changes: 3 additions & 12 deletions GHEtool/test/methods/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
ids=list_of_test_objects.names_L2)
def test_L2(model: Borefield, result):
if not isinstance(result[0], (int, float, str)):
try:
with pytest.raises(result[0]):
model.size_L2(100)
assert False # pragma: no cover
except result[0]:
assert True
else:
assert np.isclose(model.size_L2(100), result[0], atol=1e-2)
assert model.limiting_quadrant == result[1]
Expand All @@ -24,11 +21,8 @@ def test_L2(model: Borefield, result):
ids=list_of_test_objects.names_L3)
def test_L3(model: Borefield, result):
if not isinstance(result[0], (int, float, str)):
try:
with pytest.raises(result[0]):
model.size_L3(100)
assert False # pragma: no cover
except result[0]:
assert True
else:
assert np.isclose(model.size_L3(100), result[0], atol=1e-2)
assert model.calculate_quadrant() == result[1]
Expand All @@ -39,11 +33,8 @@ def test_L3(model: Borefield, result):
ids=list_of_test_objects.names_L4)
def test_L4(model: Borefield, result):
if not isinstance(result[0], (int, float, str)):
try:
with pytest.raises(result[0]):
model.size_L4(100)
assert False # pragma: no cover
except result[0]:
assert True
else:
assert np.isclose(model.size_L4(100), result[0], atol=1e-2)
assert model.calculate_quadrant() == result[1]
Expand Down
8 changes: 3 additions & 5 deletions GHEtool/test/unit-tests/test_borehole.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from GHEtool import FluidData, DoubleUTube, SingleUTube, MultipleUTube
from GHEtool.VariableClasses import Borehole


fluid_data = FluidData(0.2, 0.568, 998, 4180, 1e-3)
pipe_data = DoubleUTube(1, 0.015, 0.02, 0.4, 0.05)

Expand Down Expand Up @@ -101,12 +102,9 @@ def test_Rb():

def test_calculate_Rb_no_data():
borehole = Borehole()

try:
with pytest.raises(ValueError):
borehole.calculate_Rb(100, 1, 0.075, 3)
assert False # pragma: no cover
except ValueError:
assert True


def test_Rb_values():
borehole = Borehole()
Expand Down
29 changes: 6 additions & 23 deletions GHEtool/test/unit-tests/test_calculation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ def test_initialising_setups():

def test_no_backup():
test = CalculationSetup()
try:
with pytest.raises(ValueError):
test.restore_backup()
except ValueError:
assert True


def test_backup_functionality():
Expand Down Expand Up @@ -54,29 +52,17 @@ def test_update_variables():

def test_more_than_one_option():
test = CalculationSetup()
try:
with pytest.raises(ValueError):
test._check_and_set_sizing(True, True, False)
assert False # pragma: no cover
except ValueError:
assert True
try:
with pytest.raises(ValueError):
test._check_and_set_sizing(False, True, True)
assert False # pragma: no cover
except ValueError:
assert True
try:
with pytest.raises(ValueError):
test._check_and_set_sizing(True, False, True)
assert False # pragma: no cover
except ValueError:
assert True


def test_error_quadrant():
try:
with pytest.raises(ValueError):
CalculationSetup(quadrant_sizing=5)
assert False # pragma: no cover
except ValueError:
assert True
CalculationSetup(quadrant_sizing=0)


Expand All @@ -91,8 +77,5 @@ def test_equal_unequal():

def test_assign_incorrect_variable():
setup = CalculationSetup()
try:
with pytest.raises(ValueError):
setup.update_variables(test='test')
assert False # pragma: no cover
except ValueError:
assert True
11 changes: 3 additions & 8 deletions GHEtool/test/unit-tests/test_hourly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,11 @@ def test_load_simulation_period():

def test_set_hourly_values():
load = HourlyGeothermalLoad()
try:
with pytest.raises(ValueError):
load.set_hourly_heating(np.ones(10))
assert False # pragma: no cover
except ValueError:
assert True
try:
with pytest.raises(ValueError):
load.set_hourly_cooling(np.ones(10))
assert False # pragma: no cover
except ValueError:
assert True


### continue for multi year
def test_checks_multiyear():
Expand Down
Loading

0 comments on commit db00b9d

Please sign in to comment.