from unittest import TestCase
import lazydict

class TestLazyDictionary(TestCase):

    def test_circular_reference_error(self):
        d = lazydict.LazyDictionary()
        d['foo'] = lambda s: s['foo']
        self.assertRaises(lazydict.CircularReferenceError, d.__getitem__, 'foo')

    def test_constant_redefinition_error(self):
        d = lazydict.LazyDictionary()
        d['a'] = 1
        d['b'] = 2
        d['sum'] = lambda s: s['a'] + s['b']
        x = d['sum']
        self.assertRaises(lazydict.ConstantRedefinitionError, d.__setitem__, 'a', 'hotdog')
        self.assertRaises(lazydict.ConstantRedefinitionError, d.__delitem__, 'a')

    def test_lazy_evaluation(self):
        d = lazydict.LazyDictionary()
        d['sum'] = lambda s: s['a'] + s['b']
        d['a'] = 1
        d['b'] = 2
        self.assertEqual(d['sum'], 3)

    def test_str(self):
        d = lazydict.LazyDictionary({'a': 1})
        self.assertEqual(str(d),   "{'a': 1}")

    def test_repr(self):
        d =               lazydict.LazyDictionary({'a': 1})
        self.assertEqual(repr(d), "LazyDictionary({'a': 1})")

@@ -899,33 +899,40 @@
 ictionary(%7B'a': 
-1
+%7B'b': 1%7D
 %7D)%0A        self.
@@ -960,17 +960,24 @@
  %22%7B'a': 
-1
+%7B'b': 1%7D
 %7D%22)%0A%0A   
@@ -1054,17 +1054,24 @@
 y(%7B'a': 
-1
+%7B'b': 1%7D
 %7D)%0A     
@@ -1121,14 +1121,21 @@
 y(%7B'a': 
-1
+%7B'b': 1%7D
 %7D)%22)%0A

Check recursion in str() and repr()