def test_generate_stub_no_class_name(self): schema = Schema() schema.x = VirtualField(lambda x: None) schema.y = StringField() with pytest.raises(TypeError): generate_stub(schema)
def test_generate_stub_schema(self): schema = Schema() schema.x = VirtualField(lambda x: None) schema.y = StringField() stub = generate_stub(schema, 'Thing').split('\n') assert 'class Thing(cincoconfig.config.ConfigType):' in stub assert ' x: typing.Any' in stub assert ' y: str' in stub assert ' def __init__(self, y: str): ...' in stub
def test_generate_stub_instance_methods(self): def meth1(thing, x: int) -> None: pass def meth2(thing, y: str) -> int: pass schema = Schema() schema.instance_method('hello')(meth1) schema.instance_method('goodbye')(meth2) stub = generate_stub(schema, 'Thing').split('\n') assert ' def hello(self, x: int) -> None: ...' in stub assert ' def goodbye(self, y: str) -> int: ...' in stub
def test_generate_stub_invalid_type(self): with pytest.raises(TypeError): generate_stub(100, 'asdf')