Skip to content

Commit

Permalink
Set source type: Stub for black tests with options (#9674)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser authored Jan 29, 2024
1 parent bea8f2e commit 0045032
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"preview": "enabled"}
{"preview": "enabled", "source_type": "Stub"}
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,23 @@
}))))
}),
}


class Random:
def func():
random_service.status.active_states.inactive = (
make_new_top_level_state_from_dict(
{
"topLevelBase": {
"secondaryBase": {
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
"actionTimestamp": Timestamp(
seconds=1530584000, nanos=0
).ToJsonString(),
}
},
}
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,21 @@ my_dict = {
}
),
}


class Random:
def func():
random_service.status.active_states.inactive = (
make_new_top_level_state_from_dict({
"topLevelBase": {
"secondaryBase": {
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
"actionTimestamp": (
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
),
}
},
})
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"preview": "enabled"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"is_update": (up := commit.hash in update_hashes)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"is_update": (up := commit.hash in update_hashes)}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def import_fixture(fixture: Path, fixture_set: str):
options_path = fixture_path.with_suffix(".options.json")

if len(options) > 0:
if extension == "pyi":
options["source_type"] = "Stub"

with options_path.open("w") as options_file:
json.dump(options, options_file)
elif os.path.exists(options_path):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,51 +42,39 @@ class TopLevel:
```diff
--- Black
+++ Ruff
@@ -1,7 +1,9 @@
import sys
+
@@ -3,33 +3,27 @@
class Outer:
class InnerStub: ...
+
outer_attr_after_inner_stub: int
-
class Inner:
@@ -9,27 +11,35 @@
inner_attr: int
-
outer_attr: int
+
if sys.version_info > (3, 7):
if sys.platform == "win32":
assignment = 1
+
def function_definition(self): ...
-
def f1(self) -> str: ...
+
if sys.platform != "win32":
+
def function_definition(self): ...
+
assignment = 1
-
def f2(self) -> str: ...
+
class TopLevel:
class Nested1:
foo: int
+
def bar(self): ...
-
field = 1
class Nested2:
def bar(self): ...
+
foo: int
-
field = 1
```

Expand All @@ -95,48 +83,32 @@ class TopLevel:
```python
import sys
class Outer:
class InnerStub: ...
outer_attr_after_inner_stub: int
class Inner:
inner_attr: int
outer_attr: int
if sys.version_info > (3, 7):
if sys.platform == "win32":
assignment = 1
def function_definition(self): ...
def f1(self) -> str: ...
if sys.platform != "win32":
def function_definition(self): ...
assignment = 1
def f2(self) -> str: ...
class TopLevel:
class Nested1:
foo: int
def bar(self): ...
field = 1
class Nested2:
def bar(self): ...
foo: int
field = 1
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ my_dict = {
}))))
}),
}
class Random:
def func():
random_service.status.active_states.inactive = (
make_new_top_level_state_from_dict(
{
"topLevelBase": {
"secondaryBase": {
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
"actionTimestamp": Timestamp(
seconds=1530584000, nanos=0
).ToJsonString(),
}
},
}
)
)
```

## Black Differences
Expand Down Expand Up @@ -94,6 +114,19 @@ my_dict = {
}
{
@@ -58,9 +52,9 @@
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
- "actionTimestamp": (
- Timestamp(seconds=1530584000, nanos=0).ToJsonString()
- ),
+ "actionTimestamp": Timestamp(
+ seconds=1530584000, nanos=0
+ ).ToJsonString(),
}
},
})
```

## Ruff Output
Expand Down Expand Up @@ -142,6 +175,24 @@ my_dict = {
}
),
}
class Random:
def func():
random_service.status.active_states.inactive = (
make_new_top_level_state_from_dict({
"topLevelBase": {
"secondaryBase": {
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
"actionTimestamp": Timestamp(
seconds=1530584000, nanos=0
).ToJsonString(),
}
},
})
)
```

## Black Output
Expand Down Expand Up @@ -196,6 +247,24 @@ my_dict = {
}
),
}
class Random:
def func():
random_service.status.active_states.inactive = (
make_new_top_level_state_from_dict({
"topLevelBase": {
"secondaryBase": {
"timestamp": 1234,
"latitude": 1,
"longitude": 2,
"actionTimestamp": (
Timestamp(seconds=1530584000, nanos=0).ToJsonString()
),
}
},
})
)
```


0 comments on commit 0045032

Please sign in to comment.