def __init__( self, *, p1: int, p1d: int = Number(42), p2: float, p2d: float = Number(42.42), p3: str, p3d: str = String("foo"), p4: List[int], p4d: List[int] = LISTS[Number]([Number(42)]), p5: List[float], p5d: List[float] = LISTS[Number]([Number(42.42)]), p6: List[str], p6d: List[str] = LISTS[String]([String("foo")]), ): assert not isinstance(p1, Static) assert not isinstance(p1d, Static) assert not isinstance(p2, Static) assert not isinstance(p2d, Static) assert not isinstance(p3, Static) assert not isinstance(p3d, Static) assert not isinstance(p4, Static) assert not isinstance(p4[Number(0)], SELECTS[Number]) assert not isinstance(p4[Number(0)], Static) assert not isinstance(p4d, Static) assert not isinstance(p4d[Number(0)], SELECTS[Number]) assert not isinstance(p4d[Number(0)], Static) assert not isinstance(p5, Static) assert not isinstance(p5d, Static) assert not isinstance(p6, Static) assert not isinstance(p6d, Static)
def test_string_format(): res = String("{} {foo} {foo}").format(String("bar"), foo=Number()) assert isinstance(res, Sub) assert isinstance(res, String) assert not isinstance(res, Static) assert res._ig_format._ig_value == "${A0} ${A1} ${A1}" assert len(res._ig_kwargs._ig_value) == 2
def test_string_replace_check(target): with pytest.raises(TypeError, match="new is not a string"): target.replace(String("f"), None) with pytest.raises(TypeError, match="separator is not a static string"): target.replace(String(), String("-")) with pytest.raises(TypeError, match="separator is not a static string"): target.replace(String("-"), String())
def test_cidr_check(): with pytest.raises(TypeError, match="block is not a string"): CIDR(block=None, count=Number(), bits=Number()) with pytest.raises(TypeError, match="count is not a number"): CIDR(block=String(), count=None, bits=Number()) with pytest.raises(TypeError, match="bits is not a number"): CIDR(block=String(), count=Number(), bits=None)
def test_sub_check(): with pytest.raises(TypeError, match="format is not a static string"): Sub(String(), Map({})) with pytest.raises(TypeError, match="kwargs is not a static map"): Sub(String("foo"), Map()) err = "kwargs values are not only number or string" with pytest.raises(TypeError, match=err): Sub(String("foo"), Map({String("foo"): Boolean()}))
def test_external_paramvalue(mocker): from typing import List node = mocker.sentinel.NODE class Foo(ExternalResource): def __init__( self, *, p1: int, p1d: int = Number(42), p2: float, p2d: float = Number(42.42), p3: str, p3d: str = String("foo"), p4: List[int], p4d: List[int] = LISTS[Number]([Number(42)]), p5: List[float], p5d: List[float] = LISTS[Number]([Number(42.42)]), p6: List[str], p6d: List[str] = LISTS[String]([String("foo")]), ): assert not isinstance(p1, Static) assert not isinstance(p1d, Static) assert not isinstance(p2, Static) assert not isinstance(p2d, Static) assert not isinstance(p3, Static) assert not isinstance(p3d, Static) assert not isinstance(p4, Static) assert not isinstance(p4[Number(0)], SELECTS[Number]) assert not isinstance(p4[Number(0)], Static) assert not isinstance(p4d, Static) assert not isinstance(p4d[Number(0)], SELECTS[Number]) assert not isinstance(p4d[Number(0)], Static) assert not isinstance(p5, Static) assert not isinstance(p5d, Static) assert not isinstance(p6, Static) assert not isinstance(p6d, Static) Foo( _ig_node=node, p1=Number(42), p2=Number(42.42), p3=String("foo"), p4=LISTS[Number]([Number(42)]), p5=LISTS[Number]([Number(42.42)]), p6=LISTS[String]([String("foo")]), )
def test_asset_check(): err = "asset name is not a static string" with pytest.raises(TypeError, match=err): Asset(name=String()) err = "asset compress is not a static boolean" with pytest.raises(TypeError, match=err): Asset(name=String("foo"), compress=Boolean()) err = "asset name includes path parts" with pytest.raises(ValueError, match=err): Asset(name=String("../foo")) err = "cannot retrieve text content from compressed asset" with pytest.raises(TypeError, match=err): Asset(name=String("__init__.py"), compress=Boolean(True)).text
def __init__( self, *, p1: int, p1d: int = Number(42), p2: float, p2d: float = Number(42.42), p3: str, p3d: str = String("foo"), p4: List[int], p4d: List[int] = LISTS[Number]([Number(42)]), p5: List[float], p5d: List[float] = LISTS[Number]([Number(42.42)]), p6: List[str], p6d: List[str] = LISTS[String]([String("foo")]), ): ...
def test_getparmeters(): from typing import List defaults = dict( p1d=Number(42), p2d=Number(42.42), p3d=String("foo"), p4d=LISTS[Number]([Number(42)]), p5d=LISTS[Number]([Number(42.42)]), p6d=LISTS[String]([String("foo")]), ) class Foo(ExternalResource): def __init__( self, *, p1: int, p1d: int = defaults["p1d"], p2: float, p2d: float = defaults["p2d"], p3: str, p3d: str = defaults["p3d"], p4: List[int], p4d: List[int] = defaults["p4d"], p5: List[float], p5d: List[float] = defaults["p5d"], p6: List[str], p6d: List[str] = defaults["p6d"], ): ... params = _getparmeters(Foo) for k, v in params.items(): d = f"{k}d" if not k.endswith("d") else k typ = type(defaults[d]) assert isinstance(v, PARAMETERS[typ]) assert isinstance(v, typ) assert not isinstance(v, Static) assert v._ig_name == k assert v._ig_default == defaults.get(k, None)
def test_external_paramvalue_check(mocker): node = mocker.sentinel.NODE class Foo(ExternalResource): def __init__(self, *, bar: int): ... err = "argument 'bar' is not a number" with pytest.raises(TypeError, match=err): Foo(_ig_node=node, bar=String()) err = "missing 1 required keyword-only argument: 'bar'" with pytest.raises(TypeError, match=err): Foo(_ig_node=node)
def test_string_format_check(): with pytest.raises(TypeError, match="formatting string is not a static string"): String().format() with pytest.raises(TypeError, match="field conversion is not supported"): String("{!r}").format(String()) with pytest.raises(TypeError, match="format specification is not supported"): String("{:>3}").format(String()) with pytest.raises(ValueError, match="cannot switch from manual field"): String("{0} {}").format(String())
"value is not a valid list", ), ( "list[native]_empty", NativeResourceList, [], "value is not a valid native resource list", ), ( "list[native]_ext", NativeResourceList, lambda node: [_EXTERNAL(_ig_node=node)], "value is not a valid native resource list", ), ("map_key", Map, { String(): Number() }, "value is not a static map"), ( "map_value_native", Map, lambda node: ({ String(""): _NATIVE(_ig_node=node) }), "value is not a static map", ), ( "map_value_ext", Map, lambda node: ({ String(""): _EXTERNAL(_ig_node=node) }),
def __init__(self, *, bar: List[str] = LISTS[String]([String()])): ...
def __init__(self, *, bar: str = String()): ...
def __init__(self): self.bar = String("foo")
def test_split(target): res = Split(target, String("-")) assert isinstance(res, Split) assert isinstance(res, LISTS[String]) assert not isinstance(res, Static)
def test_split_check(): with pytest.raises(TypeError, match="target is not a string"): Split(Number(), String("-")) with pytest.raises(TypeError, match="separator is not a static string"): Split(String(), String())
def test_string_join_check(): with pytest.raises(TypeError): String().join(LISTS[String]())
def test_sub(): res = Sub(String("foo"), Map({})) assert isinstance(res, Sub) assert isinstance(res, String) assert not isinstance(res, Static)
def test_string_join(items): res = String("baz").join(items) assert isinstance(res, String) assert isinstance(res, Join) assert not isinstance(res, Static)
def test_join(items): res = Join(items, String("-")) assert isinstance(res, Join) assert isinstance(res, String) assert not isinstance(res, Static)
def test_join_check(): with pytest.raises(TypeError, match="items are not a list of strings"): Join(LISTS[Boolean](), String("-")) with pytest.raises(TypeError, match="separator is not a static string"): Join(LISTS[String](), String())
def test_string_replace(target): res = target.replace(String("-"), String("+")) assert isinstance(res, String) assert isinstance(res, Join) assert not isinstance(res, Static)
def test_string_split_check(target): with pytest.raises(TypeError, match="separator is not a static string"): target.split(String())