From 1f90719d9d5b42d1c553ecded27a85965ce3197c Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 28 Mar 2013 17:03:04 +0000 Subject: Rename functions and methods in plugins to comply with pep8 There are lots of historical camelCase function and method names in the plugin directory even though pep8 very clearly recommends against these other than for external backwards compatibility. Rename all the camelCased functions and methods and fix up the main sosreport code, examples and tests to use the new names. Fixes Issue #112. Signed-off-by: Bryn M. Reeves --- tests/option_tests.py | 8 +++---- tests/plugin_tests.py | 60 +++++++++++++++++++++++++-------------------------- 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'tests') diff --git a/tests/option_tests.py b/tests/option_tests.py index 03804dec..6114c9b2 100644 --- a/tests/option_tests.py +++ b/tests/option_tests.py @@ -19,16 +19,16 @@ class GlobalOptionTest(unittest.TestCase): self.plugin.optParms = [{'enabled': False}, {'enabled': None}] def test_simple_lookup(self): - self.assertEquals(self.plugin.getOption('test_option'), 'foobar') + self.assertEquals(self.plugin.get_option('test_option'), 'foobar') def test_multi_lookup(self): - self.assertEquals(self.plugin.getOption(('not_there', 'test_option')), 'foobar') + self.assertEquals(self.plugin.get_option(('not_there', 'test_option')), 'foobar') def test_cascade(self): - self.assertEquals(self.plugin.getOption(('baz')), False) + self.assertEquals(self.plugin.get_option(('baz')), False) def test_none_should_cascade(self): - self.assertEquals(self.plugin.getOption(('empty', 'empty_global')), True) + self.assertEquals(self.plugin.get_option(('empty', 'empty_global')), True) if __name__ == "__main__": unittest.main() diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index f01a7a9c..0e7869bb 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -3,7 +3,7 @@ import os import tempfile from StringIO import StringIO -from sos.plugins import Plugin, regex_findall, sosRelPath, mangle_command +from sos.plugins import Plugin, regex_findall, sos_relative_path, mangle_command from sos.utilities import Archive PATH = os.path.dirname(__file__) @@ -72,7 +72,7 @@ class ForbiddenMockPlugin(Plugin): plugin_name = "forbidden" def setup(self): - self.addForbiddenPath("tests") + self.add_forbidden_path("tests") class EnablerPlugin(Plugin): @@ -114,17 +114,17 @@ class PluginToolTests(unittest.TestCase): def test_rel_path(self): path1 = "/usr/lib/foo" path2 = "/usr/lib/boo" - self.assertEquals(sosRelPath(path1, path2), "../boo") + self.assertEquals(sos_relative_path(path1, path2), "../boo") def test_abs_path(self): path1 = "usr/lib/foo" path2 = "foo/lib/boo" - self.assertEquals(sosRelPath(path1, path2), "foo/lib/boo") + self.assertEquals(sos_relative_path(path1, path2), "foo/lib/boo") def test_bad_path(self): path1 = None path2 = "foo/lib/boo" - self.assertEquals(sosRelPath(path1, path2), "foo/lib/boo") + self.assertEquals(sos_relative_path(path1, path2), "foo/lib/boo") def test_mangle_command(self): self.assertEquals("foo", mangle_command("/usr/bin/foo")) @@ -161,27 +161,27 @@ class PluginTests(unittest.TestCase): def test_set_plugin_option(self): p = MockPlugin({}) - p.setOption("opt", "testing") - self.assertEquals(p.getOption("opt"), "testing") + p.set_option("opt", "testing") + self.assertEquals(p.get_option("opt"), "testing") def test_set_nonexistant_plugin_option(self): p = MockPlugin({}) - self.assertFalse(p.setOption("badopt", "testing")) + self.assertFalse(p.set_option("badopt", "testing")) def test_get_nonexistant_plugin_option(self): p = MockPlugin({}) - self.assertEquals(p.getOption("badopt"), 0) + self.assertEquals(p.get_option("badopt"), 0) def test_get_unset_plugin_option(self): p = MockPlugin({}) - self.assertEquals(p.getOption("opt"), 0) + self.assertEquals(p.get_option("opt"), 0) def test_get_unset_plugin_option_with_default(self): # this shows that even when we pass in a default to get, # we'll get the option's default as set in the plugin # this might not be what we really want p = MockPlugin({}) - self.assertEquals(p.getOption("opt", True), True) + self.assertEquals(p.get_option("opt", True), True) def test_get_unset_plugin_option_with_default_not_none(self): # this shows that even when we pass in a default to get, @@ -189,21 +189,21 @@ class PluginTests(unittest.TestCase): # we'll get the option's default as set in the plugin # this might not be what we really want p = MockPlugin({}) - self.assertEquals(p.getOption("opt2", True), False) + self.assertEquals(p.get_option("opt2", True), False) def test_get_option_as_list_plugin_option(self): p = MockPlugin({}) - p.setOption("opt", "one,two,three") - self.assertEquals(p.getOptionAsList("opt"), ['one', 'two', 'three']) + p.set_option("opt", "one,two,three") + self.assertEquals(p.get_option_as_list("opt"), ['one', 'two', 'three']) def test_get_option_as_list_plugin_option_default(self): p = MockPlugin({}) - self.assertEquals(p.getOptionAsList("opt", default=[]), []) + self.assertEquals(p.get_option_as_list("opt", default=[]), []) def test_get_option_as_list_plugin_option_not_list(self): p = MockPlugin({}) - p.setOption("opt", "testing") - self.assertEquals(p.getOptionAsList("opt"), ['testing']) + p.set_option("opt", "testing") + self.assertEquals(p.get_option_as_list("opt"), ['testing']) def test_copy_dir(self): self.mp.doCopyFileOrDir("tests") @@ -236,12 +236,12 @@ class AddCopySpecLimitTests(unittest.TestCase): self.mp.archive = MockArchive() def test_single_file_under_limit(self): - self.mp.addCopySpecLimit("tests/tail_test.txt", 1) + self.mp.add_copy_spec_limit("tests/tail_test.txt", 1) self.assertEquals(self.mp.copyPaths, [('tests/tail_test.txt', None)]) def test_single_file_over_limit(self): fn = create_file(2) # create 2MB file, consider a context manager - self.mp.addCopySpecLimit(fn, 1, sub=('tmp', 'awesome')) + self.mp.add_copy_spec_limit(fn, 1, sub=('tmp', 'awesome')) content, fname = self.mp.copyStrings[0] self.assertTrue("tailed" in fname) self.assertTrue("awesome" in fname) @@ -250,14 +250,14 @@ class AddCopySpecLimitTests(unittest.TestCase): os.unlink(fn) def test_bad_filename(self): - self.assertFalse(self.mp.addCopySpecLimit('', 1)) - self.assertFalse(self.mp.addCopySpecLimit(None, 1)) + self.assertFalse(self.mp.add_copy_spec_limit('', 1)) + self.assertFalse(self.mp.add_copy_spec_limit(None, 1)) def test_glob_file_over_limit(self): # assume these are in /tmp fn = create_file(2) fn2 = create_file(2) - self.mp.addCopySpecLimit("/tmp/tmp*", 1) + self.mp.add_copy_spec_limit("/tmp/tmp*", 1) self.assertEquals(len(self.mp.copyStrings), 1) content, fname = self.mp.copyStrings[0] self.assertTrue("tailed" in fname) @@ -274,21 +274,21 @@ class CheckEnabledTests(unittest.TestCase): def test_checks_for_file(self): f = j("tail_test.txt") self.mp.files = (f,) - self.assertTrue(self.mp.checkenabled()) + self.assertTrue(self.mp.check_enabled()) def test_checks_for_package(self): self.mp.packages = ('foo',) self.mp.is_installed = True - self.assertTrue(self.mp.checkenabled()) + self.assertTrue(self.mp.check_enabled()) def test_allows_bad_tuple(self): f = j("tail_test.txt") self.mp.files = (f) self.mp.packages = ('foo') - self.assertTrue(self.mp.checkenabled()) + self.assertTrue(self.mp.check_enabled()) def test_enabled_by_default(self): - self.assertTrue(self.mp.checkenabled()) + self.assertTrue(self.mp.check_enabled()) class RegexSubTests(unittest.TestCase): @@ -303,14 +303,14 @@ class RegexSubTests(unittest.TestCase): self.assertEquals(0, self.mp.doFileSub("never_copied", r"^(.*)$", "foobar")) def test_no_replacements(self): - self.mp.addCopySpec(j("tail_test.txt")) - self.mp.copyStuff() + self.mp.add_copy_spec(j("tail_test.txt")) + self.mp.copy_stuff() replacements = self.mp.doFileSub(j("tail_test.txt"), r"wont_match", "foobar") self.assertEquals(0, replacements) def test_replacements(self): - self.mp.addCopySpec(j("tail_test.txt")) - self.mp.copyStuff() + self.mp.add_copy_spec(j("tail_test.txt")) + self.mp.copy_stuff() replacements = self.mp.doFileSub(j("tail_test.txt"), r"(tail)", "foobar") self.assertEquals(1, replacements) self.assertTrue("foobar" in self.mp.archive.m.get(j('tail_test.txt'))) -- cgit From 4f0da96964fec5bdc2b66d4117aa9773e5a12a4d Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 28 Mar 2013 17:25:05 +0000 Subject: Rename copy_stuff() to collect() The name copy_stuff() isn't as descriptive now that the data may be being streamed into an archive without being copied into a temporary directory. Calling it collect covers both equally well. Signed-off-by: Bryn M. Reeves --- tests/plugin_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index 0e7869bb..153ff350 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -304,13 +304,13 @@ class RegexSubTests(unittest.TestCase): def test_no_replacements(self): self.mp.add_copy_spec(j("tail_test.txt")) - self.mp.copy_stuff() + self.mp.collect() replacements = self.mp.doFileSub(j("tail_test.txt"), r"wont_match", "foobar") self.assertEquals(0, replacements) def test_replacements(self): self.mp.add_copy_spec(j("tail_test.txt")) - self.mp.copy_stuff() + self.mp.collect() replacements = self.mp.doFileSub(j("tail_test.txt"), r"(tail)", "foobar") self.assertEquals(1, replacements) self.assertTrue("foobar" in self.mp.archive.m.get(j('tail_test.txt'))) -- cgit From 29e180fbc291686ee991952005c84c4b0d216a86 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Thu, 28 Mar 2013 18:08:59 +0000 Subject: Make more names pep8 compliant across the tree Fix policy and utility function, method and variable names to use lower case underscored style instead of camelCase. Related to Issue #112. Signed-off-by: Bryn M. Reeves --- tests/option_tests.py | 4 ++-- tests/plugin_tests.py | 10 +++++----- tests/policy_tests.py | 8 ++++---- tests/utilities_tests.py | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/option_tests.py b/tests/option_tests.py index 6114c9b2..d221b965 100644 --- a/tests/option_tests.py +++ b/tests/option_tests.py @@ -15,8 +15,8 @@ class GlobalOptionTest(unittest.TestCase): }, } self.plugin = Plugin(self.commons) - self.plugin.optNames = ['baz', 'empty'] - self.plugin.optParms = [{'enabled': False}, {'enabled': None}] + self.plugin.opt_names = ['baz', 'empty'] + self.plugin.opt_parms = [{'enabled': False}, {'enabled': None}] def test_simple_lookup(self): self.assertEquals(self.plugin.get_option('test_option'), 'foobar') diff --git a/tests/plugin_tests.py b/tests/plugin_tests.py index 153ff350..09d4c2ac 100644 --- a/tests/plugin_tests.py +++ b/tests/plugin_tests.py @@ -50,7 +50,7 @@ class MockArchive(Archive): class MockPlugin(Plugin): - optionList = [("opt", 'an option', 'fast', None), + option_list = [("opt", 'an option', 'fast', None), ("opt2", 'another option', 'fast', False)] def setup(self): @@ -237,12 +237,12 @@ class AddCopySpecLimitTests(unittest.TestCase): def test_single_file_under_limit(self): self.mp.add_copy_spec_limit("tests/tail_test.txt", 1) - self.assertEquals(self.mp.copyPaths, [('tests/tail_test.txt', None)]) + self.assertEquals(self.mp.copy_paths, [('tests/tail_test.txt', None)]) def test_single_file_over_limit(self): fn = create_file(2) # create 2MB file, consider a context manager self.mp.add_copy_spec_limit(fn, 1, sub=('tmp', 'awesome')) - content, fname = self.mp.copyStrings[0] + content, fname = self.mp.copy_strings[0] self.assertTrue("tailed" in fname) self.assertTrue("awesome" in fname) self.assertTrue("/" not in fname) @@ -258,8 +258,8 @@ class AddCopySpecLimitTests(unittest.TestCase): fn = create_file(2) fn2 = create_file(2) self.mp.add_copy_spec_limit("/tmp/tmp*", 1) - self.assertEquals(len(self.mp.copyStrings), 1) - content, fname = self.mp.copyStrings[0] + self.assertEquals(len(self.mp.copy_strings), 1) + content, fname = self.mp.copy_strings[0] self.assertTrue("tailed" in fname) self.assertEquals(1024 * 1024, len(content)) os.unlink(fn) diff --git a/tests/policy_tests.py b/tests/policy_tests.py index 25795a1c..aa74da7d 100644 --- a/tests/policy_tests.py +++ b/tests/policy_tests.py @@ -54,16 +54,16 @@ class PackageManagerTests(unittest.TestCase): self.pm = PackageManager() def test_default_all_pkgs(self): - self.assertEquals(self.pm.allPkgs(), {}) + self.assertEquals(self.pm.all_pkgs(), {}) def test_default_all_pkgs_by_name(self): - self.assertEquals(self.pm.allPkgsByName('doesntmatter'), []) + self.assertEquals(self.pm.all_pkgs_by_name('doesntmatter'), []) def test_default_all_pkgs_by_name_regex(self): - self.assertEquals(self.pm.allPkgsByNameRegex('.*doesntmatter$'), []) + self.assertEquals(self.pm.all_pkgs_by_name_regex('.*doesntmatter$'), []) def test_default_pkg_by_name(self): - self.assertEquals(self.pm.pkgByName('foo'), None) + self.assertEquals(self.pm.pkg_by_name('foo'), None) if __name__ == "__main__": unittest.main() diff --git a/tests/utilities_tests.py b/tests/utilities_tests.py index 7b5a6a3b..5520bb16 100644 --- a/tests/utilities_tests.py +++ b/tests/utilities_tests.py @@ -2,7 +2,7 @@ import os.path import unittest from StringIO import StringIO -from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sosGetCommandOutput, find, tail, shell_out +from sos.utilities import grep, DirTree, checksum, get_hash_name, is_executable, sos_get_command_output, find, tail, shell_out import sos TEST_DIR = os.path.dirname(__file__) @@ -76,13 +76,13 @@ class ExecutableTest(unittest.TestCase): def test_output(self): path = os.path.join(TEST_DIR, 'test_exe.py') - ret, out, junk = sosGetCommandOutput(path) + ret, out, junk = sos_get_command_output(path) self.assertEquals(ret, 0) self.assertEquals(out, "executed\n") def test_output_non_exe(self): path = os.path.join(TEST_DIR, 'utility_tests.py') - ret, out, junk = sosGetCommandOutput(path) + ret, out, junk = sos_get_command_output(path) self.assertEquals(ret, 127) self.assertEquals(out, "") -- cgit