def testImportBuiltInProtorpcClasses(self): """Test that built in Protorpc classes are skipped.""" file_set = descriptor.FileSet() file_set.files = [ self.MakeFileDescriptor(u'standalone'), self.MakeFileDescriptor(u'root.nested'), self.MakeFileDescriptor(u'root.nested.nested'), descriptor.describe_file(descriptor), ] root = types.ModuleType('root') nested = types.ModuleType('root.nested') root.nested = nested modules = { 'root': root, 'root.nested': nested, 'protorpc.descriptor': descriptor, } definition.import_file_set(file_set, modules=modules) self.assertEquals(root, modules['root']) self.assertEquals(nested, modules['root.nested']) self.assertEquals(nested.nested, modules['root.nested.nested']) self.assertEquals(descriptor, modules['protorpc.descriptor']) self.assertEquals( file_set, descriptor.describe_file_set([ modules['standalone'], modules['root.nested'], modules['root.nested.nested'], modules['protorpc.descriptor'], ]))
def testImportFileSetFromFile(self): """Test importing a whole file set from a file.""" file_set = descriptor.FileSet() file_set.files = [ self.MakeFileDescriptor(u'standalone'), self.MakeFileDescriptor(u'root.nested'), self.MakeFileDescriptor(u'root.nested.nested'), ] stream = StringIO.StringIO(protobuf.encode_message(file_set)) self.mox = mox.Mox() opener = self.mox.CreateMockAnything() opener('my-file.dat', 'rb').AndReturn(stream) self.mox.ReplayAll() modules = {} definition.import_file_set('my-file.dat', modules=modules, _open=opener) self.assertEquals( file_set, descriptor.describe_file_set([ modules['standalone'], modules['root.nested'], modules['root.nested.nested'], ]))
def testImportFileSet(self): """Test importing a whole file set.""" file_set = descriptor.FileSet() file_set.files = [ self.MakeFileDescriptor(u'standalone'), self.MakeFileDescriptor(u'root.nested'), self.MakeFileDescriptor(u'root.nested.nested'), ] root = types.ModuleType('root') nested = types.ModuleType('root.nested') root.nested = nested modules = { 'root': root, 'root.nested': nested, } definition.import_file_set(file_set, modules=modules) self.assertEquals(root, modules['root']) self.assertEquals(nested, modules['root.nested']) self.assertEquals(nested.nested, modules['root.nested.nested']) self.assertEquals( file_set, descriptor.describe_file_set([ modules['standalone'], modules['root.nested'], modules['root.nested.nested'], ]))
def testWithModules(self): """Test what happens when no modules provided.""" modules = [types.ModuleType('package1'), types.ModuleType('package1')] file1 = descriptor.FileDescriptor() file1.package = 'package1' file2 = descriptor.FileDescriptor() file2.package = 'package2' expected = descriptor.FileSet() expected.files = [file1, file1] described = descriptor.describe_file_set(modules) described.check_initialized() self.assertEquals(expected, described)
def testGetFileSet_None(self): request = registry.GetFileSetRequest() response = self.registry_service.get_file_set(request) self.assertEquals(descriptor.FileSet(), response.file_set)
def testNoModules(self): """Test what happens when no modules provided.""" described = descriptor.describe_file_set([]) described.check_initialized() # The described FileSet.files will be None. self.assertEquals(descriptor.FileSet(), described)