예제 #1
0
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)
예제 #2
0
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):
                ...
예제 #3
0
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):
                    ...
예제 #4
0
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}
예제 #5
0
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)
예제 #6
0
def test_import_module(module, error):
    with pytest.raises(Exception, match=error):
        with external_hook():
            with aws_hook():
                import_module(module)
예제 #7
0
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}")
예제 #8
0
def test_aws_tag():
    with aws_hook():
        from ingraph import aws

        tag = aws.Tag(Key="key", Value="value")
        assert isinstance(tag, core.Property)
예제 #9
0
def test_aws_intrinsic(lid, typ):
    with aws_hook():
        from ingraph import aws

        val = getattr(aws, lid)
        assert issubclass(val, typ)
예제 #10
0
def test_aws_pseudo(lid, typ):
    with aws_hook():
        from ingraph import aws

        val = getattr(aws, lid.upper())
        assert isinstance(val, typ)