|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class TestMain(unittest.TestCase): |
| 11 | + @classmethod |
| 12 | + def setUpClass(cls) -> None: |
| 13 | + os.environ["GPG_PASS"] = "yourpassword" |
| 14 | + |
11 | 15 | def setUp(self) -> None: |
12 | | - """Setup the test environment.""" |
| 16 | + """Set up the test environment.""" |
13 | 17 |
|
14 | 18 | # Undo anything that might have been set by failing tests. |
15 | 19 | Path("./README.md").unlink(missing_ok=True) |
16 | 20 | Path("./input.txt").unlink(missing_ok=True) |
17 | | - os.unsetenv("GPG_PASS") |
18 | 21 |
|
19 | 22 | def test_main(self) -> None: |
20 | 23 | with patch("subprocess.run") as mock_run: |
21 | 24 | mock_run.return_value.stdout = "helloo" |
22 | 25 | mock_run.return_value.stderr = "1792,0.01,0.02" |
23 | 26 | Path("README.md").write_text("") |
24 | 27 | main.main() |
25 | | - timings: list[str] = ["/usr/bin/time", "-f", "%M,%S,%U"] |
26 | | - a: tuple[list[str], ...] = tuple( |
| 28 | + timings = ["/usr/bin/time", "-f", "%M,%S,%U"] |
| 29 | + a = ( |
27 | 30 | [["dotnet", "fsi", str(PosixPath("day_99/fsharp_iain/solution.fsx")), x] for x in ("one", "two")] |
28 | 31 | + [ |
29 | 32 | ["ipython", "-c", f"%run {str(PosixPath('day_99/jupyter_iain/solution.ipynb'))}", x] |
@@ -59,6 +62,31 @@ def test_main(self) -> None: |
59 | 62 | ], |
60 | 63 | ) |
61 | 64 |
|
| 65 | + def test_main_two(self) -> None: |
| 66 | + with patch("subprocess.run") as mock_run: |
| 67 | + mock_run.return_value.stdout = "helloo" |
| 68 | + mock_run.return_value.stderr = "1792,0.01,0.02" |
| 69 | + shutil.copy(Path("README_TEMPLATE_3.md"), Path("README.md")) |
| 70 | + main.main() |
| 71 | + timings = ["/usr/bin/time", "-f", "%M,%S,%U"] |
| 72 | + a = [["dotnet", "fsi", str(PosixPath("day_99/fsharp_iain/solution.fsx")), x] for x in ("one", "two")] + [ |
| 73 | + ["cargo", "run", "--quiet", "--manifest-path", str(PosixPath("day_99/rust_iain/Cargo.toml")), x] |
| 74 | + for x in ("one", "two") |
| 75 | + ] |
| 76 | + self.assertListEqual( |
| 77 | + mock_run.call_args_list, |
| 78 | + [ |
| 79 | + call( |
| 80 | + timings + x, |
| 81 | + capture_output=True, |
| 82 | + timeout=60, |
| 83 | + text=True, |
| 84 | + check=True, |
| 85 | + ) |
| 86 | + for x in a |
| 87 | + ], |
| 88 | + ) |
| 89 | + |
62 | 90 | def test_measure_one(self) -> None: |
63 | 91 | # Check that we measure the run. |
64 | 92 | actual = main.measure_execution_time(("answer", "answer"), Path("."), lambda x, y: (1792, 0.03, "answer")) |
@@ -157,7 +185,6 @@ def test_write_results_two(self) -> None: |
157 | 185 | self.assertEqual(expected_readme_txt, readme.read_text()) |
158 | 186 |
|
159 | 187 | def test_get_answers(self) -> None: |
160 | | - os.environ["GPG_PASS"] = "yourpassword" |
161 | 188 | actual = main.get_answers(Path("day_99/")) |
162 | 189 | self.assertEqual(("answer", "answer2"), actual) |
163 | 190 |
|
|
0 commit comments