Example #1
0
    def table(self):
        content = [['foo', 'bar'], ['spam', 'eggs']]
        self.writer.table(content)
        self.writer.table(content, padding=2)
        self.writer.table(content, ['hello', 'wo\nrld'])
        Assert(self.stream.getvalue()) == textwrap.dedent("""\
            foo  | bar
            spam | eggs

            foo   |  bar
            spam  |  eggs

            hello | wo\\nrld
            ------+--------
            foo   | bar
            spam  | eggs

        """)
        with Assert.raises(ValueError):
            self.writer.table([])
        with Assert.raises(ValueError):
            self.writer.table([['foo', 'bar'], ['spam']])
        with Assert.raises(ValueError):
            self.writer.table([['foo', 'bar']], ['spam'])

        self.set_writer(stream=FlushStream())
        self.writer.table(content)
        Assert(len(self.stream.contents)) == 2
        Assert.isinstance(self.stream.contents[0], basestring)
        Assert(self.stream.contents[1]) == True
Example #2
0
 def type_checking(self):
     d = self.dict_class()
     types = [
         dict, ImmutableDict, MultiDict, ImmutableMultiDict, OrderedDict
     ]
     for type in types:
         Assert.isinstance(d, type), type
Example #3
0
    def table(self):
        content = [['foo', 'bar'], ['spam', 'eggs']]
        self.writer.table(content)
        self.writer.table(content, padding=2)
        self.writer.table(content, ['hello', 'wo\nrld'])
        Assert(self.stream.getvalue()) == textwrap.dedent("""\
            foo  | bar
            spam | eggs

            foo   |  bar
            spam  |  eggs

            hello | wo\\nrld
            ------+--------
            foo   | bar
            spam  | eggs

        """)
        with Assert.raises(ValueError):
            self.writer.table([])
        with Assert.raises(ValueError):
            self.writer.table([['foo', 'bar'], ['spam']])
        with Assert.raises(ValueError):
            self.writer.table([['foo', 'bar']], ['spam'])

        self.set_writer(stream=FlushStream())
        self.writer.table(content)
        Assert(len(self.stream.contents)) == 2
        Assert.isinstance(self.stream.contents[0], basestring)
        Assert(self.stream.contents[1]) == True
Example #4
0
 def get_dimensions(self):
     with Assert.raises(NotImplementedError):
         self.writer.get_dimensions()
     writer = TerminalWriter(sys.__stdout__)
     with Assert.not_raising(NotImplementedError):
         dimensions = writer.get_dimensions()
     height, width = dimensions
     Assert.isinstance(height, int)
     Assert.isinstance(width, int)
     Assert(height) == dimensions.height
     Assert(width) == dimensions.width
Example #5
0
 def get_dimensions(self):
     with Assert.raises(NotImplementedError):
         self.writer.get_dimensions()
     writer = TerminalWriter(sys.__stdout__)
     with Assert.not_raising(NotImplementedError):
         dimensions = writer.get_dimensions()
     height, width = dimensions
     Assert.isinstance(height, int)
     Assert.isinstance(width, int)
     Assert(height) == dimensions.height
     Assert(width) == dimensions.width
Example #6
0
    def type_checks_work(self):
        class Foo(object):
            __metaclass__ = ABCMeta

        class Bar(object):
            pass

        Foo.register(Bar)

        Assert.issubclass(Bar, Foo)
        Assert.isinstance(Bar(), Foo)
Example #7
0
    def type_checks_work(self):
        class Foo(object):
            __metaclass__ = ABCMeta

        class Bar(object):
            pass

        Foo.register(Bar)

        Assert.issubclass(Bar, Foo)
        Assert.isinstance(Bar(), Foo)
Example #8
0
def isinstance():
    """Assert.isinstance"""

    with Assert.raises(AssertionError) as error:
        Assert.isinstance("hello", (int, float))
    error.__str__() == "not isinstance('hello', (int, float))"

    with Assert.raises(AssertionError) as error:
        Assert.isinstance("hello", int)
    error.__str__() == "not isinstance('hello', int)"

    Assert.isinstance("hello", basestring)
Example #9
0
def test_virtual_subclass_meta():
    from abc import ABCMeta

    class Foo(object):
        __metaclass__ = ABCMeta

    class Bar(object):
        __metaclass__ = ABCMeta

    class Simple(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Foo, Bar]

    class InheritingSimple(Simple):
        pass

    for a, b in product([Simple, InheritingSimple], [Foo, Bar]):
        Assert.issubclass(a, b)
        Assert.isinstance(a(), b)

    Assert.issubclass(InheritingSimple, Simple)
    Assert.isinstance(InheritingSimple(), Simple)

    class Spam(object):
        __metaclass__ = ABCMeta

    class Eggs(object):
        __metaclass__ = ABCMeta

    class SimpleMonty(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Spam, Eggs]

    class MultiInheritance(Simple, SimpleMonty):
        pass

    class MultiVirtualInheritance(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Simple, SimpleMonty]

    for virtual_super_cls in [Foo, Bar, Simple, Spam, Eggs, SimpleMonty]:
        Assert.issubclass(MultiInheritance, virtual_super_cls)
        Assert.isinstance(MultiInheritance(), virtual_super_cls)
Example #10
0
def test_virtual_subclass_meta():
    from abc import ABCMeta

    class Foo(object):
        __metaclass__ = ABCMeta

    class Bar(object):
        __metaclass__ = ABCMeta

    class Simple(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Foo, Bar]

    class InheritingSimple(Simple):
        pass

    for a, b in product([Simple, InheritingSimple], [Foo, Bar]):
        Assert.issubclass(a, b)
        Assert.isinstance(a(), b)

    Assert.issubclass(InheritingSimple, Simple)
    Assert.isinstance(InheritingSimple(), Simple)

    class Spam(object):
        __metaclass__ = ABCMeta

    class Eggs(object):
        __metaclass__ = ABCMeta

    class SimpleMonty(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Spam, Eggs]

    class MultiInheritance(Simple, SimpleMonty):
        pass

    class MultiVirtualInheritance(object):
        __metaclass__ = VirtualSubclassMeta
        virtual_superclasses = [Simple, SimpleMonty]

    for virtual_super_cls in [Foo, Bar, Simple, Spam, Eggs, SimpleMonty]:
        Assert.issubclass(MultiInheritance, virtual_super_cls)
        Assert.isinstance(MultiInheritance(), virtual_super_cls)
Example #11
0
 def type_checking(self):
     Assert.isinstance(self.dict_class(), dict)
Example #12
0
def basic_creation():
    q = quantum.now()

    Assert(q.tz) == None
    Assert.isinstance(q.as_utc(), datetime)
    with Assert.raises(quantum.QuantumException):
        Assert.isinstance(q.as_local(), datetime)

    q = quantum.parse('2013-06-27T12:27:54', timezone='UTC')

    Assert(q.tz) == pytz.utc
    Assert.isinstance(q.as_utc(), datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 27, 12, 27, 54)
    Assert(q.as_local()) == datetime(2013, 6, 27, 12, 27, 54)

    q = quantum.parse('2013-06-27T12:27:54', timezone='Pacific/Auckland')

    Assert(q.tz) == pytz.timezone('Pacific/Auckland')
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 27, 0, 27, 54)
    Assert(q.as_local()) == datetime(2013, 6, 27, 12, 27, 54)

    q = quantum.parse('2013-06-26 3:27pm', timezone='UTC', relaxed=True)

    Assert(q.tz) == pytz.utc
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 26, 15, 27, 0)
    Assert(q.as_local()) == datetime(2013, 6, 26, 15, 27, 0)

    q = quantum.parse('2013-06-26 3:27pm', relaxed=True, timezone='Pacific/Auckland')

    Assert(q.tz) == pytz.timezone('Pacific/Auckland')
    Assert.isinstance(q.dt, datetime)
    Assert(q.as_utc()) == datetime(2013, 6, 26, 3, 27, 0)
    Assert(q.as_local()) == datetime(2013, 6, 26, 15, 27, 0)
Example #13
0
 def type_checking(self):
     d = self.dict_class()
     types = [dict, ImmutableDict, MultiDict, ImmutableMultiDict,
              OrderedDict]
     for type in types:
         Assert.isinstance(d, type), type
Example #14
0
 def type_checking(self):
     d = self.dict_class()
     Assert.isinstance(d, OrderedDict)
     Assert.isinstance(d, ImmutableDict)
     Assert.isinstance(d, dict)
Example #15
0
 def type_checking(self):
     d = self.dict_class()
     Assert.isinstance(d, dict)
Example #16
0
 def type_checking(self):
     Assert.isinstance(self.dict_class(), dict)
Example #17
0
 def type_checking(self):
     d = self.dict_class()
     Assert.isinstance(d, dict)
Example #18
0
def initialization(instance, L):
    Assert.isinstance(instance, roadmap.Router)
Example #19
0
 def type_checking(self):
     d = self.dict_class()
     Assert.isinstance(d, OrderedDict)
     Assert.isinstance(d, ImmutableDict)
     Assert.isinstance(d, dict)