Ejemplo n.º 1
0
    def test_dd_no_extra_calls(self):
        def bad():
            raise ValueError("shouldn't call me")

        def good():
            return 'good results'

        dd = DynamicDictLookup()
        dd['bad'] = bad
        dd['good'] = good

        ok = "string with just the {good} reference"
        # format forces __get_item__ on all key/values by default
        with pytest.raises(ValueError):
            ok.format(**dd)

        # using minimal_subdict, should fly
        assert 'good results' in ok.format(**dd.minimal_subdict(ok))
    def test_dd_no_extra_calls(self):
        def bad():
            raise ValueError("shouldn't call me")

        def good():
            return 'good results'

        dd = DynamicDictLookup()
        dd['bad'] = bad
        dd['good'] = good

        ok = "string with just the {good} reference"
        # format forces __get_item__ on all key/values by default
        with pytest.raises(ValueError):
            ok.format(**dd)

        # using minimal_subdict, should fly
        assert 'good results' in ok.format(**dd.minimal_subdict(ok))
Ejemplo n.º 3
0
    def test_dd(self):
        def f():
            return 'zzz'

        dd = DynamicDictLookup()
        dd['a'] = f
        dd['b'] = 'bbb'
        assert dd['a'] == 'zzz'
        assert dd['b'] == 'bbb'
        target = 'a {a} and b {b}'.format(**dd)
        assert dd['a'] in target
        assert dd['b'] in target
Ejemplo n.º 4
0
 def test_unicode(self):
     dd = DynamicDictLookup()
     dd['u'] = '✓'
     target = 'works {u}'
     result = target.format(**dd)
     assert '✓' in result
Ejemplo n.º 5
0
 def test_dd_no_key(self):
     dd = DynamicDictLookup()
     with pytest.raises(KeyError):
         dd['a']
 def test_unicode(self):
     dd = DynamicDictLookup()
     dd['u'] = u'\u2713'
     target = u'works {u}'
     result = target.format(**dd)
     assert u'\u2713' in result