|
| 1 | +# Copyright 2022-2025 The Ramble Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 4 | +# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 5 | +# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
| 6 | +# option. This file may not be copied, modified, or distributed |
| 7 | +# except according to those terms. |
| 8 | + |
| 9 | +import pytest |
| 10 | + |
| 11 | +from ramble import main |
| 12 | +from ramble.cmd import style |
| 13 | + |
| 14 | +style_cmd = main.RambleCommand("style") |
| 15 | + |
| 16 | + |
| 17 | +@pytest.mark.parametrize("tool", style.tool_names) |
| 18 | +def test_style(tool): |
| 19 | + out = style_cmd("--tool", tool, __file__) |
| 20 | + assert f"{tool} checks were clean" in out |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.parametrize( |
| 24 | + "content,expected_err", |
| 25 | + [ |
| 26 | + ("import b\nimport a", "Imports are incorrectly sorted"), |
| 27 | + ("import a\nimport b", "No newline at end of file"), |
| 28 | + ], |
| 29 | +) |
| 30 | +def test_style_with_error(tmpdir, content, expected_err): |
| 31 | + with tmpdir.as_cwd(): |
| 32 | + new_file = "new_file.py" |
| 33 | + with open(new_file, "w+") as f: |
| 34 | + f.write(content) |
| 35 | + |
| 36 | + out = style_cmd(new_file, fail_on_error=False) |
| 37 | + assert style_cmd.returncode != 0 |
| 38 | + assert expected_err in out |
| 39 | + |
| 40 | + |
| 41 | +def test_changed_files_all(): |
| 42 | + files = style.changed_files(all_files=True) |
| 43 | + # Currently there are more than 900 files checked for styling. |
| 44 | + # Use a smaller number here. |
| 45 | + assert len(files) > 500 |
| 46 | + |
| 47 | + |
| 48 | +def test_skip_tools(): |
| 49 | + output = style_cmd("--skip", ",".join(style.tool_names)) |
| 50 | + assert "Nothing to run" in output |
0 commit comments