root/gaphor/tags/gaphor-0.2.0/tests/model-consistency.py

Revision 110, 1.3 kB (checked in by arjanmol, 6 years ago)

Temp commit, not stable at all

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # vim: sw=4
2 # Check the attribute consistency (and proper import statements ;-) for a
3 # module.
4
5 import sys
6 sys.path.insert(0, '..')
7 from testlist import *
8 from gaphor.UML import *
9
10 def testvar(var1, var2):
11     if isinstance(var1, Sequence):
12         if var1.list[0] is not var2:
13             print "Association not fulfilled! (seq)"
14             print "var1", var1
15             print "var2", var2
16             sys.exit(1)
17     else:
18         if var1 is not var2:
19             print "Association not fulfilled!"
20             print "var1", var1
21             print "var2", var2
22             sys.exit(1)
23
24 for c in testlist:
25     assert hasattr(c, '_attrdef'), 'Every model element should have a _attrdef structure (%s)' % str(c)
26     for key in c._attrdef:
27         # Test associations:
28         if len(c._attrdef[key]) == 3:
29             mult, c2, key2 = c._attrdef[key]
30             print c.__name__ + "." + key + " <-> " + c2.__name__ + "." + key2,
31             i1 = c(1)
32             i2 = c2(2)
33             try:
34                 i1.__setattr__(key, i2)
35             except AttributeError, e:
36                 print "Setting value '" + key + "' on class '" + c.__name__ + "' does not seem to work."
37                 print e
38                 sys.exit(1)
39
40             # Now test if the keys are assigned properly
41             var1 = eval('i1.' + key)
42             var2 = eval('i2.' + key2)
43
44             testvar(var1, i2)
45             testvar(var2, i1)
46             print " (Okay!)"
47 #print "=================="
48 #print " All tests passed"
49 #print "=================="
Note: See TracBrowser for help on using the browser.