diff --git a/tests/conftest.py b/tests/conftest.py index 2479685..a35c4a5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,6 +6,12 @@ from nbautoexport.utils import JupyterNotebook +@pytest.fixture(autouse=True) +def disable_typer_rich_colors(monkeypatch): + # https://rich.readthedocs.io/en/stable/console.html#environment-variables + monkeypatch.setenv("TERM", "unknown") + + @pytest.fixture(scope="session") def notebook_asset(): return JupyterNotebook.from_file(Path(__file__).parent / "assets" / "the_notebook.ipynb") diff --git a/tests/test_cli.py b/tests/test_cli.py index 9895f9d..12a9265 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -13,7 +13,8 @@ def test_no_command(): runner = CliRunner() result = runner.invoke(app) assert result.exit_code > 0 - assert "Error: Missing command." in result.output + assert "Error" in result.output + assert "Missing command." in result.output def test_help(): @@ -41,7 +42,8 @@ def test_no_command_python_m(): universal_newlines=True, ) assert result.returncode > 0 - assert "Error: Missing command." in result.stderr + assert "Error" in result.stderr + assert "Missing command." in result.stderr assert result.stderr.startswith("Usage: python -m nbautoexport") assert "Usage: __main__.py" not in result.stderr diff --git a/tests/test_cli_clean.py b/tests/test_cli_clean.py index 29ad050..3d2f74b 100644 --- a/tests/test_cli_clean.py +++ b/tests/test_cli_clean.py @@ -206,7 +206,7 @@ def test_clean_abort(notebooks_dir): result = CliRunner().invoke(app, ["clean", str(notebooks_dir)], input="n") assert result.exit_code == 1 - assert result.stdout.endswith("Aborted!\n") + assert result.stdout.strip().endswith("Aborted.") ending_files = set(notebooks_dir.glob("**/*")) @@ -234,7 +234,8 @@ def test_clean_no_directory_error(): result = CliRunner().invoke(app, ["clean"]) assert result.exit_code == 2 - assert "Error: Missing argument 'DIRECTORY'." in result.stdout + assert "Error" in result.stdout + assert "Missing argument 'DIRECTORY'." in result.stdout def test_clean_missing_config_error(notebooks_dir): @@ -244,7 +245,8 @@ def test_clean_missing_config_error(notebooks_dir): result = CliRunner().invoke(app, ["clean", str(notebooks_dir)]) assert result.exit_code == 1 - assert "Error: Missing expected nbautoexport config file" in result.stdout + assert "Error" in result.stdout + assert "Missing expected nbautoexport config file" in result.stdout assert str(sentinel_path.resolve()) in result.stdout ending_files = set(notebooks_dir.glob("**/*")) diff --git a/tests/test_cli_configure.py b/tests/test_cli_configure.py index abd8eeb..411ad01 100644 --- a/tests/test_cli_configure.py +++ b/tests/test_cli_configure.py @@ -64,7 +64,8 @@ def test_invalid_export_format(): runner = CliRunner() result = runner.invoke(app, ["configure", "-f", "invalid-output-format"]) assert result.exit_code == 2 - assert "Error: Invalid value for '--export-format' / '-f'" in result.output + assert "Error" in result.output + assert "Invalid value for '--export-format' / '-f'" in result.output assert "invalid-output-format" in result.output @@ -152,4 +153,5 @@ def test_configure_no_directory_error(): result = CliRunner().invoke(app, ["configure"]) assert result.exit_code == 2 - assert "Error: Missing argument 'DIRECTORY'." in result.stdout + assert "Error" in result.stdout + assert "Missing argument 'DIRECTORY'." in result.stdout diff --git a/tests/test_cli_export.py b/tests/test_cli_export.py index c79a140..1cd5e65 100644 --- a/tests/test_cli_export.py +++ b/tests/test_cli_export.py @@ -1,5 +1,6 @@ from itertools import chain, product from pathlib import Path +import re import shutil import pytest @@ -225,11 +226,12 @@ def test_export_notebook_doesnt_exist_error(tmp_path): assert not nonexistent_notebook.exists() result = CliRunner().invoke(app, ["export", str(nonexistent_notebook)]) assert result.exit_code == 2 - assert "does not exist" in result.stdout + assert re.search("does[^a-zA-Z]+not[^a-zA-Z]+exist", result.stdout) def test_export_no_input_error(): result = CliRunner().invoke(app, ["export"]) assert result.exit_code == 2 - assert "Error: Missing argument 'INPUT'." in result.stdout + assert "Error" in result.stdout + assert "Missing argument 'INPUT'." in result.stdout