comparison tests/test.py @ 723:c17a4e30ebbf

Docs for nested filters
author Franz Glasner <f.glasner@feldmann-mg.com>
date Wed, 16 Aug 2023 17:04:14 +0200
parents 6d9552eb7e4d
children ef7bee8b54e1
comparison
equal deleted inserted replaced
722:ea1a6beadc6c 723:c17a4e30ebbf
2416 self.assertRaises( 2416 self.assertRaises(
2417 KeyError, 2417 KeyError,
2418 cfg.getvar, 2418 cfg.getvar,
2419 u("intl.cache")) 2419 u("intl.cache"))
2420 2420
2421 def test_global_filter_wrong_syntax(self): 2421 def test_nested_filter_wrong_syntax(self):
2422 cfg = configmix.load() 2422 cfg = configmix.load()
2423 try: 2423 try:
2424 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|None}}") 2424 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|None}}")
2425 except ValueError: 2425 except ValueError:
2426 pass 2426 pass
2427 else: 2427 else:
2428 self.fail("`ValueError' should have been raised") 2428 self.fail("`ValueError' should have been raised")
2429 2429
2430 def test_global_filter_None(self): 2430 def test_nested_filter_None(self):
2431 cfg = configmix.load() 2431 cfg = configmix.load()
2432 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|None|}}") 2432 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|None|}}")
2433 self.assertTrue(y is None) 2433 self.assertTrue(y is None)
2434 2434
2435 def test_global_filter_empty(self): 2435 def test_nested_filter_empty(self):
2436 cfg = configmix.load() 2436 cfg = configmix.load()
2437 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|Empty|}}") 2437 y = getattr(cfg, self.interpolate_meth)(u"{{|{{not-existing}}|Empty|}}")
2438 self.assertEqual(u(""), y) 2438 self.assertEqual(u(""), y)
2439 2439
2440 def test_global_nested_filter_empty(self): 2440 def test_nested_nested_filter_empty(self):
2441 cfg = configmix.load() 2441 cfg = configmix.load()
2442 y = getattr(cfg, self.interpolate_meth)(u"{{|pre-{{not-existing|Empty}}-post|upper|}}") 2442 y = getattr(cfg, self.interpolate_meth)(u"{{|pre-{{not-existing|Empty}}-post|upper|}}")
2443 self.assertEqual(u("PRE--POST"), y) 2443 self.assertEqual(u("PRE--POST"), y)
2444 2444
2445 def test_global_filter_upper(self): 2445 def test_nested_filter_upper(self):
2446 cfg1 = { 2446 cfg1 = {
2447 u("key-1"): u("Value for key-1") 2447 u("key-1"): u("Value for key-1")
2448 } 2448 }
2449 cfg = cfg = configmix.config.Configuration(cfg1) 2449 cfg = cfg = configmix.config.Configuration(cfg1)
2450 y = getattr(cfg, self.interpolate_meth)(u"{{|pre_{{key-1}}_post|upper|}}") 2450 y = getattr(cfg, self.interpolate_meth)(u"{{|pre_{{key-1}}_post|upper|}}")
2451 self.assertEqual(u("PRE_VALUE FOR KEY-1_POST"), y) 2451 self.assertEqual(u("PRE_VALUE FOR KEY-1_POST"), y)
2452 2452
2453 def test_global_filter_normpath(self): 2453 def test_nested_filter_normpath(self):
2454 cfg1 = { 2454 cfg1 = {
2455 u("path1"): u("a\\b\\c"), 2455 u("path1"): u("a\\b\\c"),
2456 u("path2"): u("{{|{{path1}}/../d|normpath|}}") 2456 u("path2"): u("{{|{{path1}}/../d|normpath|}}")
2457 } 2457 }
2458 cfg = cfg = configmix.config.Configuration(cfg1) 2458 cfg = cfg = configmix.config.Configuration(cfg1)