aboutsummaryrefslogtreecommitdiffstats
path: root/tests/archive_tests.py
diff options
context:
space:
mode:
authorJesse Jaggars <jhjaggars@gmail.com>2011-12-14 16:05:59 -0600
committerJesse Jaggars <jhjaggars@gmail.com>2011-12-14 16:05:59 -0600
commit6ea48cbbc85d007dfefd1f254db66ff2e0a9cec5 (patch)
tree35188a9f5f2be7f3ae6ea52beea0883dca47abda /tests/archive_tests.py
parent1e83a26da25981f362d4acc35d61dfa3b2ab56a3 (diff)
downloadsos-6ea48cbbc85d007dfefd1f254db66ff2e0a9cec5.tar.gz
Major updates to most of SoSReport
Code reorganization Cross platform support for Windows, OS X and Linux Dynamically loaded policies Support for loading plugins from multiple locations via __path__ modification of sos.plugins Support for running via Jython Support for executing from a jarfile Support for json based reporting infrastructure - Previous reporting methods still exist Support for other checksum algorithms (determined by policy) Support for other compression algorithms (determined by policy) New plugin API for writing arbitrary information in a new file inside the report archive. New plugin API for modifying files that have been added to the archive. Added API for global plugin options - external interface is unavailable at this time Many small bugfixes
Diffstat (limited to 'tests/archive_tests.py')
-rwxr-xr-xtests/archive_tests.py130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
new file mode 100755
index 00000000..01c46395
--- /dev/null
+++ b/tests/archive_tests.py
@@ -0,0 +1,130 @@
+#!/usr/bin/env python
+
+import unittest
+import os
+import tarfile
+import zipfile
+
+from sos.utilities import TarFileArchive, ZipFileArchive
+
+class ZipFileArchiveTest(unittest.TestCase):
+
+ def setUp(self):
+ self.zf = ZipFileArchive('test')
+
+ def tearDown(self):
+ os.unlink('test.zip')
+
+ def check_for_file(self, filename):
+ zf = zipfile.ZipFile('test.zip', 'r')
+ zf.getinfo(filename)
+ zf.close()
+
+ def test_create(self):
+ self.zf.close()
+
+ def test_add_file(self):
+ self.zf.add_file('tests/worker.py')
+ self.zf.close()
+
+ self.check_for_file('test/tests/worker.py')
+
+ def test_add_dir(self):
+ self.zf.add_file('tests/')
+ self.zf.close()
+
+ self.check_for_file('test/tests/worker.py')
+
+ def test_add_renamed(self):
+ self.zf.add_file('tests/worker.py', dest='tests/worker_renamed.py')
+ self.zf.close()
+
+ self.check_for_file('test/tests/worker_renamed.py')
+
+ def test_add_renamed_dir(self):
+ self.zf.add_file('tests/', 'tests_renamed/')
+ self.zf.close()
+
+ self.check_for_file('test/tests_renamed/worker.py')
+
+ def test_add_string(self):
+ self.zf.add_string('this is content', 'tests/string_test.txt')
+ self.zf.close()
+
+ self.check_for_file('test/tests/string_test.txt')
+
+ def test_get_file(self):
+ self.zf.add_string('this is my content', 'tests/string_test.txt')
+
+ afp = self.zf.open_file('tests/string_test.txt')
+ self.assertEquals('this is my content', afp.read())
+
+ def test_overwrite_file(self):
+ self.zf.add_string('this is my content', 'tests/string_test.txt')
+ self.zf.add_string('this is my new content', 'tests/string_test.txt')
+
+ afp = self.zf.open_file('tests/string_test.txt')
+ self.assertEquals('this is my new content', afp.read())
+
+class TarFileArchiveTest(unittest.TestCase):
+
+ def setUp(self):
+ self.tf = TarFileArchive('test')
+
+ def tearDown(self):
+ os.unlink('test.tar')
+
+ def check_for_file(self, filename):
+ rtf = tarfile.open('test.tar')
+ rtf.getmember(filename)
+ rtf.close()
+
+ def test_create(self):
+ self.tf.close()
+ self.assertTrue(os.path.exists('test.tar'))
+
+ def test_add_file(self):
+ self.tf.add_file('tests/worker.py')
+ self.tf.close()
+
+ self.check_for_file('test/tests/worker.py')
+
+ def test_add_dir(self):
+ self.tf.add_file('tests/')
+ self.tf.close()
+
+ self.check_for_file('test/tests/worker.py')
+
+ def test_add_renamed(self):
+ self.tf.add_file('tests/worker.py', dest='tests/worker_renamed.py')
+ self.tf.close()
+
+ self.check_for_file('test/tests/worker_renamed.py')
+
+ def test_add_renamed_dir(self):
+ self.tf.add_file('tests/', 'tests_renamed/')
+ self.tf.close()
+
+ self.check_for_file('test/tests_renamed/worker.py')
+
+ def test_add_string(self):
+ self.tf.add_string('this is content', 'tests/string_test.txt')
+ self.tf.close()
+
+ self.check_for_file('test/tests/string_test.txt')
+
+ def test_get_file(self):
+ self.tf.add_string('this is my content', 'tests/string_test.txt')
+
+ afp = self.tf.open_file('tests/string_test.txt')
+ self.assertEquals('this is my content', afp.read())
+
+ def test_overwrite_file(self):
+ self.tf.add_string('this is my content', 'tests/string_test.txt')
+ self.tf.add_string('this is my new content', 'tests/string_test.txt')
+
+ afp = self.tf.open_file('tests/string_test.txt')
+ self.assertEquals('this is my new content', afp.read())
+
+if __name__ == "__main__":
+ unittest.main()