From f20139b105aa0fa62e11850fa692a8d229259534 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 10 Apr 2005 13:43:37 +0000 Subject: [PATCH] Moved unit tests to a separate directory (Thomas Leonard). git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/Archive@3872 66de3db3-b00d-0410-b41b-f4738ad19bea --- Help/Changes | 1 + formats.py | 58 --------------------------------------------------- tests/testall.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) diff --git a/Help/Changes b/Help/Changes index 136d4ea..f2fee49 100644 --- a/Help/Changes +++ b/Help/Changes @@ -10,6 +10,7 @@ Don't let the default name be the same as the original file. Try it without the extension, or with '.unpacked' if there is no extension (Thomas Leonard). Use PipeThroughCommand from ROX-Lib, instead of our own version (Thomas Leonard). +Moved unit tests to a separate directory (Thomas Leonard). 23-Dec-2004 ~~~~~~~~~~~ diff --git a/formats.py b/formats.py index 0aebcbc..1fbf7e6 100644 --- a/formats.py +++ b/formats.py @@ -288,61 +288,3 @@ class DirData: self.path = path self.default = make_tgz self.default_name = path + '.' + self.default.extension - -def test(): - test_data = 'Hello\0World\n' - src = Tmp() - src.write(test_data) - src.flush() - data = FileData(src.name) - for comp in operations: - if not isinstance(comp, Compress): continue - dec = [o for o in operations if isinstance(o, Decompress) and - o.extension == comp.extension] - assert len(dec) == 1 - dec = dec[0] - print "Test %s / %s" % (comp, dec) - middle = Tmp() - comp.save_to_stream(data, middle) - out = Tmp() - dec.save_to_stream(FileData(middle.name), out) - del middle - assert file(out.name).read() == test_data - print "Passed" - del src - - dir = '/tmp/archive-regression-test' - out = dir + '.out' - if not os.path.exists(dir): os.mkdir(dir) - print >>file(dir + '/test', 'w'), test_data - data = DirData(dir) - - for archive in operations: - if not isinstance(archive, Archive): continue - extract = [o for o in operations if isinstance(o, Extract) and - o.extension == archive.extension] - if not extract: - print "(skipping %s; no extractor)" % archive - continue - - if os.path.exists(out): os.system("rm -r '%s'" % out) - - assert len(extract) == 1 - extract = extract[0] - print "Test %s / %s" % (archive, extract) - - middle = Tmp() - archive.save_to_stream(data, middle) - extract.save_to_file(FileData(middle.name), dir + '.out') - - assert os.listdir(dir) == os.listdir(out) - assert file(dir + '/test').read() == file(out + '/test').read() - print "Passed" - - os.unlink(dir + '/test') - os.rmdir(dir) - if os.path.exists(out): os.system("rm -r '%s'" % out) - -if __name__ == '__main__': - __builtins__._ = rox.i18n.translation(os.path.join(rox.app_dir, 'Messages')) - test() diff --git a/tests/testall.py b/tests/testall.py index cec4115..98d6875 100755 --- a/tests/testall.py +++ b/tests/testall.py @@ -9,7 +9,10 @@ sys.argv[0] = dirname(sys.argv[0]) import findrox; findrox.version(1, 9, 12) +from rox import i18n from support import shell_escape, Tmp +from formats import * +__builtins__._ = rox.i18n.translation(os.path.join(rox.app_dir, 'Messages')) class TestSupport(unittest.TestCase): def testShellEscape(self): @@ -32,5 +35,65 @@ class TestSupport(unittest.TestCase): tmp_file = None assert not os.path.exists(name) +class TestFormats(unittest.TestCase): + def setUp(self): + os.chdir('/') + + def testCompress(self): + test_data = 'Hello\0World\n' + src = Tmp() + src.write(test_data) + src.flush() + data = FileData(src.name) + for comp in operations: + if not isinstance(comp, Compress): continue + dec = [o for o in operations if isinstance(o, Decompress) and + o.extension == comp.extension] + assert len(dec) == 1 + dec = dec[0] + #print "Test %s / %s" % (comp, dec) + middle = Tmp() + comp.save_to_stream(data, middle) + out = Tmp() + dec.save_to_stream(FileData(middle.name), out) + del middle + assert file(out.name).read() == test_data + #print "Passed" + del src + + def testArchive(self): + test_data = 'Hello\0World\n' + dir = '/tmp/archive-regression-test' + out = dir + '.out' + if not os.path.exists(dir): os.mkdir(dir) + print >>file(dir + '/test', 'w'), test_data + data = DirData(dir) + + for archive in operations: + if not isinstance(archive, Archive): continue + extract = [o for o in operations if isinstance(o, Extract) and + o.extension == archive.extension] + if not extract: + #print "(skipping %s; no extractor)" % archive + continue + + if os.path.exists(out): os.system("rm -r '%s'" % out) + + assert len(extract) == 1 + extract = extract[0] + #print "Test %s / %s" % (archive, extract) + + middle = Tmp() + archive.save_to_stream(data, middle) + extract.save_to_file(FileData(middle.name), dir + '.out') + + assert os.listdir(dir) == os.listdir(out) + assert file(dir + '/test').read() == file(out + '/test').read() + #print "Passed" + + os.unlink(dir + '/test') + os.rmdir(dir) + if os.path.exists(out): os.system("rm -r '%s'" % out) + sys.argv.append('-v') unittest.main() -- 2.11.4.GIT