Lichen

internal_tests/references.py

343:e0879c83a439
2016-12-07 Paul Boddie Added support for reading to the end of a stream's input, fixing EOFError raising in fread by returning shorter amounts of data when EOF occurs, only raising an exception if no data was read before EOF occurred. Made the test input longer to exercise tests of reading remaining data.
     1 #!/usr/bin/env python     2      3 from referencing import decode_reference, Reference     4      5 def show_test(v1, v2):     6     print "%r %r %r" % (v1 == v2, v1, v2)     7      8 # Compare decoded and constructed references.     9     10 var1 = decode_reference("<var>")    11 var2 = Reference("<var>")    12 show_test(var1, var2)    13     14 # Compare with var with superfluous origin.    15     16 var3 = Reference("<var>", "whatever")    17 show_test(var1, var3)    18     19 # Compare with var and alias.    20     21 var4 = Reference("<var>", None, "attribute")    22 show_test(var1, var4)    23     24 # Compare with var with superfluous origin and alias.    25     26 var5 = Reference("<var>", "whatever", "attribute")    27 show_test(var1, var5)    28 show_test(var5.get_origin(), None)    29     30 # Compare vars with different aliases.    31     32 var6 = Reference("<var>", None, "other")    33 show_test(var4, var6)    34     35 # Check aliased var.    36     37 var7 = var1.alias("attribute")    38 show_test(var7, var4)    39     40 # Check class references, firstly with someclass being identified as a class.    41     42 cls1 = decode_reference("<class>", "someclass")    43 cls2 = Reference("<class>", "someclass")    44 show_test(cls1, cls2)    45     46 # Check aliasing of class references.    47     48 cls3 = cls1.alias("attribute")    49 cls4 = cls2.alias("other")    50 show_test(cls3, cls4)    51     52 # Check other class references.    53     54 cls5 = decode_reference("<class>:someclass")    55 cls6 = Reference("<class>", "someclass")    56 show_test(cls5, cls6)    57     58 # Check aliasing again.    59     60 cls7 = cls5.alias("attribute")    61 cls8 = cls6.alias("other")    62 show_test(cls7, cls8)    63     64 # Check instance references. These do not make sense without an origin.    65     66 inst1 = decode_reference("<instance>:someclass", "whatever")    67 inst2 = Reference("<instance>", "someclass")    68 show_test(inst1, inst2)    69     70 # Check instantiation.    71     72 inst3 = cls5.instance_of()    73 show_test(inst1, inst3)    74     75 # Check modules.    76     77 mod1 = decode_reference("somemodule")    78 mod2 = Reference("<module>", "somemodule")    79 show_test(mod1, mod2)    80     81 mod3 = decode_reference("<module>:somemodule")    82 show_test(mod1, mod3)    83     84 mod4 = decode_reference("<module>", "somemodule")    85 show_test(mod1, mod4)    86     87 # vim: tabstop=4 expandtab shiftwidth=4