micropython

internal_tests/objectset.py

458:066315d6bbb7
2011-08-28 Paul Boddie Consolidated the dictionary combination code for merging ObjectSet instances (holding the attribute usage for a name) and for combining dictionaries of lists of ObjectSets (holding all the attribute usage for a section of the code). Added some tests of ObjectSet functionality.
     1 #!/usr/bin/env python     2      3 from micropython.common import ObjectSet     4      5 o1 = ObjectSet()     6 o1.add("a")     7 o1.add("b")     8 o1.add("c")     9 print "o1 =", o1    10     11 o2 = ObjectSet()    12 o2.add("b")    13 o2["c"] = ["x"]    14 o2.add("d")    15 o2["d"] += ["p", "q"]    16 print "o2 =", o2    17     18 assert o1 != o2    19 print "o1 == o2", o1 == o2    20 print "o1 != o2", o1 != o2    21     22 o12 = o1.merge(o2)    23 print "o1 =", o1    24 print "o2 =", o2    25 print "o12 =", o12    26     27 o12_keys = o12.keys()    28 o12_keys.sort()    29 assert o12_keys == ["a", "b", "c", "d"]    30 print "o12_keys =", o12_keys    31     32 o1_copy = ObjectSet(o1)    33 assert o1 == o1_copy    34 print "o1 =", o1    35 print "o1_copy =", o1_copy    36 print "o1 == o1_copy", o1 == o1_copy    37     38 o1_copy.update(o2)    39 assert o1 != o1_copy    40 assert o12 == o1_copy    41 print "o1_copy =", o1_copy    42 print "o1 != o1_copy", o1 != o1_copy    43 print "o12 == o1_copy", o12 == o1_copy    44     45 o3 = ObjectSet()    46 o3.add("c")    47 o3["c"].append("y")    48 print "o3 =", o3    49     50 # vim: tabstop=4 expandtab shiftwidth=4