removed model.clone(init=False) hack
[git-cola.git] / t / modeltest.py
blob2aec5342a88712779dbf22081af4f333aa708793
1 #!/usr/bin/env python
2 import unittest
3 from testmodel import TestModel
5 class ModelTest(unittest.TestCase):
7 def setUp(self):
8 self.model = TestModel()
10 def tearDown(self):
11 del self.model
13 def testRegularAttributes(self):
14 '''Test accessing attribute via model.attribute.'''
15 self.failUnless( self.model.attribute == 'value' )
17 def testUppercaseAttributes(self):
18 '''Test accessing attribute via model.ATTRIBUTE.'''
19 self.failUnless( self.model.ATTRIBUTE == 'value' )
21 def testMixedcaseAttributes(self):
22 '''Test accessing attribute via model.Attribute.'''
23 self.failUnless( self.model.Attribute == 'value' )
25 def testExplicitAttr(self):
26 '''Test accessing an explicit attribute.'''
27 self.failUnless( self.model.hello == 'world' )
29 def testRealMethod(self):
30 '''Test calling a concrete model method.'''
31 self.failUnless( self.model.realMethod() == 'real' )
33 def testGetter(self):
34 '''Test calling using the get* method.'''
35 self.failUnless( self.model.getAttribute() == 'value' )
37 def testSetter(self):
38 '''Test using the set* method.'''
39 self.model.set('newAttribute','baz')
40 self.failUnless( self.model.newattribute == 'baz' )
41 self.failUnless( self.model.getNewAttribute() == 'baz' )
43 def testAddArray(self):
44 '''Test using the add* array method.'''
45 self.model.array = []
46 self.model.addArray('bar')
47 self.failUnless( self.model.array[0] == 'bar' )
49 self.model.addArray('baz','quux')
50 self.failUnless( self.model.array[1] == 'baz' )
51 self.failUnless( self.model.array[2] == 'quux' )
53 def testAppendArray(self):
54 '''Test using the append* array method.'''
55 self.model.array = []
56 self.model.appendArray('bar')
57 self.failUnless( self.model.array[0] == 'bar' )
59 self.model.appendArray('baz','quux')
60 self.failUnless( self.model.array[1] == 'baz' )
61 self.failUnless( self.model.array[2] == 'quux' )
63 def testDict(self):
64 '''Test setting dictionary/dictionary values.'''
65 self.model.dict = { 'hello': 'world' }
66 self.failUnless( self.model.dict['hello'] == 'world' )
67 self.failUnless( self.model.getDict()['hello'] == 'world' )
69 def testFromDict(self):
70 '''Test reconstituting a model from a dictionary.'''
71 self.model.from_dict({
72 'test_dict': { 'hello':'world' },
73 'test_list': [ 'foo', 'bar' ],
74 'test_str': 'foo',
76 self.failUnless( self.model.get_test_dict()['hello'] == 'world' )
77 self.failUnless( self.model.get_test_list()[1] == 'bar' )
79 if __name__ == '__main__': unittest.main()