Skip to content

Commit ce6dd5e

Browse files
committed
test: fix snapshots
Signed-off-by: 11happy <soni5happy@gmail.com>
1 parent 7250d1c commit ce6dd5e

File tree

3 files changed

+268
-20
lines changed

3 files changed

+268
-20
lines changed

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__FURB103_FURB103.py.snap

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,78 @@ FURB103 `open` and `write` should be replaced by `Path("file.txt").write_text(fo
136136
help: Replace with `Path("file.txt").write_text(foobar, newline="\r\n")`
137137

138138
FURB103 `open` and `write` should be replaced by `Path("test.json")....`
139-
--> FURB103.py:154:6
139+
--> FURB103.py:155:6
140140
|
141-
152 | data = {"price": 100}
142-
153 |
143-
154 | with open("test.json", "wb") as f:
141+
153 | data = {"price": 100}
142+
154 |
143+
155 | with open("test.json", "wb") as f:
144144
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145-
155 | f.write(json.dumps(data, indent=4).encode("utf-8"))
145+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
146146
|
147147
help: Replace with `Path("test.json")....`
148+
149+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
150+
--> FURB103.py:158:6
151+
|
152+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
153+
157 |
154+
158 | with Path("file.txt").open("w") as f:
155+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
156+
159 | f.write("test")
157+
|
158+
help: Replace with `Path("file.txt").write_text("test")`
159+
160+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_bytes(b"test")`
161+
--> FURB103.py:161:6
162+
|
163+
159 | f.write("test")
164+
160 |
165+
161 | with Path("file.txt").open("wb") as f:
166+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167+
162 | f.write(b"test")
168+
|
169+
help: Replace with `Path("file.txt").write_bytes(b"test")`
170+
171+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
172+
--> FURB103.py:164:6
173+
|
174+
162 | f.write(b"test")
175+
163 |
176+
164 | with Path("file.txt").open(mode="w") as f:
177+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
178+
165 | f.write("test")
179+
|
180+
help: Replace with `Path("file.txt").write_text("test")`
181+
182+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", encoding="utf8")`
183+
--> FURB103.py:167:6
184+
|
185+
165 | f.write("test")
186+
166 |
187+
167 | with Path("file.txt").open("w", encoding="utf8") as f:
188+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189+
168 | f.write("test")
190+
|
191+
help: Replace with `Path("file.txt").write_text("test", encoding="utf8")`
192+
193+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", errors="ignore")`
194+
--> FURB103.py:170:6
195+
|
196+
168 | f.write("test")
197+
169 |
198+
170 | with Path("file.txt").open("w", errors="ignore") as f:
199+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200+
171 | f.write("test")
201+
|
202+
help: Replace with `Path("file.txt").write_text("test", errors="ignore")`
203+
204+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path(foo()).write_text("test")`
205+
--> FURB103.py:173:6
206+
|
207+
171 | f.write("test")
208+
172 |
209+
173 | with Path(foo()).open("w") as f:
210+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
211+
174 | f.write("test")
212+
|
213+
help: Replace with `Path(foo()).write_text("test")`

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__preview_FURB103_FURB103.py.snap

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,138 @@ help: Replace with `Path("file.txt").write_text(foobar, newline="\r\n")`
217217
78 |
218218

219219
FURB103 [*] `open` and `write` should be replaced by `Path("test.json")....`
220-
--> FURB103.py:154:6
220+
--> FURB103.py:155:6
221221
|
222-
152 | data = {"price": 100}
223-
153 |
224-
154 | with open("test.json", "wb") as f:
222+
153 | data = {"price": 100}
223+
154 |
224+
155 | with open("test.json", "wb") as f:
225225
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
226-
155 | f.write(json.dumps(data, indent=4).encode("utf-8"))
226+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
227227
|
228228
help: Replace with `Path("test.json")....`
229-
148 |
230-
149 | # See: https://github.com/astral-sh/ruff/issues/20785
231-
150 | import json
232-
151 + import pathlib
233229
152 |
234230
153 | data = {"price": 100}
235231
154 |
236232
- with open("test.json", "wb") as f:
237233
- f.write(json.dumps(data, indent=4).encode("utf-8"))
238-
155 + pathlib.Path("test.json").write_bytes(json.dumps(data, indent=4).encode("utf-8"))
234+
155 + Path("test.json").write_bytes(json.dumps(data, indent=4).encode("utf-8"))
235+
156 |
236+
157 | with Path("file.txt").open("w") as f:
237+
158 | f.write("test")
238+
239+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
240+
--> FURB103.py:158:6
241+
|
242+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
243+
157 |
244+
158 | with Path("file.txt").open("w") as f:
245+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246+
159 | f.write("test")
247+
|
248+
help: Replace with `Path("file.txt").write_text("test")`
249+
155 | with open("test.json", "wb") as f:
250+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
251+
157 |
252+
- with Path("file.txt").open("w") as f:
253+
- f.write("test")
254+
158 + Path("file.txt").write_text("test")
255+
159 |
256+
160 | with Path("file.txt").open("wb") as f:
257+
161 | f.write(b"test")
258+
259+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_bytes(b"test")`
260+
--> FURB103.py:161:6
261+
|
262+
159 | f.write("test")
263+
160 |
264+
161 | with Path("file.txt").open("wb") as f:
265+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
266+
162 | f.write(b"test")
267+
|
268+
help: Replace with `Path("file.txt").write_bytes(b"test")`
269+
158 | with Path("file.txt").open("w") as f:
270+
159 | f.write("test")
271+
160 |
272+
- with Path("file.txt").open("wb") as f:
273+
- f.write(b"test")
274+
161 + Path("file.txt").write_bytes(b"test")
275+
162 |
276+
163 | with Path("file.txt").open(mode="w") as f:
277+
164 | f.write("test")
278+
279+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
280+
--> FURB103.py:164:6
281+
|
282+
162 | f.write(b"test")
283+
163 |
284+
164 | with Path("file.txt").open(mode="w") as f:
285+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
286+
165 | f.write("test")
287+
|
288+
help: Replace with `Path("file.txt").write_text("test")`
289+
161 | with Path("file.txt").open("wb") as f:
290+
162 | f.write(b"test")
291+
163 |
292+
- with Path("file.txt").open(mode="w") as f:
293+
- f.write("test")
294+
164 + Path("file.txt").write_text("test")
295+
165 |
296+
166 | with Path("file.txt").open("w", encoding="utf8") as f:
297+
167 | f.write("test")
298+
299+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", encoding="utf8")`
300+
--> FURB103.py:167:6
301+
|
302+
165 | f.write("test")
303+
166 |
304+
167 | with Path("file.txt").open("w", encoding="utf8") as f:
305+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
306+
168 | f.write("test")
307+
|
308+
help: Replace with `Path("file.txt").write_text("test", encoding="utf8")`
309+
164 | with Path("file.txt").open(mode="w") as f:
310+
165 | f.write("test")
311+
166 |
312+
- with Path("file.txt").open("w", encoding="utf8") as f:
313+
- f.write("test")
314+
167 + Path("file.txt").write_text("test", encoding="utf8")
315+
168 |
316+
169 | with Path("file.txt").open("w", errors="ignore") as f:
317+
170 | f.write("test")
318+
319+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", errors="ignore")`
320+
--> FURB103.py:170:6
321+
|
322+
168 | f.write("test")
323+
169 |
324+
170 | with Path("file.txt").open("w", errors="ignore") as f:
325+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
326+
171 | f.write("test")
327+
|
328+
help: Replace with `Path("file.txt").write_text("test", errors="ignore")`
329+
167 | with Path("file.txt").open("w", encoding="utf8") as f:
330+
168 | f.write("test")
331+
169 |
332+
- with Path("file.txt").open("w", errors="ignore") as f:
333+
- f.write("test")
334+
170 + Path("file.txt").write_text("test", errors="ignore")
335+
171 |
336+
172 | with Path(foo()).open("w") as f:
337+
173 | f.write("test")
338+
339+
FURB103 [*] `Path.open()` followed by `write()` can be replaced by `Path(foo()).write_text("test")`
340+
--> FURB103.py:173:6
341+
|
342+
171 | f.write("test")
343+
172 |
344+
173 | with Path(foo()).open("w") as f:
345+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
346+
174 | f.write("test")
347+
|
348+
help: Replace with `Path(foo()).write_text("test")`
349+
170 | with Path("file.txt").open("w", errors="ignore") as f:
350+
171 | f.write("test")
351+
172 |
352+
- with Path(foo()).open("w") as f:
353+
- f.write("test")
354+
173 + Path(foo()).write_text("test")

crates/ruff_linter/src/rules/refurb/snapshots/ruff_linter__rules__refurb__tests__write_whole_file_python_39.snap

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,78 @@ FURB103 `open` and `write` should be replaced by `Path("file.txt").write_text(ba
106106
help: Replace with `Path("file.txt").write_text(bar(bar(a + x)))`
107107

108108
FURB103 `open` and `write` should be replaced by `Path("test.json")....`
109-
--> FURB103.py:154:6
109+
--> FURB103.py:155:6
110110
|
111-
152 | data = {"price": 100}
112-
153 |
113-
154 | with open("test.json", "wb") as f:
111+
153 | data = {"price": 100}
112+
154 |
113+
155 | with open("test.json", "wb") as f:
114114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115-
155 | f.write(json.dumps(data, indent=4).encode("utf-8"))
115+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
116116
|
117117
help: Replace with `Path("test.json")....`
118+
119+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
120+
--> FURB103.py:158:6
121+
|
122+
156 | f.write(json.dumps(data, indent=4).encode("utf-8"))
123+
157 |
124+
158 | with Path("file.txt").open("w") as f:
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126+
159 | f.write("test")
127+
|
128+
help: Replace with `Path("file.txt").write_text("test")`
129+
130+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_bytes(b"test")`
131+
--> FURB103.py:161:6
132+
|
133+
159 | f.write("test")
134+
160 |
135+
161 | with Path("file.txt").open("wb") as f:
136+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137+
162 | f.write(b"test")
138+
|
139+
help: Replace with `Path("file.txt").write_bytes(b"test")`
140+
141+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test")`
142+
--> FURB103.py:164:6
143+
|
144+
162 | f.write(b"test")
145+
163 |
146+
164 | with Path("file.txt").open(mode="w") as f:
147+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148+
165 | f.write("test")
149+
|
150+
help: Replace with `Path("file.txt").write_text("test")`
151+
152+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", encoding="utf8")`
153+
--> FURB103.py:167:6
154+
|
155+
165 | f.write("test")
156+
166 |
157+
167 | with Path("file.txt").open("w", encoding="utf8") as f:
158+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159+
168 | f.write("test")
160+
|
161+
help: Replace with `Path("file.txt").write_text("test", encoding="utf8")`
162+
163+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path("file.txt").write_text("test", errors="ignore")`
164+
--> FURB103.py:170:6
165+
|
166+
168 | f.write("test")
167+
169 |
168+
170 | with Path("file.txt").open("w", errors="ignore") as f:
169+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
170+
171 | f.write("test")
171+
|
172+
help: Replace with `Path("file.txt").write_text("test", errors="ignore")`
173+
174+
FURB103 `Path.open()` followed by `write()` can be replaced by `Path(foo()).write_text("test")`
175+
--> FURB103.py:173:6
176+
|
177+
171 | f.write("test")
178+
172 |
179+
173 | with Path(foo()).open("w") as f:
180+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
181+
174 | f.write("test")
182+
|
183+
help: Replace with `Path(foo()).write_text("test")`

0 commit comments

Comments
 (0)