@@ -37,6 +37,42 @@ def test_action__invalid_event_name(session, push_config, in_integration_env, ge
3737 assert get_logs ("ERROR" , "This action has only been designed to work for" )
3838
3939
40+ def get_expected_output (
41+ comment_written : bool , reference_coverage : bool
42+ ) -> dict [str , str ]:
43+ output = {
44+ "COMMENT_FILE_WRITTEN" : str (comment_written ).lower (),
45+ "NEW_COVERED_LINES" : "7" ,
46+ "NEW_NUM_STATEMENTS" : "9" ,
47+ "NEW_PERCENT_COVERED" : "0.7777777777777778" ,
48+ "NEW_MISSING_LINES" : "2" ,
49+ "NEW_EXCLUDED_LINES" : "0" ,
50+ "NEW_NUM_BRANCHES" : "0" ,
51+ "NEW_NUM_PARTIAL_BRANCHES" : "0" ,
52+ "NEW_COVERED_BRANCHES" : "0" ,
53+ "NEW_MISSING_BRANCHES" : "0" ,
54+ "DIFF_TOTAL_NUM_LINES" : "4" ,
55+ "DIFF_TOTAL_NUM_VIOLATIONS" : "1" ,
56+ "DIFF_TOTAL_PERCENT_COVERED" : "0.75" ,
57+ "DIFF_NUM_CHANGED_LINES" : "6" ,
58+ }
59+ if reference_coverage :
60+ output .update (
61+ {
62+ "REFERENCE_COVERED_LINES" : "3" ,
63+ "REFERENCE_NUM_STATEMENTS" : "10" ,
64+ "REFERENCE_PERCENT_COVERED" : "0.3" ,
65+ "REFERENCE_MISSING_LINES" : "7" ,
66+ "REFERENCE_EXCLUDED_LINES" : "0" ,
67+ "REFERENCE_NUM_BRANCHES" : "0" ,
68+ "REFERENCE_NUM_PARTIAL_BRANCHES" : "0" ,
69+ "REFERENCE_COVERED_BRANCHES" : "0" ,
70+ "REFERENCE_MISSING_BRANCHES" : "0" ,
71+ }
72+ )
73+ return output
74+
75+
4076def test_action__pull_request__store_comment (
4177 pull_request_config ,
4278 session ,
@@ -111,13 +147,13 @@ def checker(payload):
111147 in comment
112148 )
113149
114- expected_output = [
115- "COMMENT_FILE_WRITTEN=true" ,
116- "COVERAGE_PERCENTAGE=0.7777777777777778" ,
117- "REFERENCE_COVERAGE_PERCENTAGE=null" ,
118- ]
119- # The order of keys is not guaranteed, so we'll sort the lines
120- assert sorted ( output_file . read_text (). strip (). splitlines ()) == expected_output
150+ output = {
151+ key : value
152+ for key , value in (
153+ line . split ( "=" ) for line in output_file . read_text (). strip (). splitlines ()
154+ )
155+ }
156+ assert output == get_expected_output ( comment_written = True , reference_coverage = False )
121157
122158
123159@pytest .mark .add_branches ("foo" )
@@ -242,13 +278,15 @@ def checker(payload):
242278 assert comment .count ("<img" ) == 10
243279 assert comment == summary_file .read_text ()
244280
245- expected_output = [
246- "COMMENT_FILE_WRITTEN=false" ,
247- "COVERAGE_PERCENTAGE=0.7777777777777778" ,
248- "REFERENCE_COVERAGE_PERCENTAGE=0.3" ,
249- ]
250- # The order of keys is not guaranteed, so we'll sort the lines
251- assert sorted (output_file .read_text ().strip ().splitlines ()) == expected_output
281+ output = {
282+ key : value
283+ for key , value in (
284+ line .split ("=" ) for line in output_file .read_text ().strip ().splitlines ()
285+ )
286+ }
287+ assert output == get_expected_output (
288+ comment_written = False , reference_coverage = False
289+ )
252290
253291
254292def test_action__push__non_default_branch (
@@ -319,13 +357,15 @@ def checker(payload):
319357 assert "Coverage for the whole project went from 30% to 77.77%" in comment
320358 assert comment == summary_file .read_text ()
321359
322- expected_output = [
323- "COMMENT_FILE_WRITTEN=false" ,
324- "COVERAGE_PERCENTAGE=0.7777777777777778" ,
325- "REFERENCE_COVERAGE_PERCENTAGE=0.3" ,
326- ]
327- # The order of keys is not guaranteed, so we'll sort the lines
328- assert sorted (output_file .read_text ().strip ().splitlines ()) == expected_output
360+ output = {
361+ key : value
362+ for key , value in (
363+ line .split ("=" ) for line in output_file .read_text ().strip ().splitlines ()
364+ )
365+ }
366+ assert output == get_expected_output (
367+ comment_written = False , reference_coverage = False
368+ )
329369
330370
331371def test_action__push__no_branch (
@@ -400,13 +440,13 @@ def test_action__push__non_default_branch__no_pr(
400440
401441 assert pathlib .Path ("python-coverage-comment-action.txt" ).exists ()
402442
403- expected_output = [
404- "COMMENT_FILE_WRITTEN=true" ,
405- "COVERAGE_PERCENTAGE=0.7777777777777778" ,
406- "REFERENCE_COVERAGE_PERCENTAGE=0.3" ,
407- ]
408- # The order of keys is not guaranteed, so we'll sort the lines
409- assert sorted ( output_file . read_text (). strip (). splitlines ()) == expected_output
443+ output = {
444+ key : value
445+ for key , value in (
446+ line . split ( "=" ) for line in output_file . read_text (). strip (). splitlines ()
447+ )
448+ }
449+ assert output == get_expected_output ( comment_written = True , reference_coverage = False )
410450
411451
412452def test_action__pull_request__force_store_comment (
@@ -436,13 +476,13 @@ def test_action__pull_request__force_store_comment(
436476
437477 assert pathlib .Path ("python-coverage-comment-action.txt" ).exists ()
438478
439- expected_output = [
440- "COMMENT_FILE_WRITTEN=true" ,
441- "COVERAGE_PERCENTAGE=0.7777777777777778" ,
442- "REFERENCE_COVERAGE_PERCENTAGE=0.3" ,
443- ]
444- # The order of keys is not guaranteed, so we'll sort the lines
445- assert sorted ( output_file . read_text (). strip (). splitlines ()) == expected_output
479+ output = {
480+ key : value
481+ for key , value in (
482+ line . split ( "=" ) for line in output_file . read_text (). strip (). splitlines ()
483+ )
484+ }
485+ assert output == get_expected_output ( comment_written = True , reference_coverage = False )
446486
447487
448488def test_action__pull_request__post_comment__no_marker (
0 commit comments