1 #!/usr/bin/env python2.2
4 sys
.path
.append('../../python')
6 from rox
import basedir
, choices
13 class TestChoices(unittest
.TestCase
):
15 os
.environ
['CHOICESPATH'] = '/tmp/choices:/tmp/choices2'
16 os
.environ
['XDG_CONFIG_HOME'] = '/tmp/config'
18 if os
.path
.isdir('/tmp/choices'):
19 shutil
.rmtree('/tmp/choices')
21 if os
.path
.isdir('/tmp/choices2'):
22 shutil
.rmtree('/tmp/choices2')
24 if os
.path
.isdir('/tmp/config'):
25 shutil
.rmtree('/tmp/config')
30 def testDefaults(self
):
31 del os
.environ
['CHOICESPATH']
35 [os
.path
.expanduser('~/Choices'),
36 '/usr/local/share/Choices',
37 '/usr/share/Choices'],
40 def testLoadNothing(self
):
41 self
.assertEquals('/tmp/choices', choices
.paths
[0])
42 assert not os
.path
.exists('/tmp/choices')
44 self
.assertEquals(choices
.load('Edit', 'Options'), None)
47 os
.mkdir('/tmp/choices')
48 os
.mkdir('/tmp/choices/Edit')
49 self
.assertEquals(choices
.load('Edit', 'Options'), None)
51 file('/tmp/choices/Edit/Options', 'w').close()
52 self
.assertEquals(choices
.load('Edit', 'Options'),
53 '/tmp/choices/Edit/Options')
55 os
.mkdir('/tmp/choices2')
56 os
.mkdir('/tmp/choices2/Edit')
57 self
.assertEquals(choices
.load('Edit', 'Options'),
58 '/tmp/choices/Edit/Options')
60 file('/tmp/choices2/Edit/Options', 'w').close()
61 self
.assertEquals(choices
.load('Edit', 'Options'),
62 '/tmp/choices/Edit/Options')
64 os
.unlink('/tmp/choices/Edit/Options')
65 self
.assertEquals(choices
.load('Edit', 'Options'),
66 '/tmp/choices2/Edit/Options')
68 def testMigrateNothing(self
):
69 choices
.migrate('Edit', 'rox.sourceforge.net')
70 choices
.load('Draw', 'Options')
72 choices
.load('Edit', 'Options')
73 raise Exception('Expected exception!')
74 except AssertionError:
76 assert not os
.path
.exists('/tmp/config')
78 def testMigrateNormal(self
):
79 save
= choices
.save('Edit', 'Options')
80 self
.assertEquals(save
, '/tmp/choices/Edit/Options')
81 file(save
, 'w').close()
82 choices
.migrate('Edit', 'rox.sourceforge.net')
84 assert os
.path
.isfile(
85 '/tmp/config/rox.sourceforge.net/Edit/Options')
86 assert os
.path
.islink('/tmp/choices/Edit')
88 assert os
.path
.isfile('/tmp/choices/Edit/Options')
90 def testDoubleMigrate(self
):
91 choices
.migrate('Edit', 'rox.sourceforge.net')
93 choices
.migrate('Edit', 'rox.sourceforge.net')
94 raise Exception('Expected exception!')
95 except AssertionError:
98 def testFailedMigration(self
):
99 save
= choices
.save('Edit', 'Options')
100 file(save
, 'w').close()
101 save2
= basedir
.save_config_path('rox.sourceforge.net', 'Edit')
102 file(os
.path
.join(save2
, 'Options'), 'w').close()
103 old
, sys
.stderr
= sys
.stderr
, null
105 choices
.migrate('Edit', 'rox.sourceforge.net')
108 assert os
.path
.isdir('/tmp/choices/Edit')
109 assert os
.path
.isdir('/tmp/config/rox.sourceforge.net/Edit')
111 suite
= unittest
.makeSuite(TestChoices
)
112 if __name__
== '__main__':
113 sys
.argv
.append('-v')