@@ -11,23 +11,20 @@ class DummyPreviousContext:
11
11
12
12
13
13
class TestRetryUnittestStep (unittest .TestCase ):
14
- @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context " , new_callable = MagicMock )
15
- def setUp (self , mock_instantiate_context ):
14
+ @patch ("seer.automation.pipeline.PipelineStep " , new_callable = MagicMock )
15
+ def setUp (self , _ ):
16
16
self .mock_pr = MagicMock ()
17
17
self .mock_pr .html_url = "http://example.com/pr/123"
18
18
self .mock_pr .url = "http://api.github.com/pr/123"
19
19
self .repo_client = MagicMock ()
20
20
self .repo_client .repo .get_pull .return_value = self .mock_pr
21
-
22
21
self .mock_previous_context = DummyPreviousContext ()
23
22
self .mock_previous_context .original_pr_url = "http://original.com/pr/111"
24
23
self .mock_previous_context .iterations = 1
25
-
26
24
self .context = MagicMock ()
27
25
self .context .get_repo_client .return_value = self .repo_client
28
26
self .context .get_previous_run_context .return_value = self .mock_previous_context
29
27
self .context .event_manager = MagicMock ()
30
-
31
28
self .request_data = {
32
29
"run_id" : 1 ,
33
30
"pr_id" : 123 ,
@@ -45,7 +42,8 @@ def _build_step(self, extra_request=None):
45
42
step .context = self .context
46
43
return step
47
44
48
- def test_invoke_success_status (self ):
45
+ @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context" , new_callable = MagicMock )
46
+ def test_invoke_success_status (self , _ ):
49
47
step = self ._build_step ()
50
48
step .invoke ()
51
49
self .repo_client .post_unit_test_reference_to_original_pr .assert_called_once_with (
@@ -54,30 +52,8 @@ def test_invoke_success_status(self):
54
52
self .context .event_manager .mark_running .assert_called_once ()
55
53
self .context .event_manager .mark_completed .assert_called_once ()
56
54
57
- def test_invoke_failed_status_with_generated_tests (self ):
58
- extra = {"codecov_status" : {"conclusion" : "failure" }}
59
- step = self ._build_step (extra )
60
- mock_diff1 = MagicMock ()
61
- mock_diff2 = MagicMock ()
62
- mock_unittest_output = MagicMock ()
63
- mock_unittest_output .diffs = [mock_diff1 , mock_diff2 ]
64
- with patch .object (
65
- step , "_generate_unit_tests" , return_value = mock_unittest_output
66
- ) as mock_generate :
67
- with patch (
68
- "seer.automation.codegen.retry_unit_test_github_pr_creator.RetryUnitTestGithubPrUpdater"
69
- ) as mock_updater_cls :
70
- instance = mock_updater_cls .return_value
71
- step .invoke ()
72
- mock_generate .assert_called_once_with (
73
- self .repo_client , self .mock_pr , self .mock_previous_context
74
- )
75
- self .context .event_manager .append_file_change .assert_any_call (mock_diff1 )
76
- self .context .event_manager .append_file_change .assert_any_call (mock_diff2 )
77
- instance .update_github_pull_request .assert_called_once ()
78
- self .repo_client .post_unit_test_reference_to_original_pr .assert_not_called ()
79
-
80
- def test_invoke_failed_status_with_no_generated_tests (self ):
55
+ @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context" , new_callable = MagicMock )
56
+ def test_invoke_failed_status_with_no_generated_tests (self , _ ):
81
57
extra = {"codecov_status" : {"conclusion" : "failure" }}
82
58
step = self ._build_step (extra )
83
59
with patch .object (step , "_generate_unit_tests" , return_value = None ) as mock_generate :
@@ -89,7 +65,8 @@ def test_invoke_failed_status_with_no_generated_tests(self):
89
65
self .mock_previous_context .original_pr_url , self .mock_pr .html_url
90
66
)
91
67
92
- def test_max_iterations_reached (self ):
68
+ @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context" , new_callable = MagicMock )
69
+ def test_max_iterations_reached (self , _ ):
93
70
self .mock_previous_context .iterations = RetryUnittestStep .MAX_ITERATIONS
94
71
extra = {"codecov_status" : {"conclusion" : "failure" }}
95
72
step = self ._build_step (extra )
@@ -98,15 +75,17 @@ def test_max_iterations_reached(self):
98
75
mock_generate .assert_not_called ()
99
76
self .repo_client .post_unit_test_reference_to_original_pr .assert_not_called ()
100
77
101
- def test_get_previous_run_context_failure (self ):
78
+ @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context" , new_callable = MagicMock )
79
+ def test_get_previous_run_context_failure (self , _ ):
102
80
self .context .get_previous_run_context .return_value = None
103
81
extra = {"codecov_status" : {"conclusion" : "failure" }}
104
82
step = self ._build_step (extra )
105
83
with self .assertRaises (RuntimeError ):
106
84
step .invoke ()
107
85
self .context .event_manager .mark_completed .assert_called_once ()
108
86
109
- def test_generate_unit_tests_exception (self ):
87
+ @patch ("seer.automation.codegen.step.CodegenStep._instantiate_context" , new_callable = MagicMock )
88
+ def test_generate_unit_tests_exception (self , _ ):
110
89
self .repo_client .get_pr_diff_content .side_effect = Exception ("diff error" )
111
90
step = self ._build_step ()
112
91
result = step ._generate_unit_tests (
@@ -129,7 +108,6 @@ def test_update_github_pull_request_success(self, mock_session_cls):
129
108
mock_pr .html_url = "http://example.com/pr/123"
130
109
repo_client = MagicMock ()
131
110
repo_client .push_new_commit_to_pr .return_value = "new_commit"
132
- # Use a dummy previous context with an integer iterations.
133
111
mock_previous_context = DummyPreviousContext ()
134
112
mock_previous_context .iterations = 1
135
113
updater = RetryUnitTestGithubPrUpdater (
0 commit comments