Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 448:b95c12781497
Attribute-style access for jailed configurations
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 11 Dec 2021 19:56:35 +0100 |
| parents | 94cf5a8722d6 |
| children | d6be95841380 |
comparison
equal
deleted
inserted
replaced
| 447:4505ef8a1b56 | 448:b95c12781497 |
|---|---|
| 1678 u"the default", | 1678 u"the default", |
| 1679 jcfg.get([u"no", u"key"], default=u"the default")) | 1679 jcfg.get([u"no", u"key"], default=u"the default")) |
| 1680 self.assertTrue( | 1680 self.assertTrue( |
| 1681 jcfg.get([u"no", u"key"]) is None) | 1681 jcfg.get([u"no", u"key"]) is None) |
| 1682 | 1682 |
| 1683 def test_attribute_access(self): | |
| 1684 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) | |
| 1685 jcfg = cfg.jailed(rootpath=(u"tree1",)) | |
| 1686 | |
| 1687 self.assertEqual(0x20, jcfg.key3) | |
| 1688 self.assertEqual(u"off", jcfg.tree2.key6) | |
| 1689 | |
| 1690 def test_attribute_access_non_existing(self): | |
| 1691 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) | |
| 1692 jcfg = cfg.jailed(rootpath=(u"tree1",)) | |
| 1693 | |
| 1694 try: | |
| 1695 jcfg.non_existing | |
| 1696 except AttributeError: | |
| 1697 pass | |
| 1698 else: | |
| 1699 self.fail("AttributeError expected") | |
| 1700 | |
| 1701 try: | |
| 1702 jcfg.tree2.non_existing | |
| 1703 except AttributeError: | |
| 1704 pass | |
| 1705 else: | |
| 1706 self.fail("AttributeError expected") | |
| 1707 | |
| 1683 | 1708 |
| 1684 if __name__ == "__main__": | 1709 if __name__ == "__main__": |
| 1685 unittest.main() | 1710 unittest.main() |
