aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJesse Jaggars <jjaggars@redhat.com>2012-02-27 13:51:07 -0600
committerJesse Jaggars <jjaggars@redhat.com>2012-02-27 13:53:09 -0600
commit6aa392791870474e577adeb8a24bad2ccd1a8390 (patch)
treefd6da3f187937e045812e6d0ee0678ccc98bcc75 /tests
parentaf1567395d1cfc2ef84b68478309ca47515d622d (diff)
downloadsos-6aa392791870474e577adeb8a24bad2ccd1a8390.tar.gz
adding ability to specify multiple files for Plugin.fileGrep
Diffstat (limited to 'tests')
-rw-r--r--tests/policy_tests.py20
-rw-r--r--tests/utilities_tests.py37
2 files changed, 56 insertions, 1 deletions
diff --git a/tests/policy_tests.py b/tests/policy_tests.py
index 2654c82c..25795a1c 100644
--- a/tests/policy_tests.py
+++ b/tests/policy_tests.py
@@ -1,6 +1,6 @@
import unittest
-from sos.policies import Policy, import_policy
+from sos.policies import Policy, PackageManager, import_policy
from sos.plugins import Plugin, IndependentPlugin, RedHatPlugin, DebianPlugin
class FauxPolicy(Policy):
@@ -47,5 +47,23 @@ class PolicyTests(unittest.TestCase):
def test_cant_import(self):
self.assertTrue(import_policy('notreal') is None)
+
+class PackageManagerTests(unittest.TestCase):
+
+ def setUp(self):
+ self.pm = PackageManager()
+
+ def test_default_all_pkgs(self):
+ self.assertEquals(self.pm.allPkgs(), {})
+
+ def test_default_all_pkgs_by_name(self):
+ self.assertEquals(self.pm.allPkgsByName('doesntmatter'), [])
+
+ def test_default_all_pkgs_by_name_regex(self):
+ self.assertEquals(self.pm.allPkgsByNameRegex('.*doesntmatter$'), [])
+
+ def test_default_pkg_by_name(self):
+ self.assertEquals(self.pm.pkgByName('foo'), None)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py
new file mode 100644
index 00000000..d5115928
--- /dev/null
+++ b/tests/utilities_tests.py
@@ -0,0 +1,37 @@
+import os.path
+import unittest
+from StringIO import StringIO
+
+from sos.utilities import grep, DirTree, checksum
+import sos
+
+class GrepTest(unittest.TestCase):
+
+ def test_file_obj(self):
+ test_s = "\n".join(['this is only a test', 'there are only two lines'])
+ test_fo = StringIO(test_s)
+ matches = grep(".*test$", test_fo)
+ self.assertEquals(matches, ['this is only a test\n'])
+
+ def test_real_file(self):
+ matches = grep(".*unittest$", __file__.replace(".pyc", ".py"))
+ self.assertEquals(matches, ['import unittest\n'])
+
+ def test_open_file(self):
+ matches = grep(".*unittest$", open(__file__.replace(".pyc", ".py")))
+ self.assertEquals(matches, ['import unittest\n'])
+
+
+class DirTreeTest(unittest.TestCase):
+
+ def test_makes_tree(self):
+ # I'll admit, this a pretty lame test, but it will at least sniff out
+ # some syntax issues
+ 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')