# HG changeset patch # User Franz Glasner # Date 1642108481 -3600 # Node ID f167f8db46242b3f9e569db4749d5e441a43d3ad # Parent 429a7d5002b840c4f4eb0e3dcf7333fbd58b86b9 A unittest for the assertion, that a given default must be returned as identical object and not as copy diff -r 429a7d5002b8 -r f167f8db4624 tests/test.py --- a/tests/test.py Thu Jan 13 21:43:02 2022 +0100 +++ b/tests/test.py Thu Jan 13 22:14:41 2022 +0100 @@ -448,11 +448,37 @@ cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) self.assertEqual("999", cfg.getvar("non.existing.key", default="999")) + def test14_getvar_with_original_default(self): + # The default must be the original and not a copy + dflt = {"foo": "bar"} + cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertTrue(cfg.getvar("non.existing.key", default=dflt) is dflt) + def test15_getvar_s_with_default(self): cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) self.assertEqual("999", cfg.getvar_s("non.existing.key", default="999")) + def test15_getvar_s_with_original_default(self): + # The default must be the original and not a copy + dflt = {"foo2": "bar2"} + cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertTrue(cfg.getvar_s("non.existing.key", default=dflt) is dflt) + + def test15b_getvarl_with_original_default(self): + # The default must be the original and not a copy + dflt = {"foo2": "bar2"} + cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertTrue(cfg.getvarl((u"non", u"existing", u"key"), + default=dflt) is dflt) + + def test15c_getvarl_s_with_original_default(self): + # The default must be the original and not a copy + dflt = {"foo3": "bar3"} + cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) + self.assertTrue(cfg.getvarl_s((u"non", u"existing", u"key4"), + default=dflt) is dflt) + def test16_getintvar_s_with_default(self): cfg = self._load(os.path.join(TESTDATADIR, "conf20.yml")) self.assertEqual(9999, cfg.getintvar_s("non.existing.key",