comparison tests/test.py @ 467:9fcdc42a0457

len-support for jailed configurations: implement a proper __len__() method
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 15 Dec 2021 22:59:05 +0100
parents 5de1a6f213a5
children 5a88c514d4e0
comparison
equal deleted inserted replaced
466:32e228696a63 467:9fcdc42a0457
1736 1736
1737 def test_boolean_context_list_false(self): 1737 def test_boolean_context_list_false(self):
1738 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) 1738 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1739 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key7")) 1739 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key7"))
1740 self.assertFalse(jcfg) 1740 self.assertFalse(jcfg)
1741 self.assertEqual(0, len(jcfg))
1741 1742
1742 def test_boolean_context_list_true(self): 1743 def test_boolean_context_list_true(self):
1743 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) 1744 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1744 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key8")) 1745 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key8"))
1745 self.assertTrue(jcfg) 1746 self.assertTrue(jcfg)
1747 self.assertEqual(3, len(jcfg))
1746 1748
1747 def test_boolean_context_dict_false(self): 1749 def test_boolean_context_dict_false(self):
1748 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) 1750 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1749 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key9")) 1751 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key9"))
1750 self.assertFalse(jcfg) 1752 self.assertFalse(jcfg)
1753 self.assertEqual(0, len(jcfg))
1751 1754
1752 def test_boolean_context_dict_true(self): 1755 def test_boolean_context_dict_true(self):
1753 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) 1756 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1754 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2")) 1757 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2"))
1755 self.assertTrue(jcfg) 1758 self.assertTrue(jcfg)
1759 self.assertEqual(6, len(jcfg))
1756 1760
1757 def test_list_by_index(self): 1761 def test_list_by_index(self):
1758 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) 1762 cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py"))
1759 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key8")) 1763 jcfg = cfg.jailed(rootpath=(u"tree1", u"tree2", u"key8"))
1760 self.assertEqual(u"val1", jcfg[0]) 1764 self.assertEqual(u"val1", jcfg[0])