aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Quigley <code@bryanquigley.com>2020-08-11 17:05:37 -0700
committerJake Hunsaker <jhunsake@redhat.com>2020-08-13 10:14:16 -0400
commita80825dbb9e28306d9d2dac8114f00f03cce0c9a (patch)
treefe41aa8d78fdc91e6b058fe070ecac4556d63182
parent1ec1bcc94f7e51fd934d851c215e6fddeb3102ad (diff)
downloadsos-a80825dbb9e28306d9d2dac8114f00f03cce0c9a.tar.gz
[travis,style] Upgrade to 20.04 and cover more in tests
Signed-off-by: Bryan Quigley <code@bryanquigley.com> Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--.travis.yml12
-rwxr-xr-xbin/sos-collector4
-rw-r--r--sos/report/plugins/libraries.py4
-rw-r--r--sos/report/plugins/npm.py4
-rw-r--r--tests/archive_tests.py1
-rw-r--r--tests/importer_tests.py2
-rw-r--r--tests/plugin_tests.py53
-rw-r--r--tests/policy_tests.py12
-rw-r--r--tests/report_tests.py50
-rw-r--r--tests/sosreport_pexpect.py2
-rw-r--r--tests/utilities_tests.py11
11 files changed, 95 insertions, 60 deletions
diff --git a/.travis.yml b/.travis.yml
index fb0a538e..bf225c93 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,13 +1,19 @@
jobs:
include:
- - name: "18.04 pycodestyle and native run (py3.6)"
+ - name: "20.04 pycodestyle and native run (py3.8)"
os: linux
- dist: bionic
+ dist: focal
language: shell
install: sudo apt-get update; sudo apt install pycodestyle python3-pexpect;
script:
- - "pycodestyle sos"
+ - "pycodestyle sos tests bin/*"
- "sudo ./tests/simple.sh"
+ - name: "18.04 pycodestyle and native run (py3.6)"
+ os: linux
+ dist: bionic
+ language: shell
+ install: sudo apt-get update; sudo apt install pycodestyle python3-pexpect;
+ script: "sudo ./tests/simple.sh"
- name: "18.04 native run for arm64"
os: linux
dist: bionic
diff --git a/bin/sos-collector b/bin/sos-collector
index 17a4800f..df2c9774 100755
--- a/bin/sos-collector
+++ b/bin/sos-collector
@@ -22,8 +22,8 @@ except KeyboardInterrupt:
raise SystemExit()
if __name__ == '__main__':
- msg = ("Please note the 'sos-collector' command has been deprecated in favor "
- "of the new 'sos' command, E.G. 'sos collect'.\n"
+ msg = ("Please note the 'sos-collector' command has been deprecated in "
+ " favor of the new 'sos' command, E.G. 'sos collect'.\n"
"Redirecting to 'sos collect %s'" % (' '.join(sys.argv[1:]) or ''))
print(msg)
time.sleep(0.5)
diff --git a/sos/report/plugins/libraries.py b/sos/report/plugins/libraries.py
index 21059464..ed52ad2b 100644
--- a/sos/report/plugins/libraries.py
+++ b/sos/report/plugins/libraries.py
@@ -36,8 +36,8 @@ class Libraries(Plugin, RedHatPlugin, UbuntuPlugin):
if ldconfig['status'] == 0:
# Collect library directories from ldconfig's cache
dirs = set()
- for l in ldconfig['output'].splitlines():
- s = l.split(" => ", 2)
+ for lib in ldconfig['output'].splitlines():
+ s = lib.split(" => ", 2)
if len(s) != 2:
continue
dirs.add(s[1].rsplit('/', 1)[0])
diff --git a/sos/report/plugins/npm.py b/sos/report/plugins/npm.py
index 5c6c5ccb..d4c15987 100644
--- a/sos/report/plugins/npm.py
+++ b/sos/report/plugins/npm.py
@@ -60,8 +60,8 @@ class Npm(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin, SuSEPlugin):
user_cache = self.collect_cmd_output("npm cache ls", chroot=False)
if user_cache['status'] == 0:
# filter out dirs with .cache.json ('registry.npmjs.org')
- for package in [l for l in user_cache['output'].splitlines()
- if l.endswith('package.tgz')]:
+ for package in [line for line in user_cache['output'].splitlines()
+ if line.endswith('package.tgz')]:
five_tuple = package.split(os.path.sep)
if len(five_tuple) != 5: # sanity check
continue
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'])