示例#1
0
class CollectionProxyTestCase(TestCase):
    @setup
    def setup_proxy(self):
        self.target_list = [DummyTarget(1), DummyTarget(2), DummyTarget(0)]
        self.proxy = CollectionProxy(
            lambda: self.target_list,
            [
                ('foo', any, True),
                ('not_foo', all, False),
                ('equals', lambda a: list(a), True),
            ],
        )
        self.dummy = DummyObject(self.proxy)

    def test_add(self):
        self.proxy.add('foo', any, True)
        assert_equal(self.proxy._defs['foo'], (any, True))

    def test_perform(self):
        assert self.dummy.foo()
        assert not self.dummy.not_foo

    def test_perform_not_defined(self):
        assert_raises(AttributeError, self.dummy.proxy.perform, 'bar')

    def test_perform_with_params(self):
        assert_equal(self.proxy.perform('equals')(2), [False, True, False])
        sometimes = ['sometimes'] * 3
        assert_equal(
            self.proxy.perform('equals')(3, sometimes=True),
            sometimes,
        )
示例#2
0
文件: proxy_test.py 项目: Bklyn/Tron
class CollectionProxyTestCase(TestCase):

    @setup
    def setup_proxy(self):
        self.target_list = [DummyTarget(1), DummyTarget(2), DummyTarget(0)]
        self.proxy = CollectionProxy(lambda: self.target_list, [
            ('foo', any, True),
            ('not_foo', all, False),
            ('equals', lambda a: list(a), True)
        ])
        self.dummy = DummyObject(self.proxy)

    def test_add(self):
        self.proxy.add('foo', any, True)
        assert_equal(self.proxy._defs['foo'], (any, True))

    def test_perform(self):
        assert self.dummy.foo()
        assert not self.dummy.not_foo

    def test_perform_not_defined(self):
        assert_raises(AttributeError, self.dummy.proxy.perform, 'bar')

    def test_perform_with_params(self):
        assert_equal(self.proxy.perform('equals')(2), [False, True, False])
        sometimes = ['sometimes'] * 3
        assert_equal(self.proxy.perform('equals')(3, sometimes=True), sometimes)
示例#3
0
 def setup_proxy(self):
     self.target_list = [DummyTarget(1), DummyTarget(2), DummyTarget(0)]
     self.proxy = CollectionProxy(lambda: self.target_list,
                                  [('foo', any, True),
                                   ('not_foo', all, False),
                                   ('equals', lambda a: list(a), True)])
     self.dummy = DummyObject(self.proxy)
示例#4
0
文件: proxy_test.py 项目: Bklyn/Tron
 def setup_proxy(self):
     self.target_list = [DummyTarget(1), DummyTarget(2), DummyTarget(0)]
     self.proxy = CollectionProxy(lambda: self.target_list, [
         ('foo', any, True),
         ('not_foo', all, False),
         ('equals', lambda a: list(a), True)
     ])
     self.dummy = DummyObject(self.proxy)