1 #!/usr/bin/env python2.2
4 from os
.path
import dirname
, abspath
, join
5 rox_lib
= dirname(dirname(dirname(abspath(sys
.argv
[0]))))
6 sys
.path
.insert(0, join(rox_lib
, 'python'))
8 from rox
import basedir
, choices
11 def write(self
, data
):
15 class TestChoices(unittest
.TestCase
):
17 os
.environ
['CHOICESPATH'] = '/tmp/choices:/tmp/choices2'
18 os
.environ
['XDG_CONFIG_HOME'] = '/tmp/config'
20 if os
.path
.isdir('/tmp/choices'):
21 shutil
.rmtree('/tmp/choices')
23 if os
.path
.isdir('/tmp/choices2'):
24 shutil
.rmtree('/tmp/choices2')
26 if os
.path
.isdir('/tmp/config'):
27 shutil
.rmtree('/tmp/config')
32 def testDefaults(self
):
33 del os
.environ
['CHOICESPATH']
37 [os
.path
.expanduser('~/Choices'),
38 '/usr/local/share/Choices',
39 '/usr/share/Choices'],
42 def testLoadNothing(self
):
43 self
.assertEquals('/tmp/choices', choices
.paths
[0])
44 assert not os
.path
.exists('/tmp/choices')
46 self
.assertEquals(choices
.load('Edit', 'Options'), None)
49 os
.mkdir('/tmp/choices')
50 os
.mkdir('/tmp/choices/Edit')
51 self
.assertEquals(choices
.load('Edit', 'Options'), None)
53 file('/tmp/choices/Edit/Options', 'w').close()
54 self
.assertEquals(choices
.load('Edit', 'Options'),
55 '/tmp/choices/Edit/Options')
57 os
.mkdir('/tmp/choices2')
58 os
.mkdir('/tmp/choices2/Edit')
59 self
.assertEquals(choices
.load('Edit', 'Options'),
60 '/tmp/choices/Edit/Options')
62 file('/tmp/choices2/Edit/Options', 'w').close()
63 self
.assertEquals(choices
.load('Edit', 'Options'),
64 '/tmp/choices/Edit/Options')
66 os
.unlink('/tmp/choices/Edit/Options')
67 self
.assertEquals(choices
.load('Edit', 'Options'),
68 '/tmp/choices2/Edit/Options')
70 def testMigrateNothing(self
):
71 choices
.migrate('Edit', 'rox.sourceforge.net')
72 choices
.load('Draw', 'Options')
74 choices
.load('Edit', 'Options')
75 raise Exception('Expected exception!')
76 except AssertionError:
78 assert not os
.path
.exists('/tmp/config')
80 def testMigrateNormal(self
):
81 save
= choices
.save('Edit', 'Options')
82 self
.assertEquals(save
, '/tmp/choices/Edit/Options')
83 file(save
, 'w').close()
84 choices
.migrate('Edit', 'rox.sourceforge.net')
86 assert os
.path
.isfile(
87 '/tmp/config/rox.sourceforge.net/Edit/Options')
88 assert os
.path
.islink('/tmp/choices/Edit')
90 assert os
.path
.isfile('/tmp/choices/Edit/Options')
92 def testDoubleMigrate(self
):
93 choices
.migrate('Edit', 'rox.sourceforge.net')
95 choices
.migrate('Edit', 'rox.sourceforge.net')
96 raise Exception('Expected exception!')
97 except AssertionError:
100 def testFailedMigration(self
):
101 save
= choices
.save('Edit', 'Options')
102 file(save
, 'w').close()
103 save2
= basedir
.save_config_path('rox.sourceforge.net', 'Edit')
104 file(os
.path
.join(save2
, 'Options'), 'w').close()
105 old
, sys
.stderr
= sys
.stderr
, null
107 choices
.migrate('Edit', 'rox.sourceforge.net')
110 assert os
.path
.isdir('/tmp/choices/Edit')
111 assert os
.path
.isdir('/tmp/config/rox.sourceforge.net/Edit')
113 suite
= unittest
.makeSuite(TestChoices
)
114 if __name__
== '__main__':
115 sys
.argv
.append('-v')