@@ -487,37 +487,6 @@ def test_csv(self):
487487 3. Copy-paste the value of `as_csv` (in Threads & Variables tab in PyCharm) to example1_addons.csv
488488 """
489489
490- def assertFileContentsEqual (expected_file_path , actual_file_path , tol = 0.01 ):
491- with open (expected_file_path , encoding = 'utf-8' ) as ef :
492- expected_lines = ef .readlines ()
493- with open (actual_file_path , encoding = 'utf-8' ) as af :
494- actual_lines = af .readlines ()
495-
496- self .assertEqual (len (expected_lines ), len (actual_lines ), 'The number of lines in the files do not match.' )
497-
498- for line_index , (expected_line , actual_line ) in enumerate (zip (expected_lines , actual_lines ), start = 1 ):
499- expected_parts = expected_line .strip ().split (',' )
500- actual_parts = actual_line .strip ().split (',' )
501- self .assertEqual (
502- len (expected_parts ),
503- len (actual_parts ),
504- f'The number of columns in line { line_index } does not match.' ,
505- )
506- for col_index , (expected , actual ) in enumerate (zip (expected_parts , actual_parts ), start = 1 ):
507- try :
508- expected_float = float (expected )
509- actual_float = float (actual )
510- self .assertTrue (
511- abs (expected_float - actual_float ) < tol ,
512- f'Float values differ at line { line_index } , column { col_index } : { expected } != { actual } ' ,
513- )
514- except ValueError :
515- self .assertEqual (
516- expected ,
517- actual ,
518- f'String values differ at line { line_index } , column { col_index } : { expected } != { actual } ' ,
519- )
520-
521490 def assert_csv_equal (case_report_file_path , expected_csv_file_path ):
522491 test_result_path = self ._get_test_file_path (case_report_file_path )
523492 result = GeophiresXResult (test_result_path )
@@ -527,7 +496,7 @@ def assert_csv_equal(case_report_file_path, expected_csv_file_path):
527496 result_file = Path (tempfile .gettempdir (), f'test_csv-result_{ uuid .uuid1 ()!s} .csv' )
528497 with open (result_file , 'w' , newline = '' , encoding = 'utf-8' ) as rf :
529498 rf .write (as_csv )
530- assertFileContentsEqual (self ._get_test_file_path (expected_csv_file_path ), result_file )
499+ self . assertCsvFileContentsEqual (self ._get_test_file_path (expected_csv_file_path ), result_file )
531500
532501 for case in [
533502 ('examples/example1_addons.out' , 'example1_addons.csv' ),
@@ -536,6 +505,54 @@ def assert_csv_equal(case_report_file_path, expected_csv_file_path):
536505 with self .subTest (msg = case [0 ]):
537506 assert_csv_equal (case [0 ], case [1 ])
538507
508+ op_example_file = 'examples/example_overpressure.out'
509+ with self .subTest (msg = op_example_file ):
510+ # Ensure overpressure-specific RESERVOIR POWER REQUIRED PROFILES doesn't cause issues
511+ op_result = GeophiresXResult (self ._get_test_file_path (op_example_file ))
512+ op_csv = op_result .as_csv ()
513+ self .assertIsNotNone (op_csv )
514+
515+ sam_example_file = 'examples/example_SAM-single-owner-PPA.out'
516+ with self .subTest (msg = sam_example_file ):
517+ sam_result = GeophiresXResult (self ._get_test_file_path (sam_example_file ))
518+ sam_csv = sam_result .as_csv ()
519+ self .assertIsNotNone (sam_csv )
520+ sam_cf_lines = [line .split (',' ) for line in sam_csv .split ('\n ' ) if line .startswith ('SAM CASH FLOW PROFILE' )]
521+ self .assertGreater (len (sam_cf_lines ), 250 )
522+ # TODO test more of the content (but not full result given how big/complex it is, which would add undue
523+ # maintenance overhead)
524+
525+ def assertCsvFileContentsEqual (self , expected_file_path , actual_file_path , tol = 0.01 ):
526+ with open (expected_file_path , encoding = 'utf-8' ) as ef :
527+ expected_lines = ef .readlines ()
528+ with open (actual_file_path , encoding = 'utf-8' ) as af :
529+ actual_lines = af .readlines ()
530+
531+ self .assertEqual (len (expected_lines ), len (actual_lines ), 'The number of lines in the files do not match.' )
532+
533+ for line_index , (expected_line , actual_line ) in enumerate (zip (expected_lines , actual_lines ), start = 1 ):
534+ expected_parts = expected_line .strip ().split (',' )
535+ actual_parts = actual_line .strip ().split (',' )
536+ self .assertEqual (
537+ len (expected_parts ),
538+ len (actual_parts ),
539+ f'The number of columns in line { line_index } does not match.' ,
540+ )
541+ for col_index , (expected , actual ) in enumerate (zip (expected_parts , actual_parts ), start = 1 ):
542+ try :
543+ expected_float = float (expected )
544+ actual_float = float (actual )
545+ self .assertTrue (
546+ abs (expected_float - actual_float ) < tol ,
547+ f'Float values differ at line { line_index } , column { col_index } : { expected } != { actual } ' ,
548+ )
549+ except ValueError :
550+ self .assertEqual (
551+ expected ,
552+ actual ,
553+ f'String values differ at line { line_index } , column { col_index } : { expected } != { actual } ' ,
554+ )
555+
539556 def test_parse_chp_percent_cost_allocation (self ):
540557 result = GeophiresXResult (self ._get_test_file_path ('examples/example3.out' ))
541558 self .assertEqual (
0 commit comments