-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters