Lichen

tests/getattr.py

544:8df59b6c2c68
2017-02-05 Paul Boddie Fixed internal mapping methods to accept explicit bucket sequences, preventing confusion when searching for entries in one set of buckets while attempting to populate another. Implemented various dictionary and set methods. Added set iteration support. Expanded the test of sets.
     1 class C:     2     def __init__(self):     3         self.x = 1     4         self.y = 2     5         self.z = 3     6      7 class D:     8     def __init__(self):     9         self.x = 4    10         self.y = 5    11         self.z = 6    12     13 c = C()    14 d = D()    15     16 attrnames = ["a", "b", "c", "x", "y", "z"]    17     18 print ". c d"    19     20 for attrname in attrnames:    21     print attrname, hasattr(c, attrname) and "1" or "0", hasattr(d, attrname) and "1" or "0"    22     23 print    24 print ". c d"    25     26 for attrname in attrnames:    27     print attrname,    28     try:    29         v = getattr(c, attrname)    30         print v,    31     except AttributeError:    32         print "?",    33     34     try:    35         v = getattr(d, attrname)    36         print v    37     except AttributeError:    38         print "?"    39     40 try:    41     setattr(c, "x", 7)    42 except NotImplementedError, exc:    43     print 'setattr(c, "x", 7): not implemented:', exc.name