Moved unit tests to a separate directory (Thomas Leonard).
[rox-archive.git] / tests / testall.py
blob98d6875670ee90892a447ae774a712a91b16bc5d
1 #!/usr/bin/env python2.2
2 import unittest
3 import sys
4 import os, time
5 from os.path import dirname, abspath, join
7 sys.path.insert(0, '..')
8 sys.argv[0] = dirname(sys.argv[0])
10 import findrox; findrox.version(1, 9, 12)
12 from rox import i18n
13 from support import shell_escape, Tmp
14 from formats import *
15 __builtins__._ = rox.i18n.translation(os.path.join(rox.app_dir, 'Messages'))
17 class TestSupport(unittest.TestCase):
18 def testShellEscape(self):
19 assert shell_escape(''' a test ''') == ' a test '
20 assert shell_escape(''' "a's test" ''') == ''' "a\\'s test" '''
21 assert shell_escape(''' "a\\'s test" ''') == ''' "a\\\\\\'s test" '''
23 def testTmp(self):
24 tmp_file = Tmp()
25 tmp_file.write('Hello')
26 print >>tmp_file, ' ',
27 tmp_file.flush()
28 os.write(tmp_file.fileno(), 'World')
30 tmp_file.seek(0)
31 assert tmp_file.read() == 'Hello World'
33 name = tmp_file.name
34 assert os.path.exists(name)
35 tmp_file = None
36 assert not os.path.exists(name)
38 class TestFormats(unittest.TestCase):
39 def setUp(self):
40 os.chdir('/')
42 def testCompress(self):
43 test_data = 'Hello\0World\n'
44 src = Tmp()
45 src.write(test_data)
46 src.flush()
47 data = FileData(src.name)
48 for comp in operations:
49 if not isinstance(comp, Compress): continue
50 dec = [o for o in operations if isinstance(o, Decompress) and
51 o.extension == comp.extension]
52 assert len(dec) == 1
53 dec = dec[0]
54 #print "Test %s / %s" % (comp, dec)
55 middle = Tmp()
56 comp.save_to_stream(data, middle)
57 out = Tmp()
58 dec.save_to_stream(FileData(middle.name), out)
59 del middle
60 assert file(out.name).read() == test_data
61 #print "Passed"
62 del src
64 def testArchive(self):
65 test_data = 'Hello\0World\n'
66 dir = '/tmp/archive-regression-test'
67 out = dir + '.out'
68 if not os.path.exists(dir): os.mkdir(dir)
69 print >>file(dir + '/test', 'w'), test_data
70 data = DirData(dir)
72 for archive in operations:
73 if not isinstance(archive, Archive): continue
74 extract = [o for o in operations if isinstance(o, Extract) and
75 o.extension == archive.extension]
76 if not extract:
77 #print "(skipping %s; no extractor)" % archive
78 continue
80 if os.path.exists(out): os.system("rm -r '%s'" % out)
82 assert len(extract) == 1
83 extract = extract[0]
84 #print "Test %s / %s" % (archive, extract)
86 middle = Tmp()
87 archive.save_to_stream(data, middle)
88 extract.save_to_file(FileData(middle.name), dir + '.out')
90 assert os.listdir(dir) == os.listdir(out)
91 assert file(dir + '/test').read() == file(out + '/test').read()
92 #print "Passed"
94 os.unlink(dir + '/test')
95 os.rmdir(dir)
96 if os.path.exists(out): os.system("rm -r '%s'" % out)
98 sys.argv.append('-v')
99 unittest.main()