1 #!/usr/bin/env python2.4
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)
13 from support
import shell_escape
, Tmp
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" '''
25 tmp_file
.write('Hello')
26 print >>tmp_file
, ' ',
28 os
.write(tmp_file
.fileno(), 'World')
31 assert tmp_file
.read() == 'Hello World'
34 assert os
.path
.exists(name
)
36 assert not os
.path
.exists(name
)
38 class TestFormats(unittest
.TestCase
):
42 def testCompress(self
):
43 test_data
= 'Hello\0World\n'
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
]
54 #print "Test %s / %s" % (comp, dec)
56 comp
.save_to_stream(data
, middle
)
58 dec
.save_to_stream(FileData(middle
.name
), out
)
60 assert file(out
.name
).read() == test_data
64 def testArchive(self
):
65 test_data
= 'Hello\0World\n'
66 dir = '/tmp/archive-regression-test'
68 if not os
.path
.exists(dir): os
.mkdir(dir)
69 print >>file(dir + '/test', 'w'), test_data
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
]
77 #print "(skipping %s; no extractor)" % archive
80 if os
.path
.exists(out
): os
.system("rm -r '%s'" % out
)
82 assert len(extract
) == 1
84 #print "Test %s / %s" % (archive, extract)
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()
94 os
.unlink(dir + '/test')
96 if os
.path
.exists(out
): os
.system("rm -r '%s'" % out
)