aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utilities_tests.py
diff options
context:
space:
mode:
authorJesse Jaggars <jjaggars@redhat.com>2012-03-05 10:30:59 -0600
committerJesse Jaggars <jjaggars@redhat.com>2012-03-05 10:30:59 -0600
commitc10115652a795d0c7971ec9b03c4c58742063ddf (patch)
tree4c14fa591b807350f6db6c7da10f1430049602f5 /tests/utilities_tests.py
parent83c6e09756bd228dc76e7a84646de5a9f5b5e694 (diff)
downloadsos-c10115652a795d0c7971ec9b03c4c58742063ddf.tar.gz
Refactoring PackageManagers and Archives
Pulled up PackageManager implementation to simplify subclass responsibilities Moved compress method to Archive classes Re-organized utilities.py Added tests to exercise more utilities methods
Diffstat (limited to 'tests/utilities_tests.py')
-rw-r--r--tests/utilities_tests.py48
1 files changed, 47 insertions, 1 deletions
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
index d5115928..fbfc9a55 100644
--- a/tests/utilities_tests.py
+++ b/tests/utilities_tests.py
@@ -2,9 +2,11 @@ import os.path
import unittest
from StringIO import StringIO
-from sos.utilities import grep, DirTree, checksum
+from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sosGetCommandOutput, find
import sos
+TEST_DIR = os.path.dirname(__file__)
+
class GrepTest(unittest.TestCase):
def test_file_obj(self):
@@ -30,8 +32,52 @@ class DirTreeTest(unittest.TestCase):
t = DirTree(os.path.dirname(sos.__file__)).as_string()
self.assertTrue('Makefile' in t)
+
class ChecksumTest(unittest.TestCase):
def test_simple_hash(self):
self.assertEquals(checksum(StringIO('this is a test'), algorithm="sha256"),
'2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c')
+
+ def test_hash_loading(self):
+ # not the greatest test, since we are asking the policy to pick for us
+ name = get_hash_name()
+ self.assertTrue(name in ('md5', 'sha256'))
+
+
+class ExecutableTest(unittest.TestCase):
+
+ def test_nonexe_file(self):
+ path = os.path.join(TEST_DIR, 'utility_tests.py')
+ self.assertFalse(is_executable(path))
+
+ def test_exe_file(self):
+ path = os.path.join(TEST_DIR, 'test_exe.py')
+ self.assertTrue(is_executable(path))
+
+ def test_output(self):
+ path = os.path.join(TEST_DIR, 'test_exe.py')
+ ret, out, junk = sosGetCommandOutput(path)
+ self.assertEquals(ret, 0)
+ self.assertEquals(out, "executed")
+
+ def test_output_non_exe(self):
+ path = os.path.join(TEST_DIR, 'utility_tests.py')
+ ret, out, junk = sosGetCommandOutput(path)
+ self.assertEquals(ret, 127)
+ self.assertEquals(out, "")
+
+
+class FindTest(unittest.TestCase):
+
+ def test_find_leaf(self):
+ leaves = find("leaf", TEST_DIR)
+ self.assertTrue(any(name.endswith("leaf") for name in leaves))
+
+ def test_too_shallow(self):
+ leaves = find("leaf", TEST_DIR, max_depth=1)
+ self.assertFalse(any(name.endswith("leaf") for name in leaves))
+
+ def test_not_in_pattern(self):
+ leaves = find("leaf", TEST_DIR, path_pattern="tests/path")
+ self.assertFalse(any(name.endswith("leaf") for name in leaves))