-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from mirumee/no_reimports_plugin
No reimports plugin
- Loading branch information
Showing
7 changed files
with
73 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .extract_operations import ExtractOperationsPlugin | ||
from .no_reimports import NoReimportsPlugin | ||
from .shorter_results import ShorterResultsPlugin | ||
|
||
__all__ = ["ExtractOperationsPlugin", "ShorterResultsPlugin"] | ||
__all__ = ["ExtractOperationsPlugin", "NoReimportsPlugin", "ShorterResultsPlugin"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import ast | ||
|
||
from ariadne_codegen.plugins.base import Plugin | ||
|
||
|
||
class NoReimportsPlugin(Plugin): | ||
def generate_init_module(self, module: ast.Module) -> ast.Module: | ||
module.body = [] | ||
return module |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import ast | ||
|
||
import pytest | ||
|
||
from ariadne_codegen.contrib.no_reimports import NoReimportsPlugin | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"module", | ||
[ | ||
ast.Module( | ||
body=[ | ||
ast.ImportFrom( | ||
module="input_types", names=[ast.alias(name="InputA")], level=1 | ||
), | ||
ast.Assign( | ||
targets=[ast.Name(id="__all__")], | ||
value=ast.List(elts=[ast.Constant(value="InputA")]), | ||
), | ||
], | ||
type_ignores=[], | ||
), | ||
ast.Module(body=[], type_ignores=[]), | ||
], | ||
) | ||
def test_generate_init_module_returns_module_without_body(module): | ||
plugin = NoReimportsPlugin(schema=None, config_dict={}) | ||
|
||
modified_module = plugin.generate_init_module(module) | ||
|
||
assert isinstance(modified_module, ast.Module) | ||
assert not modified_module.body |