def test_export_notebook_doesnt_exist_error(tmp_path):
    nonexistent_notebook = tmp_path / "anne_hughes_diary.ipynb"
    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
Example #2
0
def cruft_runner():
    runner = CliRunner()
    yield partial(runner.invoke, app)
Example #3
0
import pytest
from typer.testing import CliRunner, Result
from confluence_poster.main import app
from utils import (
    generate_run_cmd,
    run_with_config,
    join_input,
    generate_local_config,
    get_pages_ids_from_stdout,
    confluence_instance,
)
from functools import partial
"""Tests the --create-in-space-root flag of post-page"""
pytestmark = pytest.mark.online

runner = CliRunner(mix_stderr=False)
default_run_cmd = generate_run_cmd(
    runner=runner,
    app=app,
    default_args=["post-page", "--create-in-space-root"])
run_with_config = partial(run_with_config, default_run_cmd=default_run_cmd)


@pytest.mark.parametrize(
    "page_count",
    list(range(1, 3)),
    ids=lambda c:
    f"Create {c} pages in the root with the --create-in-space-root flag",
)
def test_create_one_page_in_space_root(tmp_path, page_count):
    config_file, config = generate_local_config(tmp_path, pages=page_count)
Example #4
0
 def setup_method(self, method):
     # results = self.cli.invoke(cli.app, args...)
     self.cli = CliRunner()
Example #5
0
def test_help():
    """Test the CLI main callback with --help flag."""
    runner = CliRunner()
    result = runner.invoke(app, ["--help"])
    assert result.exit_code == 0
    assert "Automatically export Jupyter notebooks to various file formats" in result.output
Example #6
0
def test_version():
    runner = CliRunner()
    result = runner.invoke(app, ["version"])
    assert result.exit_code == 0
    assert lord_version in result.output
Example #7
0
def cli_runner(tmp_path):
    return CliRunner()
Example #8
0
def test_version():
    """Test the CLI with --version flag."""
    result = CliRunner().invoke(app, ["--version"])
    assert result.exit_code == 0
    assert result.output.strip() == __version__
Example #9
0
def cli_runner():
    return CliRunner()
Example #10
0
def runner() -> CliRunner:
    return CliRunner()
Example #11
0
def test_help():
    """Test the CLI with --help flag."""
    result = CliRunner().invoke(app, ["--help"])
    assert result.exit_code == 0
    assert "Lightweight CLI that wraps Python's `http.server`" in result.output
Example #12
0
def test_main(mockingbird, folder, tmpdir, enrich, force_enrich, entrypoint):
    files_info = [
        {
            "a": "b",
            "enriched": True,
            "name": "a",
            "md5": "0cc175b9c0f1b6a831c399e269772661"
        },
        {
            "c": "d",
            "enriched": False,
            "name": "c",
            "md5": "e2fc714c4727ee9395f324cd2e7f331f"
        },
        {
            "e": "f",
            "name": "e",
            "md5": "187ef4436122d1cc2f40dc2b92f0eba0"
        },
    ]
    input_file = os.path.join(tmpdir, "input.json")
    write_json(input_file, files_info)
    output_file = os.path.join(tmpdir, "output.json")

    if entrypoint == "main":
        with pytest.raises(
                FileNotFoundError
        ):  # nor output_file, input_folder and input_file exist
            main(output_file, None, None, enrich, force_enrich)

        open(output_file, "x")
        with pytest.raises(
                FileExistsError
        ):  # output_file exists and is different from input_file
            main(output_file, None, input_file, enrich, force_enrich)
        os.remove(output_file)

        main(output_file, folder, input_file, enrich, force_enrich)
    elif entrypoint == "typer_app":
        params = [output_file, folder, input_file]
        if enrich:
            params.append("--enrich")
        if force_enrich:
            params.append("--force-enrich")
        runner = CliRunner()
        result = runner.invoke(typer_app, params)
        assert result.exit_code == 0
    else:
        raise NotImplementedError(entrypoint)
    if force_enrich:
        expected_files_info = [
            {
                "name": "a",
                "size": 1,
                "md5": "0cc175b9c0f1b6a831c399e269772661",
                "renamed": True,
                "enriched": True,
                "mock_enriched": True,
                "a": "b"
            },
            {
                "name": "c",
                "size": 4,
                "md5": "e2fc714c4727ee9395f324cd2e7f331f",
                "c": "d",
                "enriched": False,
                "mock_enriched": True
            },
            {
                "name": "e",
                "size": 2,
                "md5": "187ef4436122d1cc2f40dc2b92f0eba0",
                "e": "f",
                "mock_enriched": True
            },
            {
                "name": "movie_3",
                "size": 3,
                "md5": "900150983cd24fb0d6963f7d28e17f72",
                "mock_enriched": True
            },
            {
                "name": "movie_4",
                "size": 0,
                "md5": "d41d8cd98f00b204e9800998ecf8427e",
                "mock_enriched": True
            },
        ]
    elif enrich:
        expected_files_info = [
            {
                "name": "a",
                "size": 1,
                "md5": "0cc175b9c0f1b6a831c399e269772661",
                "renamed": True,
                "enriched": True,
                "a": "b"
            },
            {
                "name": "c",
                "size": 4,
                "md5": "e2fc714c4727ee9395f324cd2e7f331f",
                "c": "d",
                "enriched": False,
                "mock_enriched": True
            },
            {
                "name": "e",
                "size": 2,
                "md5": "187ef4436122d1cc2f40dc2b92f0eba0",
                "e": "f",
                "mock_enriched": True
            },
            {
                "name": "movie_3",
                "size": 3,
                "md5": "900150983cd24fb0d6963f7d28e17f72",
                "mock_enriched": True
            },
            {
                "name": "movie_4",
                "size": 0,
                "md5": "d41d8cd98f00b204e9800998ecf8427e",
                "mock_enriched": True
            },
        ]
    else:
        expected_files_info = [
            {
                "name": "a",
                "size": 1,
                "md5": "0cc175b9c0f1b6a831c399e269772661",
                "renamed": True,
                "enriched": True,
                "a": "b"
            },
            {
                "name": "c",
                "size": 4,
                "md5": "e2fc714c4727ee9395f324cd2e7f331f",
                "c": "d",
                "enriched": False,
            },
            {
                "name": "e",
                "size": 2,
                "md5": "187ef4436122d1cc2f40dc2b92f0eba0",
                "e": "f",
            },
            {
                "name": "movie_3",
                "size": 3,
                "md5": "900150983cd24fb0d6963f7d28e17f72",
            },
            {
                "name": "movie_4",
                "size": 0,
                "md5": "d41d8cd98f00b204e9800998ecf8427e",
            },
        ]
    files_info = read_json(output_file)
    assert sorted(files_info, key=lambda a: a["name"]) == expected_files_info
Example #13
0
def runner() -> CliRunner:
    """Fixture for invoking command-line interfaces."""
    return CliRunner()
Example #14
0
def test_export_no_input_error():
    result = CliRunner().invoke(app, ["export"])

    assert result.exit_code == 2
    assert "Error: Missing argument 'INPUT'." in result.stdout
Example #15
0
def test_refuse_overwrite(tmp_path):
    (tmp_path / ".nbautoexport").touch()
    runner = CliRunner()
    result = runner.invoke(app, ["configure", str(tmp_path)])
    assert result.exit_code == 1
    assert "Detected existing autoexport configuration at" in result.output
def cli_runner() -> CliRunner:
    return CliRunner()
def test_sanity_main(virtualenv_python):
    subprocess.check_call([virtualenv_python, "-m", "pip", "uninstall", "-qy", "pip"])
    runner = CliRunner()
    result = runner.invoke(app, ["--python", virtualenv_python, "tree"])
    assert result.exit_code != 0
    assert "pip not available", result.stderr
Example #18
0
def test_runner(
    benchmark: BenchmarkFixture,
) -> Generator[partial, None, None]:
    runner = CliRunner()
    yield partial(benchmark, runner.invoke, app)
Example #19
0
def test_history_name(clean_start_small):
    runner = CliRunner()
    result = runner.invoke(app, ["history"])
    assert any(["bar" in line for line in result.output.split("\n")])
    result = runner.invoke(app, ["history", "--jobname", "baz"])
    assert all(["foo" not in line for line in result.output.split("\n")])
Example #20
0
    def test_tag_all_with_region_input(self, mocker):
        expected_region = "eu-west-1"
        scanned_resources = {
            expected_region: [
                Resource(
                    "arn:aws:sqs:eu-central-1:111111111111:someq",
                    "someq",
                    "queue",
                    tags,
                ),
                Resource(
                    "arn:aws:sqs:eu-central-1:111111111111:someq2",
                    "someq2",
                    "queue",
                    tags,
                ),
            ],
            "global": [
                Resource(
                    "arn:aws:cloudfront::111111111111:distribution/EMS6KR7IENMDE",
                    "EMS6KR7IENMDE",
                    "distribution",
                    tags,
                ),
                Resource(
                    "arn:aws:route53::111111111111:healthcheck/f665452c-bf56-4a43-8b5d-319c3b8d0a70",
                    "f665452c-bf56-4a43-8b5d-319c3b8d0a70",
                    "healthcheck",
                    tags,
                ),
            ],
        }
        expected_resources = (scanned_resources[expected_region] +
                              scanned_resources["global"])
        expected_tags = [Tag("Owner", "Fritz"), Tag("Project", "CRM")]
        some_config = Config(expected_tags, default_region="eu-central-1")
        runner = CliRunner()
        scan_mock = mocker.patch(
            "taggercli.commands.tag.scan_region_and_global",
            return_value=scanned_resources,
        )
        mocker.patch("taggercli.commands.tag.init_config")
        mocker.patch("taggercli.commands.tag.get_config",
                     return_value=some_config)
        perform_tagging_mock = mocker.patch(
            "taggercli.commands.tag.perform_tagging")

        actual = runner.invoke(cli,
                               ["tag", "all", "--region", expected_region],
                               input="y\n y\n")

        assert not actual.exception
        assert actual.exit_code == 0
        assert actual.stdout.find("Scanning completed")
        assert actual.stdout.find(
            f"Found {len(scanned_resources['global'])} global resources")
        assert actual.stdout.find(
            f"Found {len(scanned_resources[expected_region])} resources in region eu-central-1"
        )
        scan_mock.assert_called_once_with(expected_region)
        perform_tagging_mock.assert_called_with(expected_resources,
                                                expected_tags)
Example #21
0
def cli():
    return CliRunner()
Example #22
0
def runner():
    yield CliRunner()
Example #23
0
def runner():
    return CliRunner()
Example #24
0
def test_configure_no_jupyter_config_warning(tmp_path, monkeypatch):
    monkeypatch.setenv("JUPYTER_CONFIG_DIR", str(tmp_path))

    result = CliRunner().invoke(app, ["configure", str(tmp_path)])
    assert result.exit_code == 0
    assert "Warning: nbautoexport is not properly installed with Jupyter." in result.output
Example #25
0
def test_version():
    """Test the CLI main callback with --version flag."""
    runner = CliRunner()
    result = runner.invoke(app, ["--version"])
    assert result.exit_code == 0
    assert result.output.strip() == __version__
Example #26
0
def test_configure_no_directory_error():
    result = CliRunner().invoke(app, ["configure"])

    assert result.exit_code == 2
    assert "Error" in result.stdout
    assert "Missing argument 'DIRECTORY'." in result.stdout
def runner():
    return CliRunner(mix_stderr=False)
Example #28
0
def test_invalid_organize_by():
    runner = CliRunner()
    result = runner.invoke(app, ["configure", "-b", "invalid-organize-by"])
    assert result.exit_code == 2
    assert "Invalid value for '--organize-by' / '-b'" in result.output
    assert "invalid-organize-by" in result.output
from typer.testing import CliRunner

from cli.main import app
from tests import test_constants

runner = CliRunner()


def test_valid_restaurant_id():
    result = runner.invoke(app, [test_constants.VALID_RESTAURANT_ID])
    assert result.exit_code == 0
    assert test_constants.VALID_RESTAURANT_TITLE in result.stdout


def test_invalid_restaurant_id():
    result = runner.invoke(app, [test_constants.INVALID_RESTAURANT_ID])
    assert result.exit_code == 1


def test_successful_load_of_all_restaurants():
    result = runner.invoke(app, input="0\n")
    assert result.exit_code == 0
    assert "0)" in result.stdout
Example #30
0
def test_export_dir_no_notebooks_error(tmp_path):
    assert len(list(tmp_path.iterdir())) == 0
    result = CliRunner().invoke(app, ["export", str(tmp_path)])
    assert result.exit_code == 1
    assert result.stdout.startswith("No notebooks found in directory")