def test_check_file_syntax_correct_exit_code(self, cli_runner):
        stdin = "foo:  \n"
        params = ["--check", "-"]

        actual = cli_runner.invoke(main, params, input=stdin)

        assert ExitCode(actual.exit_code) is ExitCode.ERROR
    def test_check_file_needs_changes_correct_exit_code(self, cli_runner):
        stdin = 'include:  "a"\n'
        params = ["--check", "-"]

        actual = cli_runner.invoke(main, params, input=stdin)

        assert ExitCode(actual.exit_code) is ExitCode.WOULD_CHANGE
    def test_check_and_diff_doesnt_output_diff_if_error(self, cli_runner):
        stdin = "rule:rule:\n"
        params = ["--check", "--diff", "-"]

        result = cli_runner.invoke(main, params, input=stdin)

        assert ExitCode(result.exit_code) is ExitCode.ERROR
        assert result.output == ""
    def test_check_and_diff_runs_both_with_check_exit_code(self, cli_runner):
        stdin = "x='foo'\n"
        params = ["--check", "--diff", "-"]

        result = cli_runner.invoke(main, params, input=stdin)

        assert ExitCode(result.exit_code) is ExitCode.WOULD_CHANGE
        expected_output = "=====> Diff for stdin <=====\n\n- x='foo'\n+ x = \"foo\"\n\n"
        assert result.output == expected_output
    def test_check_two_files_both_unchanged(self, cli_runner, tmp_path):
        content = 'include: "a"\n'
        file1 = tmp_path / "Snakefile"
        file1.write_text(content)
        file2 = tmp_path / "Snakefile2"
        file2.write_text(content)
        params = ["--check", str(file1), str(file2)]

        result = cli_runner.invoke(main, params)

        assert ExitCode(result.exit_code) is ExitCode.NO_CHANGE
    def test_check_two_files_one_has_errors(self, cli_runner, tmp_path):
        content = 'include: "a"\n'
        file1 = tmp_path / "Snakefile"
        file1.write_text(content)
        file2 = tmp_path / "Snakefile2"
        content += "if:"
        file2.write_text(content)
        params = ["--check", str(file1), str(file2)]

        result = cli_runner.invoke(main, params)

        assert ExitCode(result.exit_code) is ExitCode.ERROR
    def test_check_does_not_format_file(self, cli_runner, tmp_path):
        content = "include: 'a'\nlist_of_lots_of_things = [1, 2, 3, 4, 5, 6, 7, 8]"
        snakefile = tmp_path / "Snakefile"
        snakefile.write_text(content)
        params = ["--check", str(snakefile)]

        result = cli_runner.invoke(main, params)

        assert ExitCode(result.exit_code) is ExitCode.WOULD_CHANGE

        expected_contents = content
        actual_contents = snakefile.read_text()
        assert actual_contents == expected_contents
Exemple #8
0
    def test_check_and_diff_only_runs_check(self, cli_runner, tmp_path):
        content = 'include: "a"\n'
        file1 = tmp_path / "Snakefile"
        file1.write_text(content)
        file2 = tmp_path / "Snakefile2"
        content += "x='foo'"
        file2.write_text(content)
        params = ["--check", "--diff", str(file1), str(file2)]

        result = cli_runner.invoke(main, params)

        assert ExitCode(result.exit_code) is ExitCode.WOULD_CHANGE
        assert result.output == ""