Mercurial > hgrepos > Python > libs > ConfigMix
comparison tests/test.py @ 647:df58983f28a2
Allow to disable the internal caching in configmix.
Also allow to re-enable internal caching.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 11 Mar 2022 01:53:08 +0100 |
| parents | db3ff4fbb4ce |
| children | fe1299825a9a |
comparison
equal
deleted
inserted
replaced
| 646:f8cb74b447de | 647:df58983f28a2 |
|---|---|
| 437 os.path.join(TESTDATADIR, "conf22.ini"), | 437 os.path.join(TESTDATADIR, "conf22.ini"), |
| 438 os.path.join(TESTDATADIR, "conf23.json"), | 438 os.path.join(TESTDATADIR, "conf23.json"), |
| 439 os.path.join(TESTDATADIR, "conf24.toml")) | 439 os.path.join(TESTDATADIR, "conf24.toml")) |
| 440 x = cfg.interpolate_variables("{{intl.cache.items|Empty}}") | 440 x = cfg.interpolate_variables("{{intl.cache.items|Empty}}") |
| 441 self.assertEqual(10, x) | 441 self.assertEqual(10, x) |
| 442 x = cfg.interpolate_variables("{{intl.cache.items|Empty}}") | |
| 443 self.assertEqual(10, x) | |
| 444 | |
| 445 def test12a_Empty_filter_pass_through_without_cache(self): | |
| 446 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml"), | |
| 447 os.path.join(TESTDATADIR, "conf21.yml"), | |
| 448 os.path.join(TESTDATADIR, "conf22.ini"), | |
| 449 os.path.join(TESTDATADIR, "conf23.json"), | |
| 450 os.path.join(TESTDATADIR, "conf24.toml")) | |
| 451 cfg.disable_cache() | |
| 452 x = cfg.interpolate_variables("{{intl.cache.items|Empty}}") | |
| 453 self.assertEqual(10, x) | |
| 454 x = cfg.interpolate_variables("{{intl.cache.items|Empty}}") | |
| 455 self.assertEqual(10, x) | |
| 442 | 456 |
| 443 def test13_keyerror(self): | 457 def test13_keyerror(self): |
| 444 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | 458 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) |
| 459 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key") | |
| 460 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key") | |
| 461 | |
| 462 def test13a_keyerror_without_cache(self): | |
| 463 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 464 cfg.disable_cache() | |
| 465 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key") | |
| 445 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key") | 466 self.assertRaises(KeyError, cfg.getvar_s, "non.existing.key") |
| 446 | 467 |
| 447 def test14_getvar_with_default(self): | 468 def test14_getvar_with_default(self): |
| 448 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | 469 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) |
| 449 self.assertEqual("999", cfg.getvar("non.existing.key", default="999")) | 470 self.assertEqual("999", cfg.getvar("non.existing.key", default="999")) |
| 454 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | 475 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) |
| 455 self.assertTrue(cfg.getvar("non.existing.key", default=dflt) is dflt) | 476 self.assertTrue(cfg.getvar("non.existing.key", default=dflt) is dflt) |
| 456 | 477 |
| 457 def test15_getvar_s_with_default(self): | 478 def test15_getvar_s_with_default(self): |
| 458 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | 479 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) |
| 480 self.assertEqual("999", cfg.getvar_s("non.existing.key", | |
| 481 default="999")) | |
| 482 self.assertEqual("999", cfg.getvar_s("non.existing.key", | |
| 483 default="999")) | |
| 484 | |
| 485 def test15a_getvar_s_with_default_without_cache(self): | |
| 486 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 487 cfg.disable_cache() | |
| 488 self.assertEqual("999", cfg.getvar_s("non.existing.key", | |
| 489 default="999")) | |
| 459 self.assertEqual("999", cfg.getvar_s("non.existing.key", | 490 self.assertEqual("999", cfg.getvar_s("non.existing.key", |
| 460 default="999")) | 491 default="999")) |
| 461 | 492 |
| 462 def test15_getvar_s_with_original_default(self): | 493 def test15_getvar_s_with_original_default(self): |
| 463 # The default must be the original and not a copy | 494 # The default must be the original and not a copy |
| 532 | 563 |
| 533 self.assertEqual("de", cfg.getfirstvar("intl.non.existing", | 564 self.assertEqual("de", cfg.getfirstvar("intl.non.existing", |
| 534 "intl.fallback", | 565 "intl.fallback", |
| 535 default=None)) | 566 default=None)) |
| 536 | 567 |
| 568 def test20a_getfirstvar_existing_without_cache(self): | |
| 569 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 570 cfg.disable_cache() | |
| 571 self.assertEqual("test-configmix", cfg.getfirstvar("intl.domain")) | |
| 572 self.assertEqual("test-configmix", cfg.getfirstvar("intl.domain", | |
| 573 "intl.fallback")) | |
| 574 self.assertEqual("de", cfg.getfirstvar("intl.fallback", | |
| 575 "intl.domain", | |
| 576 default=None)) | |
| 577 | |
| 578 self.assertEqual("de", cfg.getfirstvar("intl.non.existing", | |
| 579 "intl.fallback", | |
| 580 default=None)) | |
| 581 | |
| 537 def test21_getfirstvar_s_existing(self): | 582 def test21_getfirstvar_s_existing(self): |
| 538 cfg = self._load( | 583 cfg = self._load( |
| 539 os.path.join(TESTDATADIR, "conf20.yml"), | 584 os.path.join(TESTDATADIR, "conf20.yml"), |
| 540 os.path.join(TESTDATADIR, "conf21.yml")) | 585 os.path.join(TESTDATADIR, "conf21.yml")) |
| 541 self.assertEqual( | 586 self.assertEqual( |
| 547 | 592 |
| 548 def test22_getfirstvar_s_non_existing(self): | 593 def test22_getfirstvar_s_non_existing(self): |
| 549 cfg = self._load( | 594 cfg = self._load( |
| 550 os.path.join(TESTDATADIR, "conf20.yml"), | 595 os.path.join(TESTDATADIR, "conf20.yml"), |
| 551 os.path.join(TESTDATADIR, "conf21.yml")) | 596 os.path.join(TESTDATADIR, "conf21.yml")) |
| 597 self.assertIsNone( | |
| 598 cfg.getfirstvar_s("intl.non.existing", "intl.non.existing2", | |
| 599 default=None)) | |
| 600 self.assertRaises( | |
| 601 KeyError, | |
| 602 cfg.getfirstvar_s, | |
| 603 "intl.non.existing", | |
| 604 "intl.non.existing2") | |
| 605 | |
| 606 def test22a_getfirstvar_s_non_existing_without_cache(self): | |
| 607 cfg = self._load( | |
| 608 os.path.join(TESTDATADIR, "conf20.yml"), | |
| 609 os.path.join(TESTDATADIR, "conf21.yml")) | |
| 610 cfg.disable_cache() | |
| 552 self.assertIsNone( | 611 self.assertIsNone( |
| 553 cfg.getfirstvar_s("intl.non.existing", "intl.non.existing2", | 612 cfg.getfirstvar_s("intl.non.existing", "intl.non.existing2", |
| 554 default=None)) | 613 default=None)) |
| 555 self.assertRaises( | 614 self.assertRaises( |
| 556 KeyError, | 615 KeyError, |
| 865 self.assertEqual([u"key1", u"key2", u"tree1"], s) | 924 self.assertEqual([u"key1", u"key2", u"tree1"], s) |
| 866 | 925 |
| 867 def test45_clear_cache(self): | 926 def test45_clear_cache(self): |
| 868 cfg = self._load(os.path.join(TESTDATADIR, "conf10.py")) | 927 cfg = self._load(os.path.join(TESTDATADIR, "conf10.py")) |
| 869 cfg.clear_cache() | 928 cfg.clear_cache() |
| 929 | |
| 930 def test46_reenable_cache(self): | |
| 931 cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) | |
| 932 self.assertTrue(cfg.getvarl() is cfg) | |
| 933 cfg.disable_cache() | |
| 934 self.assertTrue(cfg.getvarl() is cfg) | |
| 935 cfg.clear_cache() | |
| 936 self.assertTrue(cfg.getvarl() is cfg) | |
| 937 cfg.enable_cache() | |
| 938 self.assertTrue(cfg.getvarl() is cfg) | |
| 870 | 939 |
| 871 | 940 |
| 872 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): | 941 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase): |
| 873 | 942 |
| 874 def setUp(self): | 943 def setUp(self): |
