|
| 1 | +import csv |
1 | 2 | import tempfile
|
2 | 3 | import uuid
|
3 | 4 | from pathlib import Path
|
@@ -615,3 +616,30 @@ def test_parse_sam_cash_flow_profile(self):
|
615 | 616 | cash_flow = result.result['SAM CASH FLOW PROFILE']
|
616 | 617 | self.assertIsNotNone(cash_flow)
|
617 | 618 | self.assertListEqual([''] + [f'Year {y}' for y in range(21)], cash_flow[0])
|
| 619 | + |
| 620 | + def test_csv_with_input_parameters(self): |
| 621 | + with self.assertRaises(NotImplementedError): |
| 622 | + # This should fail because CSV from file path is not implemented. |
| 623 | + ImmutableGeophiresInputParameters(from_file_path=self._get_test_file_path('input_comments.txt')).as_csv() |
| 624 | + |
| 625 | + # Simulate the main use case of adding input parameters to the CSV download from the web interface. |
| 626 | + csv_input = ImmutableGeophiresInputParameters(params={'Reservoir Depth': 3, 'Gradient 1': 50}).as_csv() |
| 627 | + csv_output = GeophiresXResult(self._get_test_file_path('geophires-result_example-1.out')).as_csv() |
| 628 | + csv_parts = csv_output.split(csv.excel.lineterminator, 1) |
| 629 | + csv_result = csv_parts[0] + csv.excel.lineterminator + csv_input + csv_parts[1] |
| 630 | + |
| 631 | + # Ensure the returned CSV are as expected. |
| 632 | + csv_lines = csv_result.splitlines() |
| 633 | + self.assertEqual(csv_lines[0], 'Category,Field,Year,Value,Units') |
| 634 | + self.assertEqual(csv_lines[1], 'INPUT PARAMETERS,Reservoir Depth,,3,') |
| 635 | + self.assertEqual(csv_lines[2], 'INPUT PARAMETERS,Gradient 1,,50,') |
| 636 | + self.assertEqual(csv_lines[3], 'SUMMARY OF RESULTS,End-Use Option,,Direct-Use Heat,') |
| 637 | + self.assertEqual( |
| 638 | + csv_lines[len(csv_lines) - 1], |
| 639 | + 'HEAT AND/OR ELECTRICITY EXTRACTION AND GENERATION PROFILE,PERCENTAGE OF TOTAL HEAT MINED,25,42.7,%', |
| 640 | + ) |
| 641 | + |
| 642 | + # Export the CSV for testing in Excel (or other spreadsheet software). |
| 643 | + result_file = Path(tempfile.gettempdir(), f'geophires-result_{uuid.uuid1()!s}.csv') |
| 644 | + with open(result_file, 'w', newline='', encoding='utf-8') as rf: |
| 645 | + rf.write(csv_result) |
0 commit comments