Example #1
0
    def test_user_defined_types(self):
        assert not is_listy(Model({}, 'test'))

        class AlwaysEmptySequence(Sequence):
            def __len__(self): return 0
            def __getitem__(self, i): return [][i]

        assert is_listy(AlwaysEmptySequence())

        class AlwaysEmptySet(Set):
            def __len__(self): return 0
            def __iter__(self): return iter([])
            def __contains__(self, x): return False

        assert is_listy(AlwaysEmptySet())
Example #2
0
 def test_sized_builtin(self):
     sized = [(), (1,), [], [1], set(), set([1]), frozenset(), frozenset([1]),
              bytearray(), bytearray(1)]
     if six.PY2:
         sized.extend([xrange(0), xrange(2), buffer(''), buffer('x')])
     for x in sized:
         assert is_listy(x)
Example #3
0
 def __getattr__(self, method):
     from sideboard.lib import is_listy
     assert self.name in self.services, '{} is not registered as a service'.format(self.name)
     service = self.services[self.name]
     assert not is_listy(getattr(service, '__all__', None)) or method in service.__all__, 'unable to call non-whitelisted method {}.{}'.format(self.name, method)
     func = service.make_caller('{}.{}'.format(self.name, method)) if isinstance(service, WebSocket) else getattr(service, method, None)
     assert func and hasattr(func, '__call__') and not method.startswith('_'), 'no such method {}.{}'.format(self.name, method)
     return func
Example #4
0
 def test_sized_builtin(self):
     sized = [(), (1, ), [], [1],
              set(),
              set([1]),
              frozenset(),
              frozenset([1]),
              bytearray(),
              bytearray(1)]
     if six.PY2:
         sized.extend([xrange(0), xrange(2), buffer(''), buffer('x')])
     for x in sized:
         assert is_listy(x)
Example #5
0
    def test_user_defined_types(self):
        assert not is_listy(Model({}, 'test'))

        class AlwaysEmptySequence(Sequence):
            def __len__(self):
                return 0

            def __getitem__(self, i):
                return [][i]

        assert is_listy(AlwaysEmptySequence())

        class AlwaysEmptySet(Set):
            def __len__(self):
                return 0

            def __iter__(self):
                return iter([])

            def __contains__(self, x):
                return False

        assert is_listy(AlwaysEmptySet())
Example #6
0
 def test_miscellaneous(self):
     class Foo(object): pass
     
     for x in [0, 1, False, True, Foo, object, object()]:
         assert not is_listy(x)
Example #7
0
 def test_unsized_builtin(self):
     assert not is_listy(iter([]))
     assert not is_listy(i for i in range(2))
Example #8
0
 def test_excluded(self):
     assert not is_listy({})
     assert not is_listy('')
     assert not is_listy(b'')
Example #9
0
    def test_miscellaneous(self):
        class Foo(object):
            pass

        for x in [0, 1, False, True, Foo, object, object()]:
            assert not is_listy(x)
Example #10
0
 def test_unsized_builtin(self):
     assert not is_listy(iter([]))
     assert not is_listy(i for i in range(2))
Example #11
0
 def test_excluded(self):
     assert not is_listy({})
     assert not is_listy('')
     assert not is_listy(b'')
Example #12
0
 def test_unsized_builtin(self):
     self.assertFalse(is_listy(iter([])))
     self.assertFalse(is_listy(i for i in range(2)))
Example #13
0
 def test_excluded(self):
     self.assertFalse(is_listy({}))
     self.assertFalse(is_listy(''))
     self.assertFalse(is_listy(b''))
Example #14
0
 def test_sized_builtin(self):
     for x in [(), (1,), [], [1], set(), set([1]), frozenset(), frozenset([1]),
               xrange(0), xrange(2), bytearray(), bytearray(1), buffer(''), buffer('x')]:
         self.assertTrue(is_listy(x))