def test_include_as_disabled(tmpdir): loader = Loader() tmpdir.join('a.thrift').write('include t "./b.thrift"') tmpdir.join('b.thrift').write('typedef string UUID') with pytest.raises(ThriftCompilerError) as exc_info: loader.load(str(tmpdir.join('a.thrift'))) assert 'Cannot include "b" as "t"' in str(exc_info) assert '"include-as" syntax is currently disabled' in str(exc_info)
def test_caching(tmpdir, monkeypatch): tmpdir.join('my_service.thrift').write(''' struct Foo { 1: required string a 2: optional string b } ''') path = str(tmpdir.join('my_service.thrift')) loader = Loader() mod1 = loader.load(path) assert path in loader.compiled_modules mod2 = loader.load(path) assert mod1 is mod2 mod3 = loader.load(path, force=True) assert mod3 is not mod2
def test_load_from_file_non_strict_missing_requiredness(tmpdir): tmpdir.join('my_service.thrift').write(''' struct Foo { 1: required string a 2: string b } ''') loader = Loader(strict=False) my_service = loader.load(str(tmpdir.join('my_service.thrift'))) my_service.Foo(b='b', a='a')
def test_caching(tmpdir, monkeypatch): tmpdir.join('my_service.thrift').write(''' struct Foo { 1: required string a 2: optional string b } ''') path = str(tmpdir.join('my_service.thrift')) loader = Loader() mod1 = loader.load(path) mod2 = loader.load(path) assert mod1 is mod2
def test_load_from_file_non_strict_missing_requiredness(tmpdir): tmpdir.join('my_service.thrift').write(''' struct Foo { 1: required string a 2: string b } exception Bar { 1: string message } ''') loader = Loader(strict=False) m = loader.load(str(tmpdir.join('my_service.thrift'))) m.Foo(b='b', a='a') m.Bar(message='foo') m.Bar()