paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from referencing import decode_reference, Reference |
paul@0 | 4 | |
paul@0 | 5 | def show_test(v1, v2): |
paul@0 | 6 | print "%r %r %r" % (v1 == v2, v1, v2) |
paul@0 | 7 | |
paul@0 | 8 | # Compare decoded and constructed references. |
paul@0 | 9 | |
paul@0 | 10 | var1 = decode_reference("<var>") |
paul@0 | 11 | var2 = Reference("<var>") |
paul@0 | 12 | show_test(var1, var2) |
paul@0 | 13 | |
paul@0 | 14 | # Compare with var with superfluous origin. |
paul@0 | 15 | |
paul@0 | 16 | var3 = Reference("<var>", "whatever") |
paul@0 | 17 | show_test(var1, var3) |
paul@0 | 18 | |
paul@0 | 19 | # Compare with var and alias. |
paul@0 | 20 | |
paul@0 | 21 | var4 = Reference("<var>", None, "attribute") |
paul@0 | 22 | show_test(var1, var4) |
paul@0 | 23 | |
paul@0 | 24 | # Compare with var with superfluous origin and alias. |
paul@0 | 25 | |
paul@0 | 26 | var5 = Reference("<var>", "whatever", "attribute") |
paul@0 | 27 | show_test(var1, var5) |
paul@0 | 28 | show_test(var5.get_origin(), None) |
paul@0 | 29 | |
paul@0 | 30 | # Compare vars with different aliases. |
paul@0 | 31 | |
paul@0 | 32 | var6 = Reference("<var>", None, "other") |
paul@0 | 33 | show_test(var4, var6) |
paul@0 | 34 | |
paul@0 | 35 | # Check aliased var. |
paul@0 | 36 | |
paul@0 | 37 | var7 = var1.alias("attribute") |
paul@0 | 38 | show_test(var7, var4) |
paul@0 | 39 | |
paul@0 | 40 | # Check class references, firstly with someclass being identified as a class. |
paul@0 | 41 | |
paul@0 | 42 | cls1 = decode_reference("<class>", "someclass") |
paul@0 | 43 | cls2 = Reference("<class>", "someclass") |
paul@0 | 44 | show_test(cls1, cls2) |
paul@0 | 45 | |
paul@0 | 46 | # Check aliasing of class references. |
paul@0 | 47 | |
paul@0 | 48 | cls3 = cls1.alias("attribute") |
paul@0 | 49 | cls4 = cls2.alias("other") |
paul@0 | 50 | show_test(cls3, cls4) |
paul@0 | 51 | |
paul@0 | 52 | # Check other class references. |
paul@0 | 53 | |
paul@0 | 54 | cls5 = decode_reference("<class>:someclass") |
paul@0 | 55 | cls6 = Reference("<class>", "someclass") |
paul@0 | 56 | show_test(cls5, cls6) |
paul@0 | 57 | |
paul@0 | 58 | # Check aliasing again. |
paul@0 | 59 | |
paul@0 | 60 | cls7 = cls5.alias("attribute") |
paul@0 | 61 | cls8 = cls6.alias("other") |
paul@0 | 62 | show_test(cls7, cls8) |
paul@0 | 63 | |
paul@0 | 64 | # Check instance references. These do not make sense without an origin. |
paul@0 | 65 | |
paul@0 | 66 | inst1 = decode_reference("<instance>:someclass", "whatever") |
paul@0 | 67 | inst2 = Reference("<instance>", "someclass") |
paul@0 | 68 | show_test(inst1, inst2) |
paul@0 | 69 | |
paul@0 | 70 | # Check instantiation. |
paul@0 | 71 | |
paul@0 | 72 | inst3 = cls5.instance_of() |
paul@0 | 73 | show_test(inst1, inst3) |
paul@0 | 74 | |
paul@0 | 75 | # Check modules. |
paul@0 | 76 | |
paul@0 | 77 | mod1 = decode_reference("somemodule") |
paul@0 | 78 | mod2 = Reference("<module>", "somemodule") |
paul@0 | 79 | show_test(mod1, mod2) |
paul@0 | 80 | |
paul@0 | 81 | mod3 = decode_reference("<module>:somemodule") |
paul@0 | 82 | show_test(mod1, mod3) |
paul@0 | 83 | |
paul@0 | 84 | mod4 = decode_reference("<module>", "somemodule") |
paul@0 | 85 | show_test(mod1, mod4) |
paul@0 | 86 | |
paul@0 | 87 | # vim: tabstop=4 expandtab shiftwidth=4 |