Skip to content

Commit 0045032

Browse files
authored
Set source type: Stub for black tests with options (#9674)
1 parent bea8f2e commit 0045032

9 files changed

+124
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"preview": "enabled"}
1+
{"preview": "enabled", "source_type": "Stub"}

crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_long_dict_values.py

+20
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,23 @@
3434
}))))
3535
}),
3636
}
37+
38+
39+
class Random:
40+
def func():
41+
random_service.status.active_states.inactive = (
42+
make_new_top_level_state_from_dict(
43+
{
44+
"topLevelBase": {
45+
"secondaryBase": {
46+
"timestamp": 1234,
47+
"latitude": 1,
48+
"longitude": 2,
49+
"actionTimestamp": Timestamp(
50+
seconds=1530584000, nanos=0
51+
).ToJsonString(),
52+
}
53+
},
54+
}
55+
)
56+
)

crates/ruff_python_formatter/resources/test/fixtures/black/cases/preview_long_dict_values.py.expect

+18
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,21 @@ my_dict = {
4747
}
4848
),
4949
}
50+
51+
52+
class Random:
53+
def func():
54+
random_service.status.active_states.inactive = (
55+
make_new_top_level_state_from_dict({
56+
"topLevelBase": {
57+
"secondaryBase": {
58+
"timestamp": 1234,
59+
"latitude": 1,
60+
"longitude": 2,
61+
"actionTimestamp": (
62+
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
63+
),
64+
}
65+
},
66+
})
67+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"preview": "enabled"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"is_update": (up := commit.hash in update_hashes)
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"is_update": (up := commit.hash in update_hashes)}

crates/ruff_python_formatter/resources/test/fixtures/import_black_tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def import_fixture(fixture: Path, fixture_set: str):
6868
options_path = fixture_path.with_suffix(".options.json")
6969

7070
if len(options) > 0:
71+
if extension == "pyi":
72+
options["source_type"] = "Stub"
73+
7174
with options_path.open("w") as options_file:
7275
json.dump(options, options_file)
7376
elif os.path.exists(options_path):

crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__nested_stub.pyi.snap

+8-36
Original file line numberDiff line numberDiff line change
@@ -42,51 +42,39 @@ class TopLevel:
4242
```diff
4343
--- Black
4444
+++ Ruff
45-
@@ -1,7 +1,9 @@
46-
import sys
47-
48-
+
45+
@@ -3,33 +3,27 @@
4946
class Outer:
5047
class InnerStub: ...
51-
+
5248
outer_attr_after_inner_stub: int
53-
49+
-
5450
class Inner:
55-
@@ -9,27 +11,35 @@
56-
51+
inner_attr: int
52+
-
5753
outer_attr: int
5854
59-
+
6055
if sys.version_info > (3, 7):
6156
if sys.platform == "win32":
6257
assignment = 1
63-
+
6458
def function_definition(self): ...
65-
59+
-
6660
def f1(self) -> str: ...
67-
+
6861
if sys.platform != "win32":
69-
+
7062
def function_definition(self): ...
71-
+
7263
assignment = 1
73-
64+
-
7465
def f2(self) -> str: ...
7566
76-
+
7767
class TopLevel:
7868
class Nested1:
7969
foo: int
80-
+
8170
def bar(self): ...
82-
71+
-
8372
field = 1
8473
8574
class Nested2:
8675
def bar(self): ...
87-
+
8876
foo: int
89-
77+
-
9078
field = 1
9179
```
9280

@@ -95,48 +83,32 @@ class TopLevel:
9583
```python
9684
import sys
9785
98-
9986
class Outer:
10087
class InnerStub: ...
101-
10288
outer_attr_after_inner_stub: int
103-
10489
class Inner:
10590
inner_attr: int
106-
10791
outer_attr: int
10892
109-
11093
if sys.version_info > (3, 7):
11194
if sys.platform == "win32":
11295
assignment = 1
113-
11496
def function_definition(self): ...
115-
11697
def f1(self) -> str: ...
117-
11898
if sys.platform != "win32":
119-
12099
def function_definition(self): ...
121-
122100
assignment = 1
123-
124101
def f2(self) -> str: ...
125102
126-
127103
class TopLevel:
128104
class Nested1:
129105
foo: int
130-
131106
def bar(self): ...
132-
133107
field = 1
134108
135109
class Nested2:
136110
def bar(self): ...
137-
138111
foo: int
139-
140112
field = 1
141113
```
142114

crates/ruff_python_formatter/tests/snapshots/black_compatibility@cases__preview_long_dict_values.py.snap

+69
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ my_dict = {
4141
}))))
4242
}),
4343
}
44+
45+
46+
class Random:
47+
def func():
48+
random_service.status.active_states.inactive = (
49+
make_new_top_level_state_from_dict(
50+
{
51+
"topLevelBase": {
52+
"secondaryBase": {
53+
"timestamp": 1234,
54+
"latitude": 1,
55+
"longitude": 2,
56+
"actionTimestamp": Timestamp(
57+
seconds=1530584000, nanos=0
58+
).ToJsonString(),
59+
}
60+
},
61+
}
62+
)
63+
)
4464
```
4565

4666
## Black Differences
@@ -94,6 +114,19 @@ my_dict = {
94114
}
95115
96116
{
117+
@@ -58,9 +52,9 @@
118+
"timestamp": 1234,
119+
"latitude": 1,
120+
"longitude": 2,
121+
- "actionTimestamp": (
122+
- Timestamp(seconds=1530584000, nanos=0).ToJsonString()
123+
- ),
124+
+ "actionTimestamp": Timestamp(
125+
+ seconds=1530584000, nanos=0
126+
+ ).ToJsonString(),
127+
}
128+
},
129+
})
97130
```
98131

99132
## Ruff Output
@@ -142,6 +175,24 @@ my_dict = {
142175
}
143176
),
144177
}
178+
179+
180+
class Random:
181+
def func():
182+
random_service.status.active_states.inactive = (
183+
make_new_top_level_state_from_dict({
184+
"topLevelBase": {
185+
"secondaryBase": {
186+
"timestamp": 1234,
187+
"latitude": 1,
188+
"longitude": 2,
189+
"actionTimestamp": Timestamp(
190+
seconds=1530584000, nanos=0
191+
).ToJsonString(),
192+
}
193+
},
194+
})
195+
)
145196
```
146197

147198
## Black Output
@@ -196,6 +247,24 @@ my_dict = {
196247
}
197248
),
198249
}
250+
251+
252+
class Random:
253+
def func():
254+
random_service.status.active_states.inactive = (
255+
make_new_top_level_state_from_dict({
256+
"topLevelBase": {
257+
"secondaryBase": {
258+
"timestamp": 1234,
259+
"latitude": 1,
260+
"longitude": 2,
261+
"actionTimestamp": (
262+
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
263+
),
264+
}
265+
},
266+
})
267+
)
199268
```
200269

201270

0 commit comments

Comments
 (0)