|
| 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
|
@@ -53,6 +55,30 @@ def get_output_file_for_example(example_file: Path):
|
53 | 55 | # TODO
|
54 | 56 | # self.assertFileContentsEqual(expected_result_output_file_path, result.output_file_path)
|
55 | 57 |
|
| 58 | + def test_print_output_to_console(self): |
| 59 | + def get_stdout_from_running(print_output_to_console: bool | int) -> str: |
| 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': print_output_to_console, |
| 68 | + } |
| 69 | + |
| 70 | + f = io.StringIO() |
| 71 | + with redirect_stdout(f): |
| 72 | + result: HipRaResult = HipRaXClient().get_hip_ra_result(HipRaInputParameters(params)) |
| 73 | + |
| 74 | + self.assertIsNotNone(result) |
| 75 | + return f.getvalue() |
| 76 | + |
| 77 | + self.assertIn('***HIP CASE REPORT***', get_stdout_from_running(True)) |
| 78 | + self.assertNotIn('***HIP CASE REPORT***', get_stdout_from_running(False)) |
| 79 | + self.assertIn('***HIP CASE REPORT***', get_stdout_from_running(1)) |
| 80 | + self.assertNotIn('***HIP CASE REPORT***', get_stdout_from_running(0)) |
| 81 | + |
56 | 82 | def test_result_parsing_1(self):
|
57 | 83 | result = HipRaResult(self._get_test_file_path('hip-result_example-1.out'))
|
58 | 84 | self.assertIsNotNone(result.result)
|
|
0 commit comments