def test_import_file(stmt, error, tmpdir): path = tmpdir / "foo.py" path.write_text(stmt, "utf-8") with pytest.raises(Exception, match=error): with external_hook(): with aws_hook(): import_file(path)
def test_custom_resource_bases(): err = "'Foo' can only inherit from 'aws_cloudformation.CustomResource'" with pytest.raises(TypeError, match=err): with importer.aws_hook(): class Foo(CustomResource, str): ...
def test_custom_resource_init(): err = "Foo' level '__init__' is not valid" with pytest.raises(TypeError, match=err): with importer.aws_hook(): from ingraph.aws import aws_cloudformation class Foo(CustomResource, aws_cloudformation.CustomResource): def __init__(self): ...
def test_custom_resource_params(mocker): node = mocker.sentinel.NODE with importer.aws_hook(): from ingraph.aws import aws_cloudformation class Foo(CustomResource, aws_cloudformation.CustomResource): Attr: int foo = Foo(_ig_node=node, ServiceToken="st", bar="BAR", baz=42) assert foo._ig_data == {"ServiceToken": "st", "bar": "BAR", "baz": 42}
def test_definition_wrapper_custom(mocker): source = textwrap.dedent(""" class Foo(CustomResource): Bar: int """) module = types.ModuleType("<adhoc>") mocker.patch.object(parser, "TRANSFORMERS", [DefinitionWrapper]) with importer.aws_hook(): from ingraph.aws.aws_cloudformation import CustomResource module.CustomResource = CustomResource process(source, "<test>", module) assert issubclass(module.Foo, core.CustomResource) assert issubclass(module.Foo, CustomResource)
def test_import_module(module, error): with pytest.raises(Exception, match=error): with external_hook(): with aws_hook(): import_module(module)
def test_aws_modules(): base = Path(__file__).parent.parent.parent.parent / "src" / "ingraph" / "aws" with aws_hook(): for file in list(base.glob("[a-z]*_*.pyi")): import_module(f"ingraph.aws.{file.stem}")
def test_aws_tag(): with aws_hook(): from ingraph import aws tag = aws.Tag(Key="key", Value="value") assert isinstance(tag, core.Property)
def test_aws_intrinsic(lid, typ): with aws_hook(): from ingraph import aws val = getattr(aws, lid) assert issubclass(val, typ)
def test_aws_pseudo(lid, typ): with aws_hook(): from ingraph import aws val = getattr(aws, lid.upper()) assert isinstance(val, typ)