|
14 | 14 |
|
15 | 15 | # ========================== ISOLATED NOTEBOOK TESTS ============================================
|
16 | 16 | #
|
17 |
| -# In these tests are only changed notebooks are tested. It is assumed that notebooks install cirq |
18 |
| -# conditionally if they can't import cirq. This installation path is the main focus and it is |
19 |
| -# exercised in an isolated virtual environment for each notebook. This is also the path that is |
20 |
| -# tested in the devsite workflows, these tests meant to provide earlier feedback. |
| 17 | +# It is assumed that notebooks install cirq conditionally if they can't import cirq. This |
| 18 | +# installation path is the main focus and it is exercised in an isolated virtual environment for |
| 19 | +# each notebook. This is also the path that is tested in the devsite workflows, these tests meant |
| 20 | +# to provide earlier feedback. |
21 | 21 | #
|
22 | 22 | # In case the dev environment changes or this particular file changes, all notebooks are executed!
|
23 | 23 | # This can take a long time and even lead to timeout on Github Actions, hence partitioning of the
|
@@ -155,23 +155,7 @@ def _partitioned_test_cases(notebooks):
|
155 | 155 | return [(f"partition-{i%n_partitions}", notebook) for i, notebook in enumerate(notebooks)]
|
156 | 156 |
|
157 | 157 |
|
158 |
| -@pytest.mark.slow |
159 |
| -@pytest.mark.parametrize( |
160 |
| - "partition, notebook_path", |
161 |
| - _partitioned_test_cases(filter_notebooks(_list_changed_notebooks(), SKIP_NOTEBOOKS)), |
162 |
| -) |
163 |
| -def test_notebooks_against_released_cirq(partition, notebook_path, cloned_env): |
164 |
| - """Tests the notebooks in isolated virtual environments. |
165 |
| -
|
166 |
| - In order to speed up the execution of these tests an auxiliary file may be supplied which |
167 |
| - performs substitutions on the notebook to make it faster. |
168 |
| -
|
169 |
| - Specifically for a notebook file notebook.ipynb, one can supply a file notebook.tst which |
170 |
| - contains the substitutes. The substitutions are provide in the form `pattern->replacement` |
171 |
| - where the pattern is what is matched and replaced. While the pattern is compiled as a |
172 |
| - regular expression, it is considered best practice to not use complicated regular expressions. |
173 |
| - Lines in this file that do not have `->` are ignored. |
174 |
| - """ |
| 158 | +def _rewrite_and_run_notebook(notebook_path, cloned_env): |
175 | 159 | notebook_file = os.path.basename(notebook_path)
|
176 | 160 | notebook_rel_dir = os.path.dirname(os.path.relpath(notebook_path, "."))
|
177 | 161 | out_path = f"out/{notebook_rel_dir}/{notebook_file[:-6]}.out.ipynb"
|
@@ -213,6 +197,40 @@ def test_notebooks_against_released_cirq(partition, notebook_path, cloned_env):
|
213 | 197 | os.remove(rewritten_notebook_path)
|
214 | 198 |
|
215 | 199 |
|
| 200 | +@pytest.mark.slow |
| 201 | +@pytest.mark.parametrize( |
| 202 | + "partition, notebook_path", |
| 203 | + _partitioned_test_cases(filter_notebooks(_list_changed_notebooks(), SKIP_NOTEBOOKS)), |
| 204 | +) |
| 205 | +def test_changed_notebooks_against_released_cirq(partition, notebook_path, cloned_env): |
| 206 | + """Tests changed notebooks in isolated virtual environments. |
| 207 | +
|
| 208 | + In order to speed up the execution of these tests an auxiliary file may be supplied which |
| 209 | + performs substitutions on the notebook to make it faster. |
| 210 | +
|
| 211 | + Specifically for a notebook file notebook.ipynb, one can supply a file notebook.tst which |
| 212 | + contains the substitutes. The substitutions are provide in the form `pattern->replacement` |
| 213 | + where the pattern is what is matched and replaced. While the pattern is compiled as a |
| 214 | + regular expression, it is considered best practice to not use complicated regular expressions. |
| 215 | + Lines in this file that do not have `->` are ignored. |
| 216 | + """ |
| 217 | + _rewrite_and_run_notebook(notebook_path, cloned_env) |
| 218 | + |
| 219 | + |
| 220 | +@pytest.mark.weekly |
| 221 | +@pytest.mark.parametrize( |
| 222 | + "partition, notebook_path", |
| 223 | + _partitioned_test_cases(filter_notebooks(list_all_notebooks(), SKIP_NOTEBOOKS)), |
| 224 | +) |
| 225 | +def test_all_notebooks_against_released_cirq(partition, notebook_path, cloned_env): |
| 226 | + """Tests all notebooks in isolated virtual environments. |
| 227 | +
|
| 228 | + See `test_changed_notebooks_against_released_cirq` for more details on |
| 229 | + notebooks execution. |
| 230 | + """ |
| 231 | + _rewrite_and_run_notebook(notebook_path, cloned_env) |
| 232 | + |
| 233 | + |
216 | 234 | @pytest.mark.parametrize("notebook_path", NOTEBOOKS_DEPENDING_ON_UNRELEASED_FEATURES)
|
217 | 235 | def test_ensure_unreleased_notebooks_install_cirq_pre(notebook_path):
|
218 | 236 | # utf-8 is important for Windows testing, otherwise characters like ┌──┐ fail on cp1252
|
|
0 commit comments