From 1b6519c521b799ff5359742a96f0bcaef60970d4 Mon Sep 17 00:00:00 2001 From: softwareengineerprogrammer <4056124+softwareengineerprogrammer@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:13:12 -0700 Subject: [PATCH] Break out client-package-specific tests into separate GeophiresXClientTestCase --- tests/test_geophires_x.py | 128 ---------------------------- tests/test_geophires_x_client.py | 141 +++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 128 deletions(-) create mode 100644 tests/test_geophires_x_client.py diff --git a/tests/test_geophires_x.py b/tests/test_geophires_x.py index 13534d30..75f5eecf 100644 --- a/tests/test_geophires_x.py +++ b/tests/test_geophires_x.py @@ -132,117 +132,6 @@ def test_reservoir_model_2(self): assert result is not None - def test_geophires_x_result_1(self): - test_result_path = self._get_test_file_path('geophires-result_example-1.out') - - result = GeophiresXResult(test_result_path) - - assert result is not None - - expected_price = 7.06 - - assert result.direct_use_heat_breakeven_price_USD_per_MMBTU == expected_price - assert result.result['SUMMARY OF RESULTS']['Direct-Use heat breakeven price']['value'] == expected_price - assert result.result['SUMMARY OF RESULTS']['Direct-Use heat breakeven price']['unit'] == 'USD/MMBTU' - - def test_geophires_x_result_2(self): - test_result_path = self._get_test_file_path('geophires-result_example-2.out') - result = GeophiresXResult(test_result_path) - - assert result is not None - assert result.direct_use_heat_breakeven_price_USD_per_MMBTU is None - assert result.result['SUMMARY OF RESULTS']['Average Net Electricity Production']['value'] == 5.39 - - def test_geophires_x_result_4(self): - test_result_path = self._get_test_file_path('geophires-result_example-4.out') - result = GeophiresXResult(test_result_path) - - assert result is not None - assert result.result['SUMMARY OF RESULTS']['Annual District Heating Demand']['value'] == 242.90 - assert result.result['SUMMARY OF RESULTS']['Annual District Heating Demand']['unit'] == 'GWh/year' - - assert ( - result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Annual District Heating O&M Cost']['value'] - == 0.39 - ) - assert ( - result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Annual District Heating O&M Cost']['unit'] - == 'MUSD/yr' - ) - - assert ( - result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Average Annual Peaking Fuel Cost']['value'] - == 3.01 - ) - assert ( - result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Average Annual Peaking Fuel Cost']['unit'] - == 'MUSD/yr' - ) - - def test_geophires_x_result_generation_profiles(self): - test_result_path = self._get_test_file_path('geophires-result_example-3.out') - result = GeophiresXResult(test_result_path) - - assert result.power_generation_profile is not None - assert len(result.power_generation_profile) == 36 - assert result.power_generation_profile[0] == [ - 'YEAR', - 'THERMAL DRAWDOWN', - 'GEOFLUID TEMPERATURE (deg C)', - 'PUMP POWER (MW)', - 'NET POWER (MW)', - 'NET HEAT (MW)', - 'FIRST LAW EFFICIENCY (%)', - ] - assert result.power_generation_profile[1] == [0, 1.0, 225.24, 0.1791, 20.597, 11.6711, 16.5771] - assert result.power_generation_profile[19] == [18, 0.9877, 222.47, 0.1791, 20.0002, 11.3001, 16.3717] - assert result.power_generation_profile[35] == [34, 0.9248, 208.31, 0.1791, 17.1102, 9.2569, 15.3214] - - assert result.heat_electricity_extraction_generation_profile is not None - assert len(result.heat_electricity_extraction_generation_profile) == 36 - assert result.heat_electricity_extraction_generation_profile[0] == [ - 'YEAR', - 'HEAT PROVIDED (GWh/year)', - 'ELECTRICITY PROVIDED (GWh/year)', - 'HEAT EXTRACTED (GWh/year)', - 'RESERVOIR HEAT CONTENT (10^15 J)', - 'PERCENTAGE OF TOTAL HEAT MINED (%)', - ] - assert result.heat_electricity_extraction_generation_profile[1] == [1, 93.2, 164.4, 1090.2, 80.03, 4.67] - assert result.heat_electricity_extraction_generation_profile[-1] == [35, 72.5, 134.2, 958.47, -48.48, 157.75] - - def test_ags_clgs_result_generation_profiles(self): - test_result_path = self._get_test_file_path('geophires-result_example-5.out') - result = GeophiresXResult(test_result_path) - - assert result.power_generation_profile is not None - assert len(result.power_generation_profile) == 41 - self.assertListEqual( - result.power_generation_profile[0], - [ - 'YEAR', - 'THERMAL DRAWDOWN', - 'GEOFLUID TEMPERATURE (degC)', - 'PUMP POWER (MW)', - 'NET POWER (MW)', - 'FIRST LAW EFFICIENCY (%)', - ], - ) - self.assertListEqual(result.power_generation_profile[1], [1, 1.0000, 108.39, 0.0000, 0.2930, 9.5729]) - assert result.power_generation_profile[-1] == [40, 0.8649, 96.86, 0.0000, 0.2070, 6.7646] - - assert result.heat_electricity_extraction_generation_profile is not None - assert len(result.heat_electricity_extraction_generation_profile) == 41 - assert result.heat_electricity_extraction_generation_profile[0] == [ - 'YEAR', - 'ELECTRICITY PROVIDED (GWh/year)', - 'HEAT EXTRACTED (GWh/year)', - 'RESERVOIR HEAT CONTENT (10^15 J)', - 'PERCENTAGE OF TOTAL HEAT MINED (%)', - ] - assert result.heat_electricity_extraction_generation_profile[1] == [1, 2.6, 30.1, 3.68, 2.86] - assert result.heat_electricity_extraction_generation_profile[-1] == [40, 1.8, 22.7, 0.32, 91.57] - def test_geophires_examples(self): log = _get_logger() client = GeophiresXClient() @@ -295,20 +184,3 @@ def test_runtime_error_with_error_code(self): self.assertEqual( str(re.exception), 'GEOPHIRES encountered an exception: failed with the following error codes: [5500.]' ) - - def test_input_hashing(self): - input1 = GeophiresInputParameters( - {'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 50, 'Maximum Temperature': 250} - ) - - input2 = GeophiresInputParameters( - {'Maximum Temperature': 250, 'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 50} - ) - - assert hash(input1) == hash(input2) - - input3 = GeophiresInputParameters( - {'Maximum Temperature': 420, 'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 69} - ) - - assert hash(input1) != hash(input3) diff --git a/tests/test_geophires_x_client.py b/tests/test_geophires_x_client.py new file mode 100644 index 00000000..601bbc49 --- /dev/null +++ b/tests/test_geophires_x_client.py @@ -0,0 +1,141 @@ +from base_test_case import BaseTestCase +from geophires_x_client import GeophiresXResult +from geophires_x_client.geophires_input_parameters import EndUseOption +from geophires_x_client.geophires_input_parameters import GeophiresInputParameters + + +# noinspection PyTypeChecker +class GeophiresXClientTestCase(BaseTestCase): + """ + Note that these are tests of the geophires_x_client package only and not of the core geophires_x package. + If a test calls geophires_x_client.GeophiresXClient.get_geophires_result then it belongs in + test_geophires_x.GeophiresXTestCase. + """ + + def test_geophires_x_result_1(self): + test_result_path = self._get_test_file_path('geophires-result_example-1.out') + + result = GeophiresXResult(test_result_path) + + assert result is not None + + expected_price = 7.06 + + assert result.direct_use_heat_breakeven_price_USD_per_MMBTU == expected_price + assert result.result['SUMMARY OF RESULTS']['Direct-Use heat breakeven price']['value'] == expected_price + assert result.result['SUMMARY OF RESULTS']['Direct-Use heat breakeven price']['unit'] == 'USD/MMBTU' + + def test_geophires_x_result_2(self): + test_result_path = self._get_test_file_path('geophires-result_example-2.out') + result = GeophiresXResult(test_result_path) + + assert result is not None + assert result.direct_use_heat_breakeven_price_USD_per_MMBTU is None + assert result.result['SUMMARY OF RESULTS']['Average Net Electricity Production']['value'] == 5.39 + + def test_geophires_x_result_4(self): + test_result_path = self._get_test_file_path('geophires-result_example-4.out') + result = GeophiresXResult(test_result_path) + + assert result is not None + assert result.result['SUMMARY OF RESULTS']['Annual District Heating Demand']['value'] == 242.90 + assert result.result['SUMMARY OF RESULTS']['Annual District Heating Demand']['unit'] == 'GWh/year' + + assert ( + result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Annual District Heating O&M Cost']['value'] + == 0.39 + ) + assert ( + result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Annual District Heating O&M Cost']['unit'] + == 'MUSD/yr' + ) + + assert ( + result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Average Annual Peaking Fuel Cost']['value'] + == 3.01 + ) + assert ( + result.result['OPERATING AND MAINTENANCE COSTS (M$/yr)']['Average Annual Peaking Fuel Cost']['unit'] + == 'MUSD/yr' + ) + + def test_geophires_x_result_generation_profiles(self): + test_result_path = self._get_test_file_path('geophires-result_example-3.out') + result = GeophiresXResult(test_result_path) + + assert result.power_generation_profile is not None + assert len(result.power_generation_profile) == 36 + assert result.power_generation_profile[0] == [ + 'YEAR', + 'THERMAL DRAWDOWN', + 'GEOFLUID TEMPERATURE (deg C)', + 'PUMP POWER (MW)', + 'NET POWER (MW)', + 'NET HEAT (MW)', + 'FIRST LAW EFFICIENCY (%)', + ] + assert result.power_generation_profile[1] == [0, 1.0, 225.24, 0.1791, 20.597, 11.6711, 16.5771] + assert result.power_generation_profile[19] == [18, 0.9877, 222.47, 0.1791, 20.0002, 11.3001, 16.3717] + assert result.power_generation_profile[35] == [34, 0.9248, 208.31, 0.1791, 17.1102, 9.2569, 15.3214] + + assert result.heat_electricity_extraction_generation_profile is not None + assert len(result.heat_electricity_extraction_generation_profile) == 36 + assert result.heat_electricity_extraction_generation_profile[0] == [ + 'YEAR', + 'HEAT PROVIDED (GWh/year)', + 'ELECTRICITY PROVIDED (GWh/year)', + 'HEAT EXTRACTED (GWh/year)', + 'RESERVOIR HEAT CONTENT (10^15 J)', + 'PERCENTAGE OF TOTAL HEAT MINED (%)', + ] + assert result.heat_electricity_extraction_generation_profile[1] == [1, 93.2, 164.4, 1090.2, 80.03, 4.67] + assert result.heat_electricity_extraction_generation_profile[-1] == [35, 72.5, 134.2, 958.47, -48.48, 157.75] + + def test_ags_clgs_result_generation_profiles(self): + test_result_path = self._get_test_file_path('geophires-result_example-5.out') + result = GeophiresXResult(test_result_path) + + assert result.power_generation_profile is not None + assert len(result.power_generation_profile) == 41 + self.assertListEqual( + result.power_generation_profile[0], + [ + 'YEAR', + 'THERMAL DRAWDOWN', + 'GEOFLUID TEMPERATURE (degC)', + 'PUMP POWER (MW)', + 'NET POWER (MW)', + 'FIRST LAW EFFICIENCY (%)', + ], + ) + self.assertListEqual(result.power_generation_profile[1], [1, 1.0000, 108.39, 0.0000, 0.2930, 9.5729]) + assert result.power_generation_profile[-1] == [40, 0.8649, 96.86, 0.0000, 0.2070, 6.7646] + + assert result.heat_electricity_extraction_generation_profile is not None + assert len(result.heat_electricity_extraction_generation_profile) == 41 + assert result.heat_electricity_extraction_generation_profile[0] == [ + 'YEAR', + 'ELECTRICITY PROVIDED (GWh/year)', + 'HEAT EXTRACTED (GWh/year)', + 'RESERVOIR HEAT CONTENT (10^15 J)', + 'PERCENTAGE OF TOTAL HEAT MINED (%)', + ] + assert result.heat_electricity_extraction_generation_profile[1] == [1, 2.6, 30.1, 3.68, 2.86] + assert result.heat_electricity_extraction_generation_profile[-1] == [40, 1.8, 22.7, 0.32, 91.57] + + def test_input_hashing(self): + input1 = GeophiresInputParameters( + {'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 50, 'Maximum Temperature': 250} + ) + + input2 = GeophiresInputParameters( + {'Maximum Temperature': 250, 'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 50} + ) + + assert hash(input1) == hash(input2) + + input3 = GeophiresInputParameters( + {'Maximum Temperature': 420, 'End-Use Option': EndUseOption.DIRECT_USE_HEAT.value, 'Gradient 1': 69} + ) + + assert hash(input1) != hash(input3)