Пример #1
0
  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'],
                          ]))
Пример #2
0
  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'],
                          ]))
Пример #3
0
  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'],
                          ]))
Пример #4
0
    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'],
            ]))
Пример #5
0
    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'],
            ]))
Пример #6
0
    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'],
            ]))
Пример #7
0
#!/usr/bin/env python
#
# Copyright 2010 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

"""Client library for tunes_db service."""

import os

from protorpc import definition

definition.import_file_set(os.path.join(os.path.dirname(__file__),
                                        'music_service.descriptor'))