@@ -72,17 +72,23 @@ def test_basics(self):
7272 for m1 , m2 in zip (d .maps , e .maps ):
7373 self .assertIsNot (m1 , m2 , e )
7474
75- d .new_child ()
76- d ['b' ] = 5
77- self .assertEqual (d .maps , [{'b' : 5 }, {'c' :30 }, {'a' :1 , 'b' :2 }])
78- self .assertEqual (d .parents .maps , [{'c' :30 }, {'a' :1 , 'b' :2 }]) # check parents
79- self .assertEqual (d ['b' ], 5 ) # find first in chain
80- self .assertEqual (d .parents ['b' ], 2 ) # look beyond maps[0]
75+ f = d .new_child ()
76+ f ['b' ] = 5
77+ self .assertEqual (f .maps , [{'b' : 5 }, {'c' :30 }, {'a' :1 , 'b' :2 }])
78+ self .assertEqual (f .parents .maps , [{'c' :30 }, {'a' :1 , 'b' :2 }]) # check parents
79+ self .assertEqual (f ['b' ], 5 ) # find first in chain
80+ self .assertEqual (f .parents ['b' ], 2 ) # look beyond maps[0]
8181
8282 def test_contructor (self ):
83- self .assertEqual (ChainedContext ().maps , [{}]) # no-args --> one new dict
83+ self .assertEqual (ChainMap ().maps , [{}]) # no-args --> one new dict
8484 self .assertEqual (ChainMap ({1 :2 }).maps , [{1 :2 }]) # 1 arg --> list
8585
86+ def test_bool (self ):
87+ self .assertFalse (ChainMap ())
88+ self .assertFalse (ChainMap ({}, {}))
89+ self .assertTrue (ChainMap ({1 :2 }, {}))
90+ self .assertTrue (ChainMap ({}, {1 :2 }))
91+
8692 def test_missing (self ):
8793 class DefaultChainMap (ChainMap ):
8894 def __missing__ (self , key ):
@@ -1182,7 +1188,7 @@ def test_popitem(self):
11821188def test_main (verbose = None ):
11831189 NamedTupleDocs = doctest .DocTestSuite (module = collections )
11841190 test_classes = [TestNamedTuple , NamedTupleDocs , TestOneTrickPonyABCs ,
1185- TestCollectionABCs , TestCounter ,
1191+ TestCollectionABCs , TestCounter , TestChainMap ,
11861192 TestOrderedDict , GeneralMappingTests , SubclassMappingTests ]
11871193 support .run_unittest (* test_classes )
11881194 support .run_doctest (collections , verbose )
0 commit comments