|
| 1 | +import csv |
1 | 2 | import tempfile
|
2 | 3 | import uuid
|
3 | 4 | from pathlib import Path
|
@@ -631,3 +632,30 @@ def test_stash_cwd(self):
|
631 | 632 | )
|
632 | 633 |
|
633 | 634 | self.assertEqual(start_cwd, Path.cwd())
|
| 635 | + |
| 636 | + def test_csv_with_input_parameters(self): |
| 637 | + with self.assertRaises(NotImplementedError): |
| 638 | + # This should fail because CSV from file path is not implemented. |
| 639 | + ImmutableGeophiresInputParameters(from_file_path=self._get_test_file_path('input_comments.txt')).as_csv() |
| 640 | + |
| 641 | + # Simulate the main use case of adding input parameters to the CSV download from the web interface. |
| 642 | + csv_input = ImmutableGeophiresInputParameters(params={'Reservoir Depth': 3, 'Gradient 1': 50}).as_csv() |
| 643 | + csv_output = GeophiresXResult(self._get_test_file_path('geophires-result_example-1.out')).as_csv() |
| 644 | + csv_parts = csv_output.split(csv.excel.lineterminator, 1) |
| 645 | + csv_result = csv_parts[0] + csv.excel.lineterminator + csv_input + csv_parts[1] |
| 646 | + |
| 647 | + # Ensure the returned CSV are as expected. |
| 648 | + csv_lines = csv_result.splitlines() |
| 649 | + self.assertEqual(csv_lines[0], 'Category,Field,Year,Value,Units') |
| 650 | + self.assertEqual(csv_lines[1], 'INPUT PARAMETERS,Reservoir Depth,,3,') |
| 651 | + self.assertEqual(csv_lines[2], 'INPUT PARAMETERS,Gradient 1,,50,') |
| 652 | + self.assertEqual(csv_lines[3], 'SUMMARY OF RESULTS,End-Use Option,,Direct-Use Heat,') |
| 653 | + self.assertEqual( |
| 654 | + csv_lines[len(csv_lines) - 1], |
| 655 | + 'HEAT AND/OR ELECTRICITY EXTRACTION AND GENERATION PROFILE,PERCENTAGE OF TOTAL HEAT MINED,25,42.7,%', |
| 656 | + ) |
| 657 | + |
| 658 | + # Export the CSV for testing in Excel (or other spreadsheet software). |
| 659 | + result_file = Path(tempfile.gettempdir(), f'geophires-result_{uuid.uuid1()!s}.csv') |
| 660 | + with open(result_file, 'w', newline='', encoding='utf-8') as rf: |
| 661 | + rf.write(csv_result) |
0 commit comments