diff options
| author | Michael Vogt <mvo@debian.org> | 2013-12-31 23:25:13 +0100 |
|---|---|---|
| committer | Michael Vogt <mvo@debian.org> | 2014-01-05 20:04:30 +0100 |
| commit | 3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e (patch) | |
| tree | 75ad948c351605fd7ac50b176f1149c4e2a513e4 /tests | |
| parent | e3c26754af1891d2c50993730467fc9335ec5f09 (diff) | |
| download | python-apt-3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e.tar.gz | |
make test_pep8.py pass
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/old/__init__.py | 1 | ||||
| -rw-r--r-- | tests/old/cache.py | 4 | ||||
| -rw-r--r-- | tests/old/depcache.py | 6 | ||||
| -rw-r--r-- | tests/old/pkgproblemresolver.py | 6 | ||||
| -rw-r--r-- | tests/old/pkgrecords.py | 2 | ||||
| -rw-r--r-- | tests/old/pkgsrcrecords.py | 2 | ||||
| -rwxr-xr-x | tests/old/refcount.py | 5 | ||||
| -rw-r--r-- | tests/test_all.py | 9 | ||||
| -rw-r--r-- | tests/test_apt_cache.py | 43 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 12 | ||||
| -rw-r--r-- | tests/test_auth.py | 11 | ||||
| -rw-r--r-- | tests/test_configuration.py | 5 | ||||
| -rw-r--r-- | tests/test_debfile.py | 30 | ||||
| -rw-r--r-- | tests/test_debfile_multiarch.py | 7 | ||||
| -rw-r--r-- | tests/test_group.py | 1 | ||||
| -rw-r--r-- | tests/test_hashes.py | 2 | ||||
| -rw-r--r-- | tests/test_lp659438.py | 2 | ||||
| -rw-r--r-- | tests/test_paths.py | 10 | ||||
| -rwxr-xr-x | tests/test_pep8.py | 2 | ||||
| -rw-r--r-- | tests/test_policy.py | 2 | ||||
| -rw-r--r-- | tests/test_progress.py | 5 | ||||
| -rw-r--r-- | tests/test_size_to_str.py | 136 | ||||
| -rw-r--r-- | tests/test_tagfile.py | 1 | ||||
| -rw-r--r-- | tests/test_utils.py | 22 |
24 files changed, 176 insertions, 150 deletions
diff --git a/tests/old/__init__.py b/tests/old/__init__.py index afd0f074..e93c0b65 100644 --- a/tests/old/__init__.py +++ b/tests/old/__init__.py @@ -2,7 +2,6 @@ import os import unittest - if __name__ == '__main__': os.chdir(os.path.dirname(__file__)) print os.getcwd() diff --git a/tests/old/cache.py b/tests/old/cache.py index 11156c00..5cbf19d9 100644 --- a/tests/old/cache.py +++ b/tests/old/cache.py @@ -12,8 +12,8 @@ def main(): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() - i=0 - all=cache.package_count + i = 0 + all = cache.package_count print "Running Cache test on all packages:" # first, get all pkgs for pkg in cache.packages: diff --git a/tests/old/depcache.py b/tests/old/depcache.py index cc030ed0..67a47503 100644 --- a/tests/old/depcache.py +++ b/tests/old/depcache.py @@ -12,8 +12,8 @@ def main(): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() - i=0 - all=cache.package_count + i = 0 + all = cache.package_count print "Running DepCache test on all packages" print "(trying to install each and then mark it keep again):" # first, get all pkgs @@ -21,7 +21,7 @@ def main(): i += 1 x = pkg.name # then get each version - ver =depcache.get_candidate_ver(pkg) + ver = depcache.get_candidate_ver(pkg) if ver is not None: depcache.mark_install(pkg) if depcache.inst_count == 0: diff --git a/tests/old/pkgproblemresolver.py b/tests/old/pkgproblemresolver.py index 7714c882..feaa3cb1 100644 --- a/tests/old/pkgproblemresolver.py +++ b/tests/old/pkgproblemresolver.py @@ -12,8 +12,8 @@ def main(): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() - i=0 - all=cache.package_count + i = 0 + all = cache.package_count print "Running DepCache test on all packages" print "(trying to install each and then mark it keep again):" # first, get all pkgs @@ -21,7 +21,7 @@ def main(): i += 1 x = pkg.name # then get each version - ver =depcache.get_candidate_ver(pkg) + ver = depcache.get_candidate_ver(pkg) if ver is not None: depcache.mark_install(pkg) if depcache.broken_count > 0: diff --git a/tests/old/pkgrecords.py b/tests/old/pkgrecords.py index 9e06d44c..3f253bf3 100644 --- a/tests/old/pkgrecords.py +++ b/tests/old/pkgrecords.py @@ -13,7 +13,7 @@ def main(): cache = apt_pkg.Cache() depcache = apt_pkg.DepCache(cache) depcache.init() - i=0 + i = 0 print "Running PkgRecords test on all packages:" for pkg in cache.packages: i += 1 diff --git a/tests/old/pkgsrcrecords.py b/tests/old/pkgsrcrecords.py index 36790eff..42b545ed 100644 --- a/tests/old/pkgsrcrecords.py +++ b/tests/old/pkgsrcrecords.py @@ -11,7 +11,7 @@ import sys def main(): apt_pkg.init() cache = apt_pkg.Cache() - i=0 + i = 0 print "Running PkgSrcRecords test on all packages:" for x in cache.packages: i += 1 diff --git a/tests/old/refcount.py b/tests/old/refcount.py index a80595c9..70adc0c1 100755 --- a/tests/old/refcount.py +++ b/tests/old/refcount.py @@ -1,14 +1,13 @@ #!/usr/bin/python-dbg -from pprint import pprint, pformat +from pprint import pprint import apt import sys import gc -import difflib # get initial cache print sys.gettotalrefcount() -progress= apt.progress.OpTextProgress() +progress = apt.progress.OpTextProgress() c = apt.Cache(progress) print "refcount after first cache instance: ", sys.gettotalrefcount() diff --git a/tests/test_all.py b/tests/test_all.py index 25774617..de6cb0c0 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -11,19 +11,21 @@ import sys try: import unittest.runner import unittest + unittest # pyflakes except ImportError: # py2.6 compat import unittest2 as unittest # workaround for py3.2 that apparently does not have this anymore -# it has "abiflags" +# it has "abiflags" if not hasattr(sys, "pydebug"): if sys.abiflags.startswith("d"): sys.pydebug = True else: sys.pydebug = False + def get_library_dir(): # Find the path to the built apt_pkg and apt_inst extensions if not os.path.exists("../build"): @@ -40,14 +42,17 @@ def get_library_dir(): plat_specifier) return os.path.abspath(library_dir) + class MyTestRunner(unittest.runner.TextTestRunner): def __init__(self, *args, **kwargs): kwargs["stream"] = sys.stdout super(MyTestRunner, self).__init__(*args, **kwargs) + if __name__ == '__main__': if not os.access("/etc/apt/sources.list", os.R_OK): - sys.stdout.write("[tests] Skipping because sources.list is not readable\n") + sys.stdout.write( + "[tests] Skipping because sources.list is not readable\n") sys.exit(0) sys.stdout.write("[tests] Running on %s\n" % sys.version.replace("\n", "")) diff --git a/tests/test_apt_cache.py b/tests/test_apt_cache.py index 9940374f..ee4fc50b 100644 --- a/tests/test_apt_cache.py +++ b/tests/test_apt_cache.py @@ -18,6 +18,7 @@ import unittest if sys.version_info[0] == 2 and sys.version_info[1] == 6: from unittest2 import TestCase + TestCase # pyflakes else: from unittest import TestCase @@ -36,7 +37,8 @@ def if_sources_list_is_readable(f): if os.access("/etc/apt/sources.list", os.R_OK): f(*args, **kwargs) else: - logging.warning("skipping '%s' because sources.list is not readable" % f) + logging.warning( + "skipping '%s' because sources.list is not readable" % f) return wrapper @@ -124,20 +126,23 @@ class TestAptCache(TestCase): cache = apt.Cache(rootdir="./data/test-provides/") cache.open() if len(cache) == 0: - logging.warning("skipping test_get_provided_packages, cache empty?!?") + logging.warning( + "skipping test_get_provided_packages, cache empty?!?") return # a true virtual pkg l = cache.get_providing_packages("mail-transport-agent") self.assertTrue(len(l) > 0) self.assertTrue("postfix" in [p.name for p in l]) - self.assertTrue("mail-transport-agent" in cache["postfix"].candidate.provides) + self.assertTrue( + "mail-transport-agent" in cache["postfix"].candidate.provides) def test_low_level_pkg_provides(self): apt.apt_pkg.config.set("Apt::architecture", "i386") # create highlevel cache and get the lowlevel one from it highlevel_cache = apt.Cache(rootdir="./data/test-provides") if len(highlevel_cache) == 0: - logging.warning("skipping test_log_level_pkg_provides, cache empty?!?") + logging.warning( + "skipping test_log_level_pkg_provides, cache empty?!?") return # low level cache provides list of the pkg cache = highlevel_cache._cache @@ -150,24 +155,24 @@ class TestAptCache(TestCase): break else: self.assertNotReached() - + @if_sources_list_is_readable def test_dpkg_journal_dirty(self): # create tmp env tmpdir = tempfile.mkdtemp() - dpkg_dir = os.path.join(tmpdir,"var","lib","dpkg") - os.makedirs(os.path.join(dpkg_dir,"updates")) - open(os.path.join(dpkg_dir,"status"), "w").close() + dpkg_dir = os.path.join(tmpdir, "var", "lib", "dpkg") + os.makedirs(os.path.join(dpkg_dir, "updates")) + open(os.path.join(dpkg_dir, "status"), "w").close() apt_pkg.config.set("Dir::State::status", - os.path.join(dpkg_dir,"status")) + os.path.join(dpkg_dir, "status")) cache = apt.Cache() # test empty self.assertFalse(cache.dpkg_journal_dirty) # that is ok, only [0-9] are dpkg jounral entries - open(os.path.join(dpkg_dir,"updates","xxx"), "w").close() - self.assertFalse(cache.dpkg_journal_dirty) + open(os.path.join(dpkg_dir, "updates", "xxx"), "w").close() + self.assertFalse(cache.dpkg_journal_dirty) # that is a dirty journal - open(os.path.join(dpkg_dir,"updates","000"), "w").close() + open(os.path.join(dpkg_dir, "updates", "000"), "w").close() self.assertTrue(cache.dpkg_journal_dirty) @if_sources_list_is_readable @@ -209,29 +214,29 @@ class TestAptCache(TestCase): # update a single sources.list cache = apt.Cache() cache.update(sources_list=sources_list) - # verify we just got the excpected package file + # verify we just got the excpected package file needle_packages = glob.glob( - lists_dir+"/*tests_data_test-repo_Packages*") + lists_dir + "/*tests_data_test-repo_Packages*") self.assertEqual(len(needle_packages), 1) # verify that we *only* got the Packages file from a single source - all_packages = glob.glob(lists_dir+"/*_Packages*") + all_packages = glob.glob(lists_dir + "/*_Packages*") self.assertEqual(needle_packages, all_packages) # verify that the listcleaner was not run and the marker file is # still there self.assertTrue("marker" in os.listdir(lists_dir)) - # now run update again (without the "normal" sources.list that # contains test-repo2 and verify that we got the normal sources.list cache.update() - needle_packages = glob.glob(lists_dir+"/*tests_data_test-repo2_Packages*") + needle_packages = glob.glob( + lists_dir + "/*tests_data_test-repo2_Packages*") self.assertEqual(len(needle_packages), 1) - all_packages = glob.glob(lists_dir+"/*_Packages*") + all_packages = glob.glob(lists_dir + "/*_Packages*") self.assertEqual(needle_packages, all_packages) # and another update with a single source only cache = apt.Cache() cache.update(sources_list=sources_list) - all_packages = glob.glob(lists_dir+"/*_Packages*") + all_packages = glob.glob(lists_dir + "/*_Packages*") self.assertEqual(len(all_packages), 2) apt_pkg.config.set("dir::state", old_state) apt_pkg.config.set("dir::etc::sourcelist", old_source_list) diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 0b74cb79..4539b2d1 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -70,7 +70,6 @@ class TestAptSources(unittest.TestCase): ["main"], architectures=["amd64", "i386"]) self.assertTrue(sources.list == before.list) - # test to add something new: multiverse sources.add("deb", "http://de.archive.ubuntu.com/ubuntu/", "edgy", @@ -150,8 +149,7 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list") sources = aptsources.sourceslist.SourcesList(True, self.templates) - - assert sources.list[8].invalid == False + assert sources.list[8].invalid is False assert sources.list[8].type == "deb" assert sources.list[8].architectures == ["amd64", "i386"] assert sources.list[8].uri == "http://de.archive.ubuntu.com/ubuntu/" @@ -166,11 +164,11 @@ class TestAptSources(unittest.TestCase): apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" "sources.list") sources = aptsources.sourceslist.SourcesList(True, self.templates) - - assert sources.list[9].invalid == False + assert sources.list[9].invalid is False assert sources.list[9].type == "deb" assert sources.list[9].architectures == ["amd64", "i386"] - self.assertEqual( sources.list[9].uri, "http://de.archive.ubuntu.com/ubuntu/") + self.assertEqual( + sources.list[9].uri, "http://de.archive.ubuntu.com/ubuntu/") assert sources.list[9].dist == "natty" assert sources.list[9].comps == ["main"] assert sources.list[9].trusted @@ -198,7 +196,7 @@ class TestAptSources(unittest.TestCase): comps = comps.union(set(entry.comps)) self.assertTrue("multiverse" in comps) self.assertTrue("universe" in comps) - + def testDistribution(self): """aptsources: Test distribution detection.""" apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" diff --git a/tests/test_auth.py b/tests/test_auth.py index bc353427..a9cfe736 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -15,6 +15,8 @@ import unittest if sys.version_info[0] > 2: from http.server import HTTPServer from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler + HTTPServer # pyflakes + HTTPRequestHandler # pyflakes else: from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler @@ -22,6 +24,7 @@ else: if sys.version_info[0] == 2 and sys.version_info[1] == 6: from unittest2 import TestCase + TestCase # pyflakes else: from unittest import TestCase @@ -215,7 +218,8 @@ class TestAuthKeys(TestCase): def test_add_key_from_keyserver_too_short(self): """Ensure that short keyids are not imported""" with self.assertRaises(apt.auth.AptKeyError): - apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191") + apt.auth.add_key_from_keyserver( + "46925553", "hkp://localhost:19191") def test_add_key_from_server_mitm(self): """Verify that the key fingerprint is verified after download""" @@ -227,7 +231,8 @@ class TestAuthKeys(TestCase): "0101010178F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) self.assertTrue( - str(cm.exception).startswith("Fingerprints do not match"), cm.exception) + str(cm.exception).startswith("Fingerprints do not match"), + cm.exception) def testAddKeyFromServer(self): """Install a GnuPG key from a remote server.""" @@ -236,7 +241,7 @@ class TestAuthKeys(TestCase): with self._discard_stderr(): apt.auth.add_key_from_keyserver( - "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", + "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553", "hkp://localhost:%d" % self.keyserver_port) ret = apt.auth.list_keys() diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 80509cff..adf33719 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -7,7 +7,6 @@ # notice and this notice are preserved. """Unit tests for verifying the correctness of apt_pkg.Configuration""" import unittest - import apt_pkg @@ -21,9 +20,9 @@ class TestConfiguration(unittest.TestCase): def test_lp707416(self): """configuration: Test empty arguments (LP: #707416)""" self.assertRaises(ValueError, apt_pkg.parse_commandline, - apt_pkg.config,[], []) + apt_pkg.config, [], []) self.assertRaises(SystemError, apt_pkg.parse_commandline, - apt_pkg.config,[], ["cmd", "--arg0"]) + apt_pkg.config, [], ["cmd", "--arg0"]) if __name__ == "__main__": diff --git a/tests/test_debfile.py b/tests/test_debfile.py index 9379884a..ec3bf518 100644 --- a/tests/test_debfile.py +++ b/tests/test_debfile.py @@ -19,6 +19,7 @@ if libdir: import apt_pkg import apt.debfile + class TestDebfile(unittest.TestCase): """ test the debfile """ @@ -32,31 +33,31 @@ class TestDebfile(unittest.TestCase): # Conflicts: apt (<= 0.1) ('gdebi-test4.deb', True), # Conflicts: apt (>= 0.1) - ('gdebi-test5.deb', False), + ('gdebi-test5.deb', False), # invalid unicode in descr ('gdebi-test6.deb', True), # provides/conflicts against "foobarbaz" ('gdebi-test7.deb', True), # provides/conflicts/replaces against "mail-transport-agent" # (should fails if mail-transport-agent is installed) - ('gdebi-test8.deb', False), + ('gdebi-test8.deb', False), # provides/conflicts against real pkg ('gdebi-test9.deb', True), - # provides debconf-tiny and the real debconf conflicts with + # provides debconf-tiny and the real debconf conflicts with ('gdebi-test10.deb', False), ] def setUp(self): apt_pkg.init_config() - apt_pkg.config.set("APT::Architecture","i386") + apt_pkg.config.set("APT::Architecture", "i386") # FIXME: When run via test_all.py, the tests fail without this if it # is set in the system. apt_pkg.config.clear("APT::Architectures") - apt_pkg.config.set("Dir::State::status", + apt_pkg.config.set("Dir::State::status", "./data/test_debs/var/lib/dpkg/status") - apt_pkg.config.set("Dir::State::lists", + apt_pkg.config.set("Dir::State::lists", "./data/test_debs/var/lib/apt/lists") - apt_pkg.config.set("Dir::Etc::sourcelist", + apt_pkg.config.set("Dir::Etc::sourcelist", "./data/test_debs/etc/apt/sources.list") apt_pkg.init_system() self.cache = apt.Cache() @@ -76,7 +77,8 @@ class TestDebfile(unittest.TestCase): def testDebFile(self): deb = apt.debfile.DebPackage(cache=self.cache) for (filename, expected_res) in self.TEST_DEBS: - logging.debug("testing %s, expecting %s" % (filename, expected_res)) + logging.debug("testing %s, expecting %s" % ( + filename, expected_res)) deb.open(os.path.join("data", "test_debs", filename)) res = deb.check() self.assertEqual(res, expected_res, @@ -85,7 +87,8 @@ class TestDebfile(unittest.TestCase): def test_utf8_sections(self): deb = apt.debfile.DebPackage(cache=self.cache) - deb.open(os.path.join("data","test_debs","utf8-package_1.0-1_all.deb")) + deb.open( + os.path.join("data", "test_debs", "utf8-package_1.0-1_all.deb")) self.assertEqual(deb["Maintainer"], "Samuel Lidén Borell <samuel@slbdata.se>") @@ -99,7 +102,8 @@ class TestDebfile(unittest.TestCase): deb = apt.debfile.DebPackage(cache=self.cache) deb.open(os.path.join("data", "test_debs", "gdebi-test12.deb")) content = deb.data_content("usr/bin/binary") - self.assertTrue(content.startswith("Automatically converted to printable ascii:\n\x7fELF ")) + self.assertTrue(content.startswith( + "Automatically converted to printable ascii:\n\x7fELF ")) # control file needle = """Package: gdebi-test12 Version: 1.0 @@ -136,7 +140,8 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading apt_pkg.config["APT::Architecture"] = "amd64" apt_pkg.init_system() - allowed_any = apt.debfile.DebPackage("./data/test_debs/testdep-allowed-any_1.0-1_i386.deb") + allowed_any = apt.debfile.DebPackage( + "./data/test_debs/testdep-allowed-any_1.0-1_i386.deb") self.assertTrue(allowed_any.check(), allowed_any._failure_string) def test_multi_arch_same(self): @@ -144,7 +149,8 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading apt_pkg.config["APT::Architectures::"] = "amd64" apt_pkg.config["APT::Architecture"] = "amd64" apt_pkg.init_system() - same = apt.debfile.DebPackage("./data/test_debs/testdep-same-arch_1.0-1_i386.deb") + same = apt.debfile.DebPackage( + "./data/test_debs/testdep-same-arch_1.0-1_i386.deb") self.assertTrue(same.check(), same._failure_string) diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index cf6479b1..045daf72 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -18,13 +18,15 @@ import apt import apt_pkg import apt.debfile + class TestDebfileMultiarch(unittest.TestCase): """ test the multiarch debfile """ def test_multiarch_deb_check(self): if apt_pkg.get_architectures() != ["amd64", "i386"]: # TODO: use unittest.skip - #logging.warning("skipping test because running on a non-multiarch system") + #logging.warning("skipping test because running on a " + # "non-multiarch system") return deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb") @@ -48,10 +50,9 @@ class TestDebfileMultiarch(unittest.TestCase): installable = deb.check() #print deb._failure_string self.assertFalse(installable) - self.assertEqual(deb._failure_string, + self.assertEqual(deb._failure_string, "Conflicts with the installed package 'lib3ds-1-3'") - if __name__ == "__main__": unittest.main() diff --git a/tests/test_group.py b/tests/test_group.py index 3c3a5b7a..e70d2479 100644 --- a/tests/test_group.py +++ b/tests/test_group.py @@ -22,7 +22,6 @@ class TestGroup(unittest.TestCase): list(group) == list(group) - def test_cache_groups(self): """group: Iterate over all groups""" assert len(list(self.cache.groups)) == self.cache.group_count diff --git a/tests/test_hashes.py b/tests/test_hashes.py index 660373cb..be817f88 100644 --- a/tests/test_hashes.py +++ b/tests/test_hashes.py @@ -90,7 +90,7 @@ class TestHashString(unittest.TestCase): def tearDown(self): """Cleanup, Close the file object used for the tests.""" - self.file.close() + self.file.close() def test_md5(self): """hashes: Test apt_pkg.HashString().md5""" diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py index 334f574d..40943d10 100644 --- a/tests/test_lp659438.py +++ b/tests/test_lp659438.py @@ -20,7 +20,7 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Licensed under the GNU General Public License Version 2 -__author__ = "Sebastian Heinlein <devel@glatzor.de>" +__author__ = "Sebastian Heinlein <devel@glatzor.de>" import os import shutil diff --git a/tests/test_paths.py b/tests/test_paths.py index 48f86c52..62ea1665 100644 --- a/tests/test_paths.py +++ b/tests/test_paths.py @@ -30,8 +30,10 @@ class TestPath(unittest.TestCase): def test_acquire(self): apt_pkg.AcquireFile(apt_pkg.Acquire(), "http://example.com", destdir=self.file_bytes, destfile=self.file_bytes) - apt_pkg.AcquireFile(apt_pkg.Acquire(), "http://example.com", - destdir=self.file_unicode, destfile=self.file_unicode) + apt_pkg.AcquireFile(apt_pkg.Acquire(), + "http://example.com", + destdir=self.file_unicode, + destfile=self.file_unicode) def test_ararchive(self): archive = apt_inst.ArArchive(u"data/test_debs/data-tar-xz.deb") @@ -65,7 +67,7 @@ class TestPath(unittest.TestCase): apt_inst.TarFile(os.path.join(self.dir_bytes, b"control.tar.gz")) def test_configuration(self): - with open(self.file_unicode, 'w' ) as config: + with open(self.file_unicode, 'w') as config: config.write("Hello { World 1; };") apt_pkg.read_config_file(apt_pkg.config, self.file_bytes) apt_pkg.read_config_file(apt_pkg.config, self.file_unicode) @@ -95,7 +97,7 @@ class TestPath(unittest.TestCase): self.assertEqual(size1, size2) self.assertEqual(str(hash1), str(hash2)) self.assertEqual(str(hash1), ("SHA256:fefed230e286d832ab6eb0fb7b72" - + "442165b50df23a68402ae6e9d265a31920a2")) + "442165b50df23a68402ae6e9d265a31920a2")) def test_lock(self): apt_pkg.get_lock(self.file_unicode, True) diff --git a/tests/test_pep8.py b/tests/test_pep8.py index e6a672cf..2e1f43fc 100755 --- a/tests/test_pep8.py +++ b/tests/test_pep8.py @@ -5,7 +5,7 @@ import unittest class PackagePep8TestCase(unittest.TestCase): - def test_all_code(self): + def test_pep8(self): res = 0 py_dir = os.path.join(os.path.dirname(__file__), "..") res += subprocess.call( diff --git a/tests/test_policy.py b/tests/test_policy.py index f7d41152..f15cf2d1 100644 --- a/tests/test_policy.py +++ b/tests/test_policy.py @@ -9,6 +9,7 @@ import apt import unittest + class TestAptPolicy(unittest.TestCase): def test_apt_policy_lowlevel(self): @@ -34,6 +35,5 @@ class TestAptPolicy(unittest.TestCase): pkg.candidate.policy_priority < 1001) - if __name__ == "__main__": unittest.main() diff --git a/tests/test_progress.py b/tests/test_progress.py index 508da7d4..01cd8a2d 100644 --- a/tests/test_progress.py +++ b/tests/test_progress.py @@ -12,6 +12,7 @@ import apt import apt_pkg import os + class TestAcquireProgress(apt.progress.base.AcquireProgress): def pulse(self, owner): self.pulsed = True @@ -19,6 +20,7 @@ class TestAcquireProgress(apt.progress.base.AcquireProgress): # but often this is forgoten (and causes odd error messages) # so the lib supports it. we test the lack of support value here + class TestProgress(unittest.TestCase): def setUp(self): @@ -35,7 +37,7 @@ class TestProgress(unittest.TestCase): apt_pkg.config.set("Dir::state::lists", "./tmp") # create artifical line deb_line = "deb file:%s/data/fake-packages/ /\n" % basedir - with open("fetch_sources.list","w") as fobj: + with open("fetch_sources.list", "w") as fobj: fobj.write(deb_line) apt_pkg.config.set("Dir::Etc::sourcelist", "fetch_sources.list") apt_pkg.config.clear("APT::Update::Post-Invoke") @@ -47,5 +49,6 @@ class TestProgress(unittest.TestCase): cache.update(progress) self.assertTrue(progress.pulsed) + if __name__ == "__main__": unittest.main() diff --git a/tests/test_size_to_str.py b/tests/test_size_to_str.py index 2c2c372f..1d0e9232 100644 --- a/tests/test_size_to_str.py +++ b/tests/test_size_to_str.py @@ -1,6 +1,6 @@ #!/usr/bin/python -__author__ = "Barry Warsaw <barry@ubuntu.com>, James Hunt, Michael Vogt" +__author__ = "Barry Warsaw <barry@ubuntu.com>, James Hunt, Michael Vogt" import sys import unittest @@ -9,6 +9,7 @@ import apt_pkg if sys.version_info[0] == 2 and sys.version_info[1] == 6: from unittest2 import TestCase + TestCase # pyflakes else: from unittest import TestCase @@ -18,74 +19,71 @@ class SizeToStrTestCase(TestCase): DATA = { # XXX: note the trailing spaces for some of these entries! - 10 ** 1 : "10 ", - 10 ** 2 : "100 ", - 10 ** 3 : "1000 ", - 10 ** 4 : "10.0 k", - 10 ** 5 : "100 k", - 10 ** 6 : "1000 k", - 10 ** 7 : "10.0 M", - 10 ** 8 : "100 M", - 10 ** 9 : "1000 M", - 10 ** 10 : "10.0 G", - 10 ** 11 : "100 G", - 10 ** 12 : "1000 G", - 10 ** 13 : "10.0 T", - 10 ** 14 : "100 T", - 10 ** 15 : "1000 T", - 10 ** 16 : "10.0 P", - 10 ** 17 : "100 P", - 10 ** 18 : "1000 P", - 10 ** 19 : "10.0 E", - 10 ** 20 : "100 E", - 10 ** 21 : "1000 E", - 10 ** 22 : "10.0 Z", - 10 ** 23 : "100.0 Z", - 10 ** 24 : "1000 Z", -# 10 ** 25 : "10.0 Y", - 10 ** 26 : "100 Y", - 10 ** 27 : "1000 Y", - + 10 ** 1: "10 ", + 10 ** 2: "100 ", + 10 ** 3: "1000 ", + 10 ** 4: "10.0 k", + 10 ** 5: "100 k", + 10 ** 6: "1000 k", + 10 ** 7: "10.0 M", + 10 ** 8: "100 M", + 10 ** 9: "1000 M", + 10 ** 10: "10.0 G", + 10 ** 11: "100 G", + 10 ** 12: "1000 G", + 10 ** 13: "10.0 T", + 10 ** 14: "100 T", + 10 ** 15: "1000 T", + 10 ** 16: "10.0 P", + 10 ** 17: "100 P", + 10 ** 18: "1000 P", + 10 ** 19: "10.0 E", + 10 ** 20: "100 E", + 10 ** 21: "1000 E", + 10 ** 22: "10.0 Z", + 10 ** 23: "100.0 Z", + 10 ** 24: "1000 Z", + #10 ** 25: "10.0 Y", + 10 ** 26: "100 Y", + 10 ** 27: "1000 Y", # That's our limit :) - 10 ** 28 : "10000 Y", - - 0 : "0 ", - 1 : "1 ", - 1024 : "1024 ", - 10240 : "10.2 k", - 102400 : "102 k", - 1024000 : "1024 k", - 10240000 : "10.2 M", - 102400000 : "102 M", - 2147483647 : "2147 M", - 2147483648 : "2147 M", - 1024000000 : "1024 M", - 10240000000 : "10.2 G", - - 9 : "9 ", - 99 : "99 ", - 999 : "999 ", - 9999 : "9999 ", - 99999 : "100.0 k", - 999999 : "1000 k", - 9999999 : "10000 k", - 99999999 : "100.0 M", - 999999999 : "1000 M", - 9999999999 : "10000 M", - 99999999999 : "100.0 G", - 999999999999 : "1000 G", - 9999999999999 : "10000 G", - 99999999999999 : "100.0 T", - 999999999999999 : "1000 T", - 9999999999999999 : "10.0 P", - 99999999999999999 : "100 P", - 999999999999999999 : "1000 P", - 9999999999999999999 : "10.0 E", - 99999999999999999999 : "100 E", - 999999999999999999999 : "1000 E", - 9999999999999999999999 : "10.0 Z", - 999999999999999999999999 : "1000 Z", - } + 10 ** 28: "10000 Y", + 0: "0 ", + 1: "1 ", + 1024: "1024 ", + 10240: "10.2 k", + 102400: "102 k", + 1024000: "1024 k", + 10240000: "10.2 M", + 102400000: "102 M", + 2147483647: "2147 M", + 2147483648: "2147 M", + 1024000000: "1024 M", + 10240000000: "10.2 G", + 9: "9 ", + 99: "99 ", + 999: "999 ", + 9999: "9999 ", + 99999: "100.0 k", + 999999: "1000 k", + 9999999: "10000 k", + 99999999: "100.0 M", + 999999999: "1000 M", + 9999999999: "10000 M", + 99999999999: "100.0 G", + 999999999999: "1000 G", + 9999999999999: "10000 G", + 99999999999999: "100.0 T", + 999999999999999: "1000 T", + 9999999999999999: "10.0 P", + 99999999999999999: "100 P", + 999999999999999999: "1000 P", + 9999999999999999999: "10.0 E", + 99999999999999999999: "100 E", + 999999999999999999999: "1000 E", + 9999999999999999999999: "10.0 Z", + 999999999999999999999999: "1000 Z", + } def test_from_data(self): for k, v in self.DATA.items(): @@ -96,7 +94,7 @@ class SizeToStrTestCase(TestCase): def test_raise_on_unsupported(self): for v in ["hello", None, {}, [], ()]: with self.assertRaises(TypeError): - apt_pkg.size_to_str(v) + apt_pkg.size_to_str(v) class RegressionTestCase(unittest.TestCase): diff --git a/tests/test_tagfile.py b/tests/test_tagfile.py index f26f851b..6ff6a32a 100644 --- a/tests/test_tagfile.py +++ b/tests/test_tagfile.py @@ -27,6 +27,7 @@ if libdir: import apt_pkg + class TestTagFile(unittest.TestCase): """ test the apt_pkg.TagFile """ diff --git a/tests/test_utils.py b/tests/test_utils.py index 35c0a466..12d5a554 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,12 +13,13 @@ import unittest from apt.utils import ( get_maintenance_end_date, get_release_date_from_release_file, - ) +) + class TestUtils(unittest.TestCase): def test_get_release_date_from_release_file(self): - path = os.path.join(os.path.dirname(__file__), + path = os.path.join(os.path.dirname(__file__), "data", "misc", "foo_Release") t = get_release_date_from_release_file(path) self.assertEqual(str(datetime.datetime.utcfromtimestamp(t)), @@ -28,33 +29,38 @@ class TestUtils(unittest.TestCase): months_of_support = 18 # test historic releases, jaunty release_date = datetime.datetime(2009, 4, 23) - (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support) + (end_year, end_month) = get_maintenance_end_date( + release_date, months_of_support) self.assertEqual(end_year, 2010) self.assertEqual(end_month, 10) # test historic releases, karmic release_date = datetime.datetime(2009, 10, 29) - (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support) + (end_year, end_month) = get_maintenance_end_date( + release_date, months_of_support) self.assertEqual(end_year, 2011) self.assertEqual(end_month, 4) # test maverick release_date = datetime.datetime(2010, 10, 10) - (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support) + (end_year, end_month) = get_maintenance_end_date( + release_date, months_of_support) self.assertEqual(end_year, 2012) self.assertEqual(end_month, 4) # test with modulo zero release_date = datetime.datetime(2010, 6, 10) - (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support) + (end_year, end_month) = get_maintenance_end_date( + release_date, months_of_support) self.assertEqual(end_year, 2011) self.assertEqual(end_month, 12) # test dapper months_of_support = 60 release_date = datetime.datetime(2008, 4, 24) - (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support) + (end_year, end_month) = get_maintenance_end_date( + release_date, months_of_support) self.assertEqual(end_year, 2013) self.assertEqual(end_month, 4) - + # what datetime says #d = datetime.timedelta(18*30) #print "end date: ", release_date + d |
