Example #1
0
    def test_011_add_none(self):
        r = SubclassRegistry()

        r.add('jsoner.tests.test_registry.DummyObject', None)

        self.assertEqual(r.get('jsoner.tests.test_registry.DummyObject2'),
                         None)
Example #2
0
    def test_000_get_subclass_of_class(self):
        class A:
            pass

        class B(A):
            pass

        r = SubclassRegistry()
        r.add(A, 42)

        self.assertEqual(r.get(A), 42)
        self.assertEqual(r.get(B), 42)
Example #3
0
    def test_001_get_subclass_of_object(self):
        class A:
            pass

        class B(A):
            pass

        r = SubclassRegistry()
        r.add(A, 42)

        a = A()
        b = B()

        self.assertEqual(r.get(a), 42)
        self.assertEqual(r.get(b), 42)
Example #4
0
    def test_015_contains(self):
        r = SubclassRegistry()

        self.assertNotIn(DummyObject2, r)
Example #5
0
    def test_014_contains(self):
        r = SubclassRegistry()

        r.add(DummyObject, 42)

        self.assertIn(DummyObject2, r)
Example #6
0
    def test_012_contains(self):
        r = SubclassRegistry()

        r.add('jsoner.tests.test_registry.DummyObject', None)

        self.assertIn('jsoner.tests.test_registry.DummyObject', r)
Example #7
0
    def test_009_load_from_str(self):
        r = SubclassRegistry()

        r.add('jsoner.tests.test_registry.DummyObject', 42)

        self.assertEqual(r.get('jsoner.tests.test_registry.DummyObject2'), 42)
Example #8
0
    def test_010_add_none(self):
        r = SubclassRegistry()

        r.add('foo', None)

        self.assertEqual(r.get('foo'), None)
Example #9
0
    def test_007_add_integer_as_key(self):
        r = SubclassRegistry()
        r.add(42, 'foo')

        self.assertEqual(r.get(42), 'foo')
        self.assertIsNone(r.get(DummyObject))
Example #10
0
    def test_008_pass_list(self):
        r = SubclassRegistry()

        self.assertEqual(r.get((1, 2, 3)), None)
        self.assertIsNone(r.get(DummyObject))
Example #11
0
    def test_006_not_existing_module(self):
        r = SubclassRegistry()
        r.add('foo.bar', 42)

        self.assertEqual(r.get('foo.bar'), 42)
        self.assertIsNone(r.get(DummyObject))
Example #12
0
    def test_005_register_normal_string(self):
        r = SubclassRegistry()

        self.assertEqual(r.get('abc'), None)
Example #13
0
    def test_004_register_normal_string(self):
        r = SubclassRegistry()
        r.add('abc', 42)

        self.assertEqual(r.get('abc'), 42)
Example #14
0
    def test_003_register_as_type_and_get_as_string(self):
        r = SubclassRegistry()
        r.add(DummyObject, 42)

        self.assertEqual(r.get('jsoner.tests.test_registry.DummyObject'), 42)
Example #15
0
    def test_002_register_as_string(self):
        r = SubclassRegistry()
        r.add('jsoner.tests.test_registry.DummyObject', 42)

        self.assertEqual(r.get(DummyObject), 42)