From 883d871acc4f5c81c781eeae1d074ab2b2937490 Mon Sep 17 00:00:00 2001 From: Florian Rathgeber Date: Mon, 5 Feb 2024 23:13:15 +0100 Subject: [PATCH] Add e2e tests reading from / writing to file --- tests/test_end_to_end.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_end_to_end.py b/tests/test_end_to_end.py index fd60731..725c53d 100644 --- a/tests/test_end_to_end.py +++ b/tests/test_end_to_end.py @@ -53,7 +53,7 @@ def nbstripout_exe(): @pytest.mark.parametrize("input_file, expected_file, args", TEST_CASES) -def test_end_to_end_nbstripout(input_file: str, expected_file: str, args: List[str]): +def test_end_to_end_stdin(input_file: str, expected_file: str, args: List[str]): with open(NOTEBOOKS_FOLDER / expected_file, mode="r") as f: expected = f.read() @@ -64,6 +64,19 @@ def test_end_to_end_nbstripout(input_file: str, expected_file: str, args: List[s assert output == expected +@pytest.mark.parametrize("input_file, expected_file, args", TEST_CASES) +def test_end_to_end_file(input_file: str, expected_file: str, args: List[str], tmp_path): + with open(NOTEBOOKS_FOLDER / expected_file, mode="r") as f: + expected = f.read() + + p = tmp_path / input_file + with open(NOTEBOOKS_FOLDER / input_file, mode="r") as f: + p.write_text(f.read()) + pc = run([nbstripout_exe(), p] + args, stdout=PIPE, universal_newlines=True) + + assert not pc.stdout and p.read_text() == expected + + @pytest.mark.parametrize("input_file, extra_args", DRY_RUN_CASES) def test_dry_run_stdin(input_file: str, extra_args: List[str]): expected = "Dry run: would have stripped input from stdin\n"