diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/archive_tests.py | 1 | ||||
-rw-r--r-- | tests/importer_tests.py | 2 | ||||
-rw-r--r-- | tests/plugin_tests.py | 53 | ||||
-rw-r--r-- | tests/policy_tests.py | 12 | ||||
-rw-r--r-- | tests/report_tests.py | 50 | ||||
-rw-r--r-- | tests/sosreport_pexpect.py | 2 | ||||
-rw-r--r-- | tests/utilities_tests.py | 11 |
7 files changed, 80 insertions, 51 deletions
diff --git a/tests/archive_tests.py b/tests/archive_tests.py index d890d12f..7bc9ef15 100644 --- a/tests/archive_tests.py +++ b/tests/archive_tests.py @@ -61,7 +61,6 @@ class TarFileArchiveTest(unittest.TestCase): self.tf.add_string(self.copy_strings[0][0], 'tests/string_test.txt') self.tf.finalize('auto') - # Since commit 179d9bb add_file does not support recursive directory # addition. Disable this test for now. # def test_add_dir(self): diff --git a/tests/importer_tests.py b/tests/importer_tests.py index cbac1d94..a2dddaba 100644 --- a/tests/importer_tests.py +++ b/tests/importer_tests.py @@ -9,6 +9,7 @@ import unittest from sos.utilities import ImporterHelper + class ImporterHelperTests(unittest.TestCase): def test_runs(self): @@ -16,6 +17,7 @@ class ImporterHelperTests(unittest.TestCase): modules = h.get_modules() self.assertTrue('main' in modules) + if __name__ == "__main__": unittest.main() diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index 39705599..2e2e6abd 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -19,15 +19,18 @@ import sos.policies PATH = os.path.dirname(__file__) + def j(filename): return os.path.join(PATH, filename) + def create_file(size, dir=None): - f = tempfile.NamedTemporaryFile(delete=False, dir=dir) - f.write(b"*" * size * 1024 * 1024) - f.flush() - f.close() - return f.name + f = tempfile.NamedTemporaryFile(delete=False, dir=dir) + f.write(b"*" * size * 1024 * 1024) + f.flush() + f.close() + return f.name + class MockArchive(TarFileArchive): @@ -62,7 +65,7 @@ class MockArchive(TarFileArchive): class MockPlugin(Plugin): option_list = [("opt", 'an option', 'fast', None), - ("opt2", 'another option', 'fast', False)] + ("opt2", 'another option', 'fast', False)] def setup(self): pass @@ -117,13 +120,15 @@ class MockOptions(object): class PluginToolTests(unittest.TestCase): def test_regex_findall(self): - test_s = u"\n".join(['this is only a test', 'there are only two lines']) + test_s = u"\n".join( + ['this is only a test', 'there are only two lines']) test_fo = StringIO(test_s) matches = regex_findall(r".*lines$", test_fo) self.assertEquals(matches, ['there are only two lines']) def test_regex_findall_miss(self): - test_s = u"\n".join(['this is only a test', 'there are only two lines']) + test_s = u"\n".join( + ['this is only a test', 'there are only two lines']) test_fo = StringIO(test_s) matches = regex_findall(r".*not_there$", test_fo) self.assertEquals(matches, []) @@ -139,10 +144,14 @@ class PluginToolTests(unittest.TestCase): def test_mangle_command(self): name_max = 255 self.assertEquals("foo", _mangle_command("/usr/bin/foo", name_max)) - self.assertEquals("foo_-x", _mangle_command("/usr/bin/foo -x", name_max)) - self.assertEquals("foo_--verbose", _mangle_command("/usr/bin/foo --verbose", name_max)) - self.assertEquals("foo_.path.to.stuff", _mangle_command("/usr/bin/foo /path/to/stuff", name_max)) - longcmd ="foo is " + "a" * 256 + " long_command" + self.assertEquals( + "foo_-x", _mangle_command("/usr/bin/foo -x", name_max)) + self.assertEquals( + "foo_--verbose", _mangle_command("/usr/bin/foo --verbose", + name_max)) + self.assertEquals("foo_.path.to.stuff", _mangle_command( + "/usr/bin/foo /path/to/stuff", name_max)) + longcmd = "foo is " + "a" * 256 + " long_command" expected = longcmd[0:name_max].replace(' ', '_') self.assertEquals(expected, _mangle_command(longcmd, name_max)) @@ -194,7 +203,8 @@ class PluginTests(unittest.TestCase): 'cmdlineopts': MockOptions(), 'devices': {} }) - self.assertEquals(p.get_description(), "This plugin has a description.") + self.assertEquals(p.get_description(), + "This plugin has a description.") def test_set_plugin_option(self): p = MockPlugin({ @@ -289,7 +299,9 @@ class PluginTests(unittest.TestCase): def test_copy_dir(self): self.mp._do_copy_path("tests") - self.assertEquals(self.mp.archive.m["tests/plugin_tests.py"], 'tests/plugin_tests.py') + self.assertEquals( + self.mp.archive.m["tests/plugin_tests.py"], + 'tests/plugin_tests.py') def test_copy_dir_bad_path(self): self.mp._do_copy_path("not_here_tests") @@ -340,7 +352,6 @@ class AddCopySpecTests(unittest.TestCase): expected_paths = set(map(pathmunge, self.expect_paths)) self.assertEquals(self.mp.copy_paths, expected_paths) - def test_single_file_no_limit(self): self.mp.add_copy_spec("tests/tail_test.txt") self.assert_expect_paths() @@ -351,7 +362,7 @@ class AddCopySpecTests(unittest.TestCase): def test_single_file_over_limit(self): self.mp.sysroot = '/' - fn = create_file(2) # create 2MB file, consider a context manager + fn = create_file(2) # create 2MB file, consider a context manager self.mp.add_copy_spec(fn, 1) content, fname = self.mp.copy_strings[0] self.assertTrue("tailed" in fname) @@ -440,12 +451,14 @@ class RegexSubTests(unittest.TestCase): self.mp.archive = MockArchive() def test_file_never_copied(self): - self.assertEquals(0, self.mp.do_file_sub("never_copied", r"^(.*)$", "foobar")) + self.assertEquals(0, self.mp.do_file_sub( + "never_copied", r"^(.*)$", "foobar")) def test_no_replacements(self): self.mp.add_copy_spec(j("tail_test.txt")) self.mp.collect() - replacements = self.mp.do_file_sub(j("tail_test.txt"), r"wont_match", "foobar") + replacements = self.mp.do_file_sub( + j("tail_test.txt"), r"wont_match", "foobar") self.assertEquals(0, replacements) def test_replacements(self): @@ -453,10 +466,12 @@ class RegexSubTests(unittest.TestCase): self.mp.sysroot = '/' self.mp.add_copy_spec(j("tail_test.txt")) self.mp.collect() - replacements = self.mp.do_file_sub(j("tail_test.txt"), r"(tail)", "foobar") + replacements = self.mp.do_file_sub( + j("tail_test.txt"), r"(tail)", "foobar") self.assertEquals(1, replacements) self.assertTrue("foobar" in self.mp.archive.m.get(j('tail_test.txt'))) + if __name__ == "__main__": unittest.main() diff --git a/tests/policy_tests.py b/tests/policy_tests.py index 69cc0529..263ea352 100644 --- a/tests/policy_tests.py +++ b/tests/policy_tests.py @@ -8,20 +8,26 @@ import unittest from sos.policies import Policy, PackageManager, import_policy -from sos.report.plugins import Plugin, IndependentPlugin, RedHatPlugin, DebianPlugin +from sos.report.plugins import (Plugin, IndependentPlugin, + RedHatPlugin, DebianPlugin) + class FauxPolicy(Policy): distro = "Faux" + class FauxPlugin(Plugin, IndependentPlugin): pass + class FauxRedHatPlugin(Plugin, RedHatPlugin): pass + class FauxDebianPlugin(Plugin, DebianPlugin): pass + class PolicyTests(unittest.TestCase): def test_independent_only(self): @@ -67,11 +73,13 @@ class PackageManagerTests(unittest.TestCase): self.assertEquals(self.pm.all_pkgs_by_name('doesntmatter'), []) def test_default_all_pkgs_by_name_regex(self): - self.assertEquals(self.pm.all_pkgs_by_name_regex('.*doesntmatter$'), []) + self.assertEquals( + self.pm.all_pkgs_by_name_regex('.*doesntmatter$'), []) def test_default_pkg_by_name(self): self.assertEquals(self.pm.pkg_by_name('foo'), None) + if __name__ == "__main__": unittest.main() diff --git a/tests/report_tests.py b/tests/report_tests.py index 3418f16e..86d56e7e 100644 --- a/tests/report_tests.py +++ b/tests/report_tests.py @@ -13,8 +13,8 @@ try: except ImportError: import simplejson as json -from sos.report.reporting import (Report, Section, Command, CopiedFile, CreatedFile, - Alert, PlainTextReport) +from sos.report.reporting import (Report, Section, Command, CopiedFile, + CreatedFile, Alert, PlainTextReport) class ReportTest(unittest.TestCase): @@ -94,13 +94,13 @@ class TestPlainReport(unittest.TestCase): self.report.add(section1, section2) self.assertEquals(u''.join([ - self.pluglist.format(pluglist=" first second"), - self.div, - "\nfirst", - self.div, - "\nsecond" - ]), - PlainTextReport(self.report).unicode()) + self.pluglist.format(pluglist=" first second"), + self.div, + "\nfirst", + self.div, + "\nsecond" + ]), + PlainTextReport(self.report).unicode()) def test_command(self): cmd = Command(name="ls -al /foo/bar/baz", @@ -110,10 +110,10 @@ class TestPlainReport(unittest.TestCase): self.report.add(self.section) self.assertEquals(u''.join([ - self.defaultheader, - "- commands executed:\n * ls -al /foo/bar/baz" - ]), - PlainTextReport(self.report).unicode()) + self.defaultheader, + "- commands executed:\n * ls -al /foo/bar/baz" + ]), + PlainTextReport(self.report).unicode()) def test_copied_file(self): cf = CopiedFile(name="/etc/hosts", href="etc/hosts") @@ -121,10 +121,10 @@ class TestPlainReport(unittest.TestCase): self.report.add(self.section) self.assertEquals(u''.join([ - self.defaultheader, - "- files copied:\n * /etc/hosts" - ]), - PlainTextReport(self.report).unicode()) + self.defaultheader, + "- files copied:\n * /etc/hosts" + ]), + PlainTextReport(self.report).unicode()) def test_created_file(self): crf = CreatedFile(name="sample.txt", @@ -133,10 +133,10 @@ class TestPlainReport(unittest.TestCase): self.report.add(self.section) self.assertEquals(u''.join([ - self.defaultheader, - "- files created:\n * sample.txt" - ]), - PlainTextReport(self.report).unicode()) + self.defaultheader, + "- files created:\n * sample.txt" + ]), + PlainTextReport(self.report).unicode()) def test_alert(self): alrt = Alert("this is an alert") @@ -144,10 +144,10 @@ class TestPlainReport(unittest.TestCase): self.report.add(self.section) self.assertEquals(u''.join([ - self.defaultheader, - "- alerts:\n ! this is an alert" - ]), - PlainTextReport(self.report).unicode()) + self.defaultheader, + "- alerts:\n ! this is an alert" + ]), + PlainTextReport(self.report).unicode()) if __name__ == "__main__": diff --git a/tests/sosreport_pexpect.py b/tests/sosreport_pexpect.py index f867cffc..095b6f1b 100644 --- a/tests/sosreport_pexpect.py +++ b/tests/sosreport_pexpect.py @@ -12,6 +12,7 @@ from re import search, escape from os import kill from signal import SIGINT + class PexpectTest(unittest.TestCase): def test_plugins_install(self): sos = pexpect.spawn('/usr/sbin/sosreport -l') @@ -29,6 +30,7 @@ class PexpectTest(unittest.TestCase): self.assertEquals(grp, 0) kill(sos.pid, SIGINT) + if __name__ == '__main__': unittest.main() diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py index fa861563..64be9f1e 100644 --- a/tests/utilities_tests.py +++ b/tests/utilities_tests.py @@ -11,15 +11,17 @@ import unittest # PYCOMPAT from io import StringIO -from sos.utilities import grep, is_executable, sos_get_command_output, find, tail, shell_out -import sos +from sos.utilities import (grep, is_executable, sos_get_command_output, + find, tail, shell_out) TEST_DIR = os.path.dirname(__file__) + class GrepTest(unittest.TestCase): def test_file_obj(self): - test_s = u"\n".join(['this is only a test', 'there are only two lines']) + test_s = u"\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']) @@ -33,7 +35,8 @@ class GrepTest(unittest.TestCase): self.assertEquals(matches, ['import unittest\n']) def test_grep_multiple_files(self): - matches = grep(".*unittest$", __file__.replace(".pyc", ".py"), "does_not_exist.txt") + matches = grep(".*unittest$", + __file__.replace(".pyc", ".py"), "does_not_exist.txt") self.assertEquals(matches, ['import unittest\n']) |