|
| 1 | +import io |
1 | 2 | import logging |
2 | 3 | import os |
3 | 4 | import re |
4 | 5 | import sys |
5 | 6 | import tempfile |
6 | 7 | import unittest |
7 | 8 | import uuid |
| 9 | +from contextlib import redirect_stdout |
8 | 10 | from pathlib import Path |
9 | 11 |
|
10 | 12 | from geophires_x.Parameter import OutputParameter |
@@ -57,20 +59,26 @@ def test_print_output_to_console(self): |
57 | 59 | example_files = self._list_test_files_dir(test_files_dir='./examples') |
58 | 60 | assert len(example_files) > 0 # test integrity check - no files means something is misconfigured |
59 | 61 |
|
60 | | - params = { |
61 | | - 'Reservoir Temperature': 250.0, |
62 | | - 'Rejection Temperature': 60.0, |
63 | | - 'Reservoir Porosity': 10.0, |
64 | | - 'Reservoir Area': 55.0, |
65 | | - 'Reservoir Thickness': 0.25, |
66 | | - 'Reservoir Life Cycle': 25, |
67 | | - 'Print Output to Console': False, |
68 | | - } |
| 62 | + def get_stdout_from_running(print_output_to_console: bool) -> str: |
| 63 | + params = { |
| 64 | + 'Reservoir Temperature': 250.0, |
| 65 | + 'Rejection Temperature': 60.0, |
| 66 | + 'Reservoir Porosity': 10.0, |
| 67 | + 'Reservoir Area': 55.0, |
| 68 | + 'Reservoir Thickness': 0.25, |
| 69 | + 'Reservoir Life Cycle': 25, |
| 70 | + 'Print Output to Console': print_output_to_console, |
| 71 | + } |
| 72 | + |
| 73 | + f = io.StringIO() |
| 74 | + with redirect_stdout(f): |
| 75 | + result: HipRaResult = HipRaXClient().get_hip_ra_result(HipRaInputParameters(params)) |
69 | 76 |
|
70 | | - result: HipRaResult = HipRaXClient().get_hip_ra_result(HipRaInputParameters(params)) |
71 | | - self.assertIsNotNone(result) |
| 77 | + self.assertIsNotNone(result) |
| 78 | + return f.getvalue() |
72 | 79 |
|
73 | | - # FIXME WIP verify output not printed to console |
| 80 | + self.assertIn('***HIP CASE REPORT***', get_stdout_from_running(True)) |
| 81 | + self.assertNotIn('***HIP CASE REPORT***', get_stdout_from_running(False)) |
74 | 82 |
|
75 | 83 | def test_result_parsing_1(self): |
76 | 84 | result = HipRaResult(self._get_test_file_path('hip-result_example-1.out')) |
|
0 commit comments