Exemple #1
0
    def test_attr_passthrough(self):
        class AConfig(Config):
            first_name: str = Option(default='Foo')

        class BConfig(Config):
            last_name: str = Option(default='Bar')

        with self.subTest('default'):
            self.assertEqual(
                ChainConfig(AConfig(), BConfig()).last_name, 'Bar')

        with self.subTest('set'):
            self.assertEqual(
                ChainConfig(AConfig(), BConfig(last_name='Baz')).last_name,
                'Baz')
Exemple #2
0
    def test_take_first_value(self):
        class MyConfig(Config):
            name: str = Option(default='Foo')

        self.assertEqual(
            ChainConfig(MyConfig({'name': 'Bar'}),
                        MyConfig({'name': 'Baz'})).name, 'Bar')
Exemple #3
0
    def test_attr_passthrough_ignores_invalid_default(self):
        class AConfig(Config):
            first_name: str = Option()

        class BConfig(Config):
            first_name: str = Option(default='Bar')

        self.assertEqual(ChainConfig(AConfig(), BConfig()).first_name, 'Bar')
Exemple #4
0
    def test_take_first_default(self):
        class AConfig(Config):
            name: str = Option(default='Foo')

        class BConfig(Config):
            name: str = Option(default='Bar')

        self.assertEqual(ChainConfig(AConfig(), BConfig()).name, 'Foo')
Exemple #5
0
    def test_invalid_default(self):
        class AConfig(Config):
            name: str = Option()

        class BConfig(Config):
            name: str = Option()

        with self.assertRaises(AttributeError):
            ChainConfig(AConfig(), BConfig()).name
Exemple #6
0
    def test_attr_passthrough_ignores_dictvalues(self):
        class AConfig(Config):
            first_name: str = Option(default='Foo')

        class BConfig(Config):
            last_name: str = Option(default='Bar')

        self.assertEqual(
            ChainConfig(AConfig(last_name='quux'),
                        BConfig(last_name='Baz')).last_name, 'Baz')
Exemple #7
0
    def test_attr_passthrough_ignores_attribute_error(self):
        class AConfig(Config):
            first_name: str = Option()

        class BConfig(Config):
            last_name: str = Option()

        class CConfig(Config):
            first_name: str = Option(default='Bar')

        self.assertEqual(
            ChainConfig(AConfig(), BConfig(), CConfig()).first_name, 'Bar')
Exemple #8
0
    def test_invalid_attr(self):
        class MyConfig(Config):
            name: str = Option(default='Foo')

        with self.assertRaises(AttributeError):
            ChainConfig(MyConfig()).last_name
Exemple #9
0
    def test_ignore_default(self):
        class MyConfig(Config):
            name: str = Option(default='Foo')

        self.assertEqual(
            ChainConfig(MyConfig(), MyConfig({'name': 'Baz'})).name, 'Baz')