Atlas 0.7.0
Networking protocol for the Worldforge system.
test_atlas.py
1#test objects
2
3#Copyright 2000-2002 by Aloril
4
5#This library is free software; you can redistribute it and/or
6#modify it under the terms of the GNU Lesser General Public
7#License as published by the Free Software Foundation; either
8#version 2.1 of the License, or (at your option) any later version.
9
10#This library is distributed in the hope that it will be useful,
11#but WITHOUT ANY WARRANTY; without even the implied warranty of
12#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13#Lesser General Public License for more details.
14
15#You should have received a copy of the GNU Lesser General Public
16#License along with this library; if not, write to the Free Software
17#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19from test_objects import *
20
21a = Object(id="a", a=3)
22b = Object(id="b", a=2)
23c = Object(id="c", foo=42, parents=[a,b])
24#if repr(c.get_all_attributes()) != "{'id': 'c', 'parents': ['a', 'b'], 'foo': 42, 'a': 3}":
25# print "get_all_attributes wrong?:", repr(c.get_all_attributes())
26if c.get_all_attributes() != {'id': 'c', 'parents': ['a', 'b'], 'foo': 42, 'a': 3}:
27 print("get_all_attributes wrong?:", c.get_all_attributes())
28
29abc = {"a":a, "b":b, "c":c}
30ent = Object(id="12", objtype="object", parents=[human_class], pos=[4.5, 6.5, -1.0])
31
32if not c.has_parent("a") or \
33 not c.has_parent("b") or \
34 not c.has_parent(a) or \
35 c.has_parent("fo") or \
36 not c.has_parent("c") or \
37 not c.has_parent(c) or \
38 c.has_parent(ent):
39 print("c.has_parent works wrong!")
40
41if not has_parent(c, a) or \
42 not has_parent(c, "a") or \
43 has_parent(c, "af") or \
44 not has_parent("c", a, abc) or \
45 not has_parent(c, "a", abc) or \
46 not has_parent("c", "a", abc) or \
47 has_parent(c, "af", abc) or \
48 has_parent("c", "af", abc):
49 print("has_parent works wrong!")
50
51op = Operation("move", Object(loc="house1", pos=[2.1, 0.4, 0.0]), to="joe12")
52if str(op) != '{\n\targ: {\n\t\tloc: "house1",\n\t\tpos: [2.1, 0.4, 0.0]\n\t},\n\tobjtype: "op",\n\tparents: ["move"],\n\tto: "joe12"\n}\n':
53 print("Operation doesn't match:", repr(op))
54
55
56
57#tests by mithro:
59 peanut="blah"
60
61a = test1()
62assert(a.peanut=="blah")
63#print a.peanut
64
66 parents=[test1]
67
68b = test2()
69assert(b.peanut=="blah")
70
71#few more test2 by aloril
73 parents=[test2()]
74
75c = test3()
76assert(c.peanut=="blah")
77
79 pass
80
81d = test4()
82d.parents = [test1]
83assert(d.peanut=="blah")
84d.parents = [test1()]
85assert(d.peanut=="blah")
86
87
89 parents=[test2()]
90e = test5()
91assert(e.peanut=="blah")
92
93
94#Doesn't work, no support for this yet:
95#class test6(atlas.Object):
96# parents=[test2]
97#
98#f = test6()
99#print "-"*60
100#assert(f.peanut=="blah")
101
102#class test7(test5):
103# pass
104#g = test7()
105#assert(g.peanut=="blah")
106
107
108#class test8(test6):
109# pass
110#h = test8()
111#assert(h.peanut=="blah")
112