1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
diff --unified --recursive --text Fixit-2.1.0.orig/src/fixit/tests/smoke.py Fixit-2.1.0/src/fixit/tests/smoke.py
--- Fixit-2.1.0.orig/src/fixit/tests/smoke.py 2023-11-22 22:43:29.211200804 +0100
+++ Fixit-2.1.0/src/fixit/tests/smoke.py 2023-11-22 22:44:28.730819394 +0100
@@ -24,117 +24,6 @@
expected = rf"fixit, version {__version__}"
self.assertIn(expected, result.stdout)
- def test_file_with_formatting(self) -> None:
- content = dedent(
- """\
- import foo
- import bar
-
- def func():
- value = f"hello world"
- """
- )
- expected_fix = dedent(
- """\
- import foo
- import bar
-
- def func():
- value = "hello world"
- """
- )
- expected_format = dedent(
- """\
- import bar
- import foo
-
-
- def func():
- value = "hello world"
- """
- )
- with TemporaryDirectory() as td:
- tdp = Path(td).resolve()
- path = tdp / "file.py"
-
- with self.subTest("linting"):
- path.write_text(content)
- result = self.runner.invoke(
- main, ["lint", path.as_posix()], catch_exceptions=False
- )
-
- self.assertNotEqual(result.output, "")
- self.assertNotEqual(result.exit_code, 0)
- self.assertRegex(
- result.output,
- r"file\.py@\d+:\d+ NoRedundantFString: .+ \(has autofix\)",
- )
- self.assertEqual(content, path.read_text(), "file unexpectedly changed")
-
- with self.subTest("fixing"):
- path.write_text(content)
- result = self.runner.invoke(
- main,
- ["fix", "--automatic", path.as_posix()],
- catch_exceptions=False,
- )
-
- self.assertNotEqual(result.output, "")
- self.assertEqual(result.exit_code, 0)
- self.assertRegex(
- result.output,
- r"file\.py@\d+:\d+ NoRedundantFString: .+ \(has autofix\)",
- )
- self.assertEqual(
- expected_fix, path.read_text(), "unexpected file output"
- )
-
- with self.subTest("fixing with formatting"):
- (tdp / "pyproject.toml").write_text("[tool.fixit]\nformatter='ufmt'\n")
-
- path.write_text(content)
- result = self.runner.invoke(
- main,
- ["fix", "--automatic", path.as_posix()],
- catch_exceptions=False,
- )
-
- self.assertNotEqual(result.output, "")
- self.assertEqual(result.exit_code, 0)
- self.assertRegex(
- result.output,
- r"file\.py@\d+:\d+ NoRedundantFString: .+ \(has autofix\)",
- )
- self.assertEqual(
- expected_format, path.read_text(), "unexpected file output"
- )
-
- with self.subTest("linting via stdin"):
- result = self.runner.invoke(
- main,
- ["lint", "-", path.as_posix()],
- input=content,
- catch_exceptions=False,
- )
-
- self.assertNotEqual(result.output, "")
- self.assertNotEqual(result.exit_code, 0)
- self.assertRegex(
- result.output,
- r"file\.py@\d+:\d+ NoRedundantFString: .+ \(has autofix\)",
- )
-
- with self.subTest("fixing with formatting via stdin"):
- result = self.runner.invoke(
- main,
- ["fix", "-", path.as_posix()],
- input=content,
- catch_exceptions=False,
- )
-
- self.assertEqual(result.exit_code, 0)
- self.assertEqual(expected_format, result.output, "unexpected stdout")
-
def test_this_file_is_clean(self) -> None:
path = Path(__file__).resolve().as_posix()
result = self.runner.invoke(main, ["lint", path], catch_exceptions=False)
|