@@ -22,7 +22,9 @@ def test_benchmarks_pull(self, mock_write, mock_read):
2222 with open (dummy_ipynb , "w" ) as f :
2323 f .write ("{}" )
2424
25- result_dir = self .api .benchmarks_pull ("testuser/my-benchmark" , path = tmpdir , quiet = True )
25+ result_dir = self .api .benchmarks_pull (
26+ "testuser/my-benchmark" , path = tmpdir , quiet = True
27+ )
2628 self .assertEqual (result_dir , tmpdir )
2729
2830 # 1. notebooks should be renamed to benchmark.ipynb
@@ -33,7 +35,9 @@ def test_benchmarks_pull(self, mock_write, mock_read):
3335 # 2. jupytext read and write should be called
3436 mock_read .assert_called_once_with (benchmark_ipynb )
3537 mock_write .assert_called_once ()
36- self .assertEqual (mock_write .call_args [0 ][1 ], os .path .join (tmpdir , "benchmark.py" ))
38+ self .assertEqual (
39+ mock_write .call_args [0 ][1 ], os .path .join (tmpdir , "benchmark.py" )
40+ )
3741 self .assertEqual (mock_write .call_args [1 ]["fmt" ], "py:percent" )
3842 self .api .kernels_pull .assert_called_once_with (
3943 "testuser/my-benchmark" , path = tmpdir , metadata = True , quiet = True
@@ -51,15 +55,20 @@ def test_benchmarks_publish_and_run(self, mock_write, mock_read):
5155 self .api .kernels_push = MagicMock (return_value = "push_success" )
5256
5357 result = self .api .benchmarks_publish_and_run (
54- kernel = "testuser/new-benchmark" , path = tmpdir , file_name = "benchmark.py" , quiet = True
58+ kernel = "testuser/new-benchmark" ,
59+ path = tmpdir ,
60+ file_name = "benchmark.py" ,
61+ quiet = True ,
5562 )
5663
5764 self .assertEqual (result , "push_success" )
5865
5966 # verify jupytext was used to read .py and write .ipynb
6067 mock_read .assert_called_once_with (py_file , fmt = "py:percent" )
6168 mock_write .assert_called_once ()
62- self .assertEqual (mock_write .call_args [0 ][1 ], os .path .join (tmpdir , "benchmark.ipynb" ))
69+ self .assertEqual (
70+ mock_write .call_args [0 ][1 ], os .path .join (tmpdir , "benchmark.ipynb" )
71+ )
6372
6473 # verify metadata was created correctly
6574 metadata_file = os .path .join (tmpdir , "kernel-metadata.json" )
@@ -85,7 +94,14 @@ def test_benchmarks_publish_and_run_existing_metadata(self, mock_write, mock_rea
8594 # Create existing metadata
8695 metadata_file = os .path .join (tmpdir , "kernel-metadata.json" )
8796 with open (metadata_file , "w" ) as f :
88- json .dump ({"id" : "otheruser/existing-benchmark" , "code_file" : "old.ipynb" , "keywords" : ["tag1" ]}, f )
97+ json .dump (
98+ {
99+ "id" : "otheruser/existing-benchmark" ,
100+ "code_file" : "old.ipynb" ,
101+ "keywords" : ["tag1" ],
102+ },
103+ f ,
104+ )
89105
90106 self .api .kernels_push = MagicMock (return_value = "push_success" )
91107
@@ -118,7 +134,9 @@ def test_benchmarks_publish_and_run_explicit_kernel(self, mock_write, mock_read)
118134 self .api .kernels_push = MagicMock (return_value = "push_success" )
119135
120136 # Act with explicit kernel override
121- self .api .benchmarks_publish_and_run (kernel = "newuser/new-benchmark" , path = tmpdir , quiet = True )
137+ self .api .benchmarks_publish_and_run (
138+ kernel = "newuser/new-benchmark" , path = tmpdir , quiet = True
139+ )
122140
123141 # Assert
124142 self .api .kernels_push .assert_called_once_with (tmpdir )
@@ -130,7 +148,6 @@ def test_benchmarks_publish_and_run_explicit_kernel(self, mock_write, mock_read)
130148 self .assertNotIn ("id_no" , metadata )
131149 self .assertIn ("personal-benchmark" , metadata ["keywords" ])
132150
133-
134151 @patch ("time.sleep" )
135152 def test_benchmarks_get_results (self , mock_sleep ):
136153 # mock status to return 'running' once, then 'complete'
@@ -139,16 +156,24 @@ def __init__(self, status):
139156 self .status = status
140157 self .failure_message = ""
141158
142- self .api .kernels_status = MagicMock (side_effect = [MockStatus ("running" ), MockStatus ("complete" )])
159+ self .api .kernels_status = MagicMock (
160+ side_effect = [MockStatus ("running" ), MockStatus ("complete" )]
161+ )
143162 self .api .kernels_output = MagicMock (return_value = "output_data" )
144163
145- result = self .api .benchmarks_get_results ("testuser/my-bench" , path = "some_path" , poll_interval = 10 )
164+ result = self .api .benchmarks_get_results (
165+ "testuser/my-bench" , path = "some_path" , poll_interval = 10
166+ )
146167
147168 self .assertEqual (result , "output_data" )
148169 self .assertEqual (self .api .kernels_status .call_count , 2 )
149170 mock_sleep .assert_called_once_with (10 )
150171 self .api .kernels_output .assert_called_once_with (
151- kernel = "testuser/my-bench" , path = "some_path" , force = True , quiet = False
172+ kernel = "testuser/my-bench" ,
173+ path = "some_path" ,
174+ file_pattern = None ,
175+ force = True ,
176+ quiet = False ,
152177 )
153178
154179 def test_benchmarks_get_results_error (self ):
@@ -158,6 +183,7 @@ def __init__(self):
158183 self .failure_message = "syntax error"
159184
160185 self .api .kernels_status = MagicMock (return_value = MockStatusError ())
186+ self .api .kernels_output = MagicMock ()
161187
162188 with self .assertRaisesRegex (ValueError , "error state" ):
163189 self .api .benchmarks_get_results ("testuser/my-bench" )
@@ -168,22 +194,25 @@ class MockStatus:
168194 def __init__ (self , status ):
169195 self .status = status
170196 self .failure_message = ""
171-
197+
172198 self .api .kernels_status = MagicMock (return_value = MockStatus ("complete" ))
173199 self .api .kernels_output = MagicMock (return_value = "output_data" )
174200
175201 with tempfile .TemporaryDirectory () as tmpdir :
176202 # Create existing metadata
177203 metadata_file = os .path .join (tmpdir , "kernel-metadata.json" )
178204 with open (metadata_file , "w" ) as f :
179- import json
180205 json .dump ({"id" : "implicit/my-bench" }, f )
181206
182207 result = self .api .benchmarks_get_results (kernel = None , path = tmpdir )
183208
184209 self .assertEqual (result , "output_data" )
185210 self .api .kernels_output .assert_called_once_with (
186- kernel = "implicit/my-bench" , path = tmpdir , force = True , quiet = False
211+ kernel = "implicit/my-bench" ,
212+ path = tmpdir ,
213+ file_pattern = None ,
214+ force = True ,
215+ quiet = False ,
187216 )
188217
189218
0 commit comments