11"""Unit tests for main.py"""
2+
23import io
34import json
45import os
1617class TestBuildCheckArgs (unittest .TestCase ):
1718 def test_all_true (self ):
1819 result = main .build_check_args ("true" , "true" , "true" , "true" )
19- self .assertEqual (result , ["--message" , "--branch" , "--author-name" , "--author-email" ])
20+ self .assertEqual (
21+ result , ["--message" , "--branch" , "--author-name" , "--author-email" ]
22+ )
2023
2124 def test_all_false (self ):
2225 result = main .build_check_args ("false" , "false" , "false" , "false" )
@@ -62,7 +65,11 @@ def test_single_message_fail(self):
6265 self .assertEqual (rc , 1 )
6366
6467 def test_multiple_messages_partial_failure (self ):
65- results = [MagicMock (returncode = 0 ), MagicMock (returncode = 1 ), MagicMock (returncode = 0 )]
68+ results = [
69+ MagicMock (returncode = 0 ),
70+ MagicMock (returncode = 1 ),
71+ MagicMock (returncode = 0 ),
72+ ]
6673 with patch ("main.subprocess.run" , side_effect = results ):
6774 rc = main .run_pr_message_checks (["ok" , "bad" , "ok" ], self ._make_file ())
6875 self .assertEqual (rc , 1 )
@@ -125,7 +132,9 @@ def test_rc_one(self):
125132 def test_command_contains_all_args (self ):
126133 mock_result = MagicMock (returncode = 0 )
127134 with patch ("main.subprocess.run" , return_value = mock_result ) as mock_run :
128- main .run_default_checks (["--message" , "--branch" , "--author-name" ], io .StringIO ())
135+ main .run_default_checks (
136+ ["--message" , "--branch" , "--author-name" ], io .StringIO ()
137+ )
129138 called_cmd = mock_run .call_args [0 ][0 ]
130139 self .assertEqual (
131140 called_cmd ,
@@ -152,6 +161,7 @@ def setUp(self):
152161 # Ensure result.txt is written to a temp location
153162 self ._orig_dir = os .getcwd ()
154163 import tempfile
164+
155165 self ._tmpdir = tempfile .mkdtemp ()
156166 os .chdir (self ._tmpdir )
157167
@@ -300,6 +310,7 @@ def test_exception_returns_empty(self):
300310class TestReadResultFile (unittest .TestCase ):
301311 def setUp (self ):
302312 import tempfile
313+
303314 self ._orig_dir = os .getcwd ()
304315 self ._tmpdir = tempfile .mkdtemp ()
305316 os .chdir (self ._tmpdir )
@@ -335,6 +346,7 @@ def test_trailing_whitespace_stripped(self):
335346class TestAddJobSummary (unittest .TestCase ):
336347 def setUp (self ):
337348 import tempfile
349+
338350 self ._orig_dir = os .getcwd ()
339351 self ._tmpdir = tempfile .mkdtemp ()
340352 os .chdir (self ._tmpdir )
@@ -387,6 +399,7 @@ def test_no_event_path(self):
387399
388400 def test_same_repo_not_fork (self ):
389401 import tempfile
402+
390403 event = {
391404 "pull_request" : {
392405 "head" : {"repo" : {"full_name" : "owner/repo" }},
@@ -403,6 +416,7 @@ def test_same_repo_not_fork(self):
403416
404417 def test_different_repo_is_fork (self ):
405418 import tempfile
419+
406420 event = {
407421 "pull_request" : {
408422 "head" : {"repo" : {"full_name" : "fork-owner/repo" }},
@@ -419,6 +433,7 @@ def test_different_repo_is_fork(self):
419433
420434 def test_json_parse_failure_returns_false (self ):
421435 import tempfile
436+
422437 with tempfile .NamedTemporaryFile (mode = "w" , suffix = ".json" , delete = False ) as f :
423438 f .write ("not valid json{{{" )
424439 event_path = f .name
@@ -470,6 +485,7 @@ def test_empty_string_result_text_no_print(self):
470485class TestMain (unittest .TestCase ):
471486 def setUp (self ):
472487 import tempfile
488+
473489 self ._orig_dir = os .getcwd ()
474490 self ._tmpdir = tempfile .mkdtemp ()
475491 os .chdir (self ._tmpdir )
0 commit comments