Skip to content

Commit

Permalink
fix some ast deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhnnsrs committed Sep 20, 2024
1 parent f783f4b commit 8dbf470
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 5 deletions.
35 changes: 35 additions & 0 deletions tests/test_countries_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ast

from .utils import build_relative_glob, unit_test_with
from turms.config import GeneratorConfig
from turms.run import generate_ast
from turms.plugins.enums import EnumsPlugin
from turms.plugins.inputs import InputsPlugin
from turms.plugins.fragments import FragmentsPlugin
from turms.plugins.operations import OperationsPlugin
from turms.stylers.default import DefaultStyler
from turms.run import generate_ast


def test_complex_operations(countries_schema):
config = GeneratorConfig(
pydantic_version="v1",
documents=build_relative_glob("/documents/countries/**.graphql"),
)

generated_ast = generate_ast(
config,
countries_schema,
stylers=[DefaultStyler()],
plugins=[
EnumsPlugin(),
InputsPlugin(),
FragmentsPlugin(),
OperationsPlugin(),
],
)

md = ast.Module(body=generated_ast, type_ignores=[])
generated = ast.unparse(ast.fix_missing_locations(md))
unit_test_with(generated_ast, "Countries(countries=[])")
assert "from enum import Enum" in generated, "EnumPlugin not working"
87 changes: 87 additions & 0 deletions tests/test_documentation_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

from .utils import build_relative_glob, unit_test_with
from turms.config import GeneratorConfig
from turms.run import generate_ast
from turms.plugins.enums import EnumsPlugin
from turms.plugins.inputs import InputsPlugin
from turms.plugins.fragments import FragmentsPlugin
from turms.plugins.operations import OperationsPlugin
from turms.plugins.funcs import (
FunctionDefinition,
FuncsPlugin,
FuncsPluginConfig,
)
from turms.stylers.snake_case import SnakeCaseStyler
from turms.stylers.capitalize import CapitalizeStyler
from turms.run import generate_ast


def test_documentatoin(nested_input_schema):
config = GeneratorConfig(
pydantic_version="v1",
documents=build_relative_glob("/documents/documentation/*.graphql"),
)
generated_ast = generate_ast(
config,
nested_input_schema,
stylers=[CapitalizeStyler(), SnakeCaseStyler()],
plugins=[
EnumsPlugin(),
InputsPlugin(),
FragmentsPlugin(),
OperationsPlugin(),
FuncsPlugin(
config=FuncsPluginConfig(
definitions=[
FunctionDefinition(
type="mutation",
use="mocks.aquery",
is_async=False,
),
FunctionDefinition(
type="mutation",
use="mocks.aquery",
is_async=True,
),
]
),
),
],
)

unit_test_with(generated_ast, "")


def test_default_input_funcs(nested_input_schema):
config = GeneratorConfig(
documents=build_relative_glob("/documents/inputs_default/*.graphql"),
)
generated_ast = generate_ast(
config,
nested_input_schema,
stylers=[CapitalizeStyler(), SnakeCaseStyler()],
plugins=[
EnumsPlugin(),
InputsPlugin(),
FragmentsPlugin(),
OperationsPlugin(),
FuncsPlugin(
config=FuncsPluginConfig(
definitions=[
FunctionDefinition(
type="mutation",
use="mocks.aquery",
is_async=False,
),
FunctionDefinition(
type="mutation",
use="mocks.aquery",
is_async=True,
),
]
),
),
],
)

unit_test_with(generated_ast, "")
29 changes: 29 additions & 0 deletions tests/test_forward_reference_to_interface_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@


from .utils import (
unit_test_with,
)
from turms.config import GeneratorConfig
from turms.run import generate_ast
from turms.plugins.objects import ObjectsPlugin
from turms.run import generate_ast
from turms.stylers.default import DefaultStyler


def test_generation(forward_reference_to_interface_schema):
config = GeneratorConfig(
pydantic_version="v1",

)

generated_ast = generate_ast(

config,
forward_reference_to_interface_schema,
stylers=[DefaultStyler()],
plugins=[
ObjectsPlugin(),
],
)

unit_test_with(generated_ast, "")
48 changes: 48 additions & 0 deletions tests/test_operations_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

from .utils import build_relative_glob, unit_test_with
from turms.config import GeneratorConfig
from turms.run import generate_ast
from turms.plugins.enums import EnumsPlugin
from turms.plugins.inputs import InputsPlugin
from turms.plugins.operations import OperationsPlugin, OperationsPluginConfig
from turms.plugins.fragments import FragmentsPlugin
from turms.stylers.default import DefaultStyler
from turms.run import generate_ast


def test_extra_arguments(arkitekt_schema):
config = GeneratorConfig(
pydantic_version="v1",
documents=build_relative_glob("/documents/arkitekt/**/*.graphql"),
scalar_definitions={
"uuid": "str",
"Callback": "str",
"Any": "typing.Any",
"QString": "str",
"UUID": "pydantic.UUID4",
},
)

generated_ast = generate_ast(
config,
arkitekt_schema,
stylers=[DefaultStyler()],
plugins=[
EnumsPlugin(),
InputsPlugin(),
FragmentsPlugin(),
OperationsPlugin(
config=OperationsPluginConfig(
subscription_bases=["mocks.ExtraOnOperations"],
mutation_bases=["mocks.ExtraOnOperations"],
query_bases=["mocks.ExtraOnOperations"],
arguments_bases=["mocks.ExtraArguments"],
)
),
],
)

unit_test_with(
generated_ast,
"ReturnPortInput(child=ReturnPortInput(bound=BoundTypeInput.AGENT))",
)
1 change: 1 addition & 0 deletions turms/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing import (
Any,
Callable,
Dict,
List,
Optional,
Expand Down
2 changes: 1 addition & 1 deletion turms/plugins/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def generate_input_annotation(
def list_builder(x):
return ast.Subscript(
value=ast.Name("Tuple", ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Constant(value="...")], ctx=ast.Load()),
ctx=ast.Load(),
)

Expand Down
2 changes: 1 addition & 1 deletion turms/plugins/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def generate_object_field_annotation(
def list_builder(x):
return ast.Subscript(
value=ast.Name("Tuple", ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Constant(value="...")], ctx=ast.Load()),
ctx=ast.Load(),
)

Expand Down
2 changes: 1 addition & 1 deletion turms/plugins/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def generate_operation(
if operation_documentation:
class_body_fields.append(
ast.Expr(
value=ast.Str(s=operation_documentation),
value=ast.Constant(value=operation_documentation),
)
)

Expand Down
2 changes: 1 addition & 1 deletion turms/recurse.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class X(BaseModel):
def list_builder(x):
return ast.Subscript(
value=ast.Name("Tuple", ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Ellipsis()], ctx=ast.Load()),
slice=ast.Tuple(elts=[x, ast.Constant(value="...")], ctx=ast.Load()),
ctx=ast.Load(),
)

Expand Down
2 changes: 1 addition & 1 deletion turms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def generate_config_class_pydantic(
config_fields.insert(
0,
ast.Expr(
value=ast.Str(s="A config class"),
value=ast.Constant(value="A config class"),
),
)
if len(config_fields) > 0:
Expand Down

0 comments on commit 8dbf470

Please sign in to comment.