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')
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')
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')
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')
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
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')
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')
def test_invalid_attr(self): class MyConfig(Config): name: str = Option(default='Foo') with self.assertRaises(AttributeError): ChainConfig(MyConfig()).last_name
def test_ignore_default(self): class MyConfig(Config): name: str = Option(default='Foo') self.assertEqual( ChainConfig(MyConfig(), MyConfig({'name': 'Baz'})).name, 'Baz')