Skip to content

Commit

Permalink
Update tests for typer rich output (#99)
Browse files Browse the repository at this point in the history
* Update tests for typer rich output. Closes #97

* Use NO_COLOR env var

* Try setting TERM

Co-authored-by: Jay Qi <[email protected]>
  • Loading branch information
jayqi and jayqi authored Jul 31, 2022
1 parent 089cce8 commit eb5937d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions tests/test_cli_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("**/*"))

Expand Down Expand Up @@ -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):
Expand All @@ -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("**/*"))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_cli_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions tests/test_cli_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from itertools import chain, product
from pathlib import Path
import re
import shutil

import pytest
Expand Down Expand Up @@ -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

0 comments on commit eb5937d

Please sign in to comment.