6 from os
.path
import join
7 from os
.path
import dirname
8 from os
.path
import basename
11 from cola
.model
import Model
13 DEBUG_MODE
= os
.getenv('DEBUG','')
15 TEST_SCRIPT_DIR
= dirname(__file__
)
16 ROOT_TMP_DIR
= join( dirname(TEST_SCRIPT_DIR
), 'tmp' )
17 TEST_TMP_DIR
= join( ROOT_TMP_DIR
, basename(sys
.argv
[0]) )
21 parentdir
= dirname(newdir
)
22 if not os
.path
.isdir(parentdir
):
24 if not os
.path
.isdir(newdir
):
29 return '%s-%d.%04d' % (TEST_TMP_DIR
, os
.getpid(), LAST_IDX
)
31 def create_test_dir():
34 newdir
= get_test_dir()
41 os
.chdir(ROOT_TMP_DIR
)
44 def remove_test_dir():
46 testdir
= get_test_dir()
51 result
= os
.system(cmd
)
56 out
= p
.read().strip()
60 # All tests that operate on temporary data derive from testlib.TestCase
61 class TestCase(unittest
.TestCase
):
68 self
.failIf(result
!= 0)
69 def get_test_dir(self
):
72 class DuckModel(Model
):
74 duck
= Model().create(sound
='quack',name
='ducky')
75 goose
= Model().create(sound
='cluck',name
='goose')
77 self
.create(attribute
= 'value',
78 mylist
=[duck
,duck
,goose
])
80 self
.set_mylist([duck
,duck
,goose
, 'meow', 'caboose',42])
85 class InnerModel(Model
):
87 self
.create(foo
= 'bar')
89 class NestedModel(Model
):
91 self
.create(inner
= InnerModel(),
93 normaList
= [ 1,2,3, [4,5, [6,7,8], 9]])
94 self
.innerList
.append(InnerModel())
95 self
.innerList
.append([InnerModel()])
96 self
.innerList
.append([[InnerModel()]])
97 self
.innerList
.append([[[InnerModel(),InnerModel()]]])
98 self
.innerList
.append({"foo": InnerModel()})