예제 #1
0
파일: tests.py 프로젝트: leipzig/avocado
class RegistryTestCase(TestCase):
    def setUp(self):
        class A(object): pass
        class B(object): pass
        self.A = A
        self.B = B
        self.r = Registry(register_instance=False)

    def test_register(self):
        self.r.register(self.B)
        self.r.register(self.A)
        self.assertEqual(self.r.choices, [('A', 'A'), ('B', 'B')])

    def test_unregister(self):
        self.r.register(self.A)
        self.assertEqual(self.r.choices, [('A', 'A')])
        self.r.unregister(self.A)
        self.assertEqual(self.r.choices, [])

    def test_already(self):
        self.r.register(self.A)
        self.assertRaises(AlreadyRegistered, self.r.register, self.A)

    def test_default(self):
        class C(object): pass
        C.default = True
        self.r.register(C)
        self.assertEqual(self.r['foo'], C)

        class D(object): pass
        D.default = True
        self.assertRaises(ImproperlyConfigured, self.r.register, D)
예제 #2
0
    def setUp(self):
        class A(object):
            pass

        class B(object):
            pass

        self.A = A
        self.B = B
        self.r = Registry(register_instance=False)
예제 #3
0
 def setUp(self):
     self.r = Registry(register_instance=False)
예제 #4
0
class RegistryTestCase(TestCase):
    def setUp(self):
        self.r = Registry(register_instance=False)

    def test_register(self):
        self.r.register(B)
        self.r.register(A)
        self.assertEqual(self.r.choices, [('A', 'A'), ('B', 'B')])

    def test_unregister(self):
        self.r.register(A)
        self.assertEqual(self.r.choices, [('A', 'A')])
        self.r.unregister(A)
        self.assertEqual(self.r.choices, [])

    def test_already(self):
        self.r.register(A)
        self.assertRaises(AlreadyRegistered, self.r.register, A)

    def test_default(self):
        self.r.register(C, default=True)
        self.assertEqual(self.r['Default'], C)

        self.r.register(D, default=True)
        self.assertEqual(self.r['Default'], D)

    def test_decorator(self):
        @self.r.register
        class E(object):
            pass

        self.assertEqual(self.r.choices, [('E', 'E')])

    def test_decorator_arguments(self):
        @self.r.register('F Class', default=True)
        class F(object):
            pass

        self.assertEqual(self.r.choices, [('F Class', 'F Class')])
        self.assertEqual(self.r.default, F)