def test_filename(self): package = Package('test') module = Module('service.module') module.package = package generator = PythonGenerator('/tmp') filename = generator._filename(module) assert filename == 'test/service/module/protocol.py'
def test_render_interface(self): exc = Message('Exception', is_exception=True) iface = Interface('Interface', exc=exc) iface.create_method('method0', NativeType.INT32, [('arg', NativeType.INT32)]) iface.create_method('method1', NativeType.STRING, [('name', NativeType.STRING)]) generator = PythonGenerator('/dev/null') code = generator._render_definition(iface) assert code
def test_render_enum(self): enum = Enum('Number') enum.create_value('ONE') enum.create_value('TWO') enum.create_value('THREE') module = Module('test', definitions=[enum]) module.link() generator = PythonGenerator('/dev/null') code = generator._render_definition(enum) assert code
def test_init_modules(self): module_names = [ 'service.server', 'service.client', 'service.client.submodule', 'service2.server', 'service3' ] generator = PythonGenerator('/tmp') parent_names = generator._init_modules(module_names) assert parent_names == {'service', 'service.client', 'service2'}
def test_render_message(self): enum = Enum('Type') type0 = enum.create_value('MESSAGE') base = Message('Base') base.create_field('type', enum, is_discriminator=True) msg = Message('Message', base=base, discriminator_value=type0) msg.create_field('field', NativeType.BOOL) generator = PythonGenerator('/dev/null') code = generator._render_definition(msg) assert code
def test_render_module(self): msg = Message('Message') iface = Interface('Interface') enum = Enum('Enum') imported = Module('imported.module') module = Module('test', definitions=[msg, iface, enum]) module.add_imported_module(imported) module.link() generator = PythonGenerator('/dev/null') code = generator._render_module(module) assert code
def test_filename__init_file(self): generator = PythonGenerator('/tmp') filename = generator._filename('test.service.module', is_init_module=True) assert filename == '/tmp/test/service/module/__init__.py'
def test_filename(self): generator = PythonGenerator('/tmp') filename = generator._filename('test.service.module') assert filename == '/tmp/test/service/module.py'