Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / tools / lint / test / test_ruff.py
blob4313824069aabf81977f7f4ded39f014cdfa232e
1 # -*- coding: utf-8 -*-
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 from pprint import pprint
8 from textwrap import dedent
10 import mozunit
12 LINTER = "ruff"
13 fixed = 0
16 def test_lint_fix(lint, create_temp_file):
17 contents = dedent(
18 """
19 import distutils
20 print("hello!")
21 """
24 path = create_temp_file(contents, "bad.py")
25 lint([path], fix=True)
26 assert fixed == 1
29 def test_lint_fix_warning(lint, create_temp_file):
30 contents = dedent(
31 """
32 import distutils
33 import os
35 def foo():
36 unused_var = 42
37 return
38 """
41 path = create_temp_file(contents, "bad.py")
42 lint([path], warning=True, fix=True)
43 assert fixed == 3
46 def test_lint_fix_withotu_warning(lint, create_temp_file):
47 contents = dedent(
48 """
49 import distutils
50 import os
52 def foo():
53 unused_var = 42
54 return
55 """
58 path = create_temp_file(contents, "bad.py")
59 lint([path], warning=False, fix=True)
60 assert fixed == 2
63 def test_lint_ruff(lint, paths):
64 results = lint(paths())
65 pprint(results, indent=2)
66 assert len(results) == 2
67 assert results[0].level == "error"
68 assert results[0].relpath == "bad.py"
69 assert "`distutils` imported but unused" in results[0].message
72 if __name__ == "__main__":
73 mozunit.main()