Skip to content

Commit 2f48232

Browse files
capture stdout and assert output is/isn't present according to Print Output to Console parameter
1 parent 1c08315 commit 2f48232

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tests/hip_ra_x_tests/test_hip_ra_x.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import io
12
import logging
23
import os
34
import re
45
import sys
56
import tempfile
67
import unittest
78
import uuid
9+
from contextlib import redirect_stdout
810
from pathlib import Path
911

1012
from geophires_x.Parameter import OutputParameter
@@ -57,20 +59,26 @@ def test_print_output_to_console(self):
5759
example_files = self._list_test_files_dir(test_files_dir='./examples')
5860
assert len(example_files) > 0 # test integrity check - no files means something is misconfigured
5961

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))
6976

70-
result: HipRaResult = HipRaXClient().get_hip_ra_result(HipRaInputParameters(params))
71-
self.assertIsNotNone(result)
77+
self.assertIsNotNone(result)
78+
return f.getvalue()
7279

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))
7482

7583
def test_result_parsing_1(self):
7684
result = HipRaResult(self._get_test_file_path('hip-result_example-1.out'))

0 commit comments

Comments
 (0)