[Piuparts-devel] [Git][debian/piuparts][legoktm-patches-1] 3 commits: tests: Replace deprecated self.fail* functions

Kunal Mehta gitlab at salsa.debian.org
Tue Jul 30 08:36:49 BST 2019



Kunal Mehta pushed to branch legoktm-patches-1 at Debian / piuparts


Commits:
b6b0a35d by Kunal Mehta at 2019-07-30T07:06:04Z
tests: Replace deprecated self.fail* functions

These were deprecated in Python 3.2 in favor of self.assert* functions
that are also available in 2.7.

- - - - -
d5a262b9 by Kunal Mehta at 2019-07-30T07:34:33Z
Port urllib usage to be Python 3 compatible

urllib2 was renamed and split into submodules as urllib.

- - - - -
2a4f9596 by Kunal Mehta at 2019-07-30T07:36:11Z
Port UserDict usage to be Python 3 compatible

The class was moved into the collections module.

- - - - -


8 changed files:

- piuparts-master-backend.py
- piuparts-report.py
- piupartslib/__init__.py
- piupartslib/conf.py
- piupartslib/packagesdb.py
- tests/test_dependencyparser.py
- tests/test_piuparts.py
- tests/unittests.py


Changes:

=====================================
piuparts-master-backend.py
=====================================
@@ -30,7 +30,10 @@ import os
 import fcntl
 import time
 import random
-from urllib2 import URLError
+try:
+    from urllib.errors import URLError
+except ImportError:
+    from urllib2 import URLError
 
 import piupartslib
 from piupartslib.packagesdb import LogfileExists


=====================================
piuparts-report.py
=====================================
@@ -38,7 +38,10 @@ import hashlib
 import pickle
 import random
 import fcntl
-from urllib2 import HTTPError, URLError
+try:
+    from urllib.errors import HTTPError, URLError
+except ImportError:
+    from urllib2 import HTTPError, URLError
 from collections import deque
 
 # if python-rpy2 ain't installed, we don't draw fancy graphs


=====================================
piupartslib/__init__.py
=====================================
@@ -20,7 +20,11 @@
 import bz2
 import lzma
 import zlib
-import urllib2
+try:
+    from urllib.request import urlopen
+    from urllib.error import HTTPError
+except ImportError:
+    from urllib2 import urlopen, HTTPError
 
 
 import conf
@@ -82,12 +86,13 @@ def open_packages_url(url):
     socket = None
     for ext in ['.xz', '.bz2', '.gz', '']:
         try:
-            socket = urllib2.urlopen(url + ext)
-        except urllib2.HTTPError as httperror:
+            socket = urlopen(url + ext)
+        except HTTPError as httperror:
             pass
         else:
             break
     if socket is None:
+        # FIXME: I don't think httperror will be defined here
         raise httperror
     url = socket.geturl()
     if ext == '.bz2':


=====================================
piupartslib/conf.py
=====================================
@@ -24,7 +24,10 @@
 #
 
 import ConfigParser
-import UserDict
+try:
+    from collections import UserDict
+except ImportError:
+    from UserDict import UserDict
 import subprocess
 import collections
 import re
@@ -46,10 +49,10 @@ class MissingMandatorySetting(Exception):
             (key, filename),
 
 
-class Config(UserDict.UserDict):
+class Config(UserDict):
 
     def __init__(self, section, defaults, mandatory=[], defaults_section=None):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self._section = section
         self._defaults_section = defaults_section
         for key, value in defaults.iteritems():
@@ -148,10 +151,10 @@ class Config(UserDict.UserDict):
         return self["arch"]
 
 
-class DistroConfig(UserDict.UserDict):
+class DistroConfig(UserDict):
 
     def __init__(self, filename, mirror):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self._mirror = mirror
         self._defaults = {
             "uri": None,


=====================================
piupartslib/packagesdb.py
=====================================
@@ -32,7 +32,10 @@ import random
 import stat
 import tempfile
 import time
-import UserDict
+try:
+    from collections import UserDict
+except ImportError:
+    from UserDict import UserDict
 import apt_pkg
 
 import piupartslib
@@ -54,10 +57,10 @@ def rfc822_like_header_parse(input):
     return headers
 
 
-class Package(UserDict.UserDict):
+class Package(UserDict):
 
     def __init__(self, headers):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self.headers = headers
         for header in headers:
             name, value = header.split(":", 1)
@@ -163,10 +166,10 @@ class Package(UserDict.UserDict):
         output_file.write("".join(self.headers))
 
 
-class PackagesFile(UserDict.UserDict):
+class PackagesFile(UserDict):
 
     def __init__(self):
-        UserDict.UserDict.__init__(self)
+        UserDict.__init__(self)
         self._urllist = []
 
     def load_packages_urls(self, urls, restrict_packages=None):


=====================================
tests/test_dependencyparser.py
=====================================
@@ -18,16 +18,16 @@ class DependencyParserTests(unittest.TestCase):
 
     def testEmpty(self):
         deps, names = self.parse("")
-        self.failUnlessEqual(deps, [])
+        self.assertEqual(deps, [])
 
     def testSingle(self):
         deps, names = self.parse("foo")
-        self.failUnlessEqual(names, [["foo"]])
+        self.assertEqual(names, [["foo"]])
 
     def testTwo(self):
         deps, names = self.parse("foo, bar")
-        self.failUnlessEqual(names, [["foo"], ["bar"]])
+        self.assertEqual(names, [["foo"], ["bar"]])
 
     def testAlternatives(self):
         deps, names = self.parse("foo, bar | foobar")
-        self.failUnlessEqual(names, [["foo"], ["bar", "foobar"]])
+        self.assertEqual(names, [["foo"], ["bar", "foobar"]])


=====================================
tests/test_piuparts.py
=====================================
@@ -100,70 +100,70 @@ class IsBrokenSymlinkTests(unittest.TestCase):
         shutil.rmtree(self.testdir)
 
     def testRelativeBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "relative-broken"))
 
     def testRelativeBrokenToSymlink(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "relative-broken-to-symlink"))
 
     def testAbsoluteBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "absolute-broken"))
 
     def testAbsoluteBrokenToSymlink(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "absolute-broken-to-symlink"))
 
     def testTrailingSlashBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "trailing-slash-broken"))
 
     def testSelfLoopBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "selfloop"))
 
     def testExpandingSelfLoopBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "explode"))
 
     def testAbsoluteSelfLoopBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "absolute-selfloop"))
 
     def testSubdirSelfLoopBroken(self):
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/selfloop"))
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/selfloop1"))
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/subdir/selfloop"))
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/subdir/selfloop1"))
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/subdir/selfloop2"))
-        self.failUnless(is_broken_symlink(self.testdir, self.testdir,
+        self.assertTrue(is_broken_symlink(self.testdir, self.testdir,
                                           "dir/subdir/selfloop3"))
 
     def testRelativeWorks(self):
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "relative-works"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "relative-works"))
 
     def testRelativeWorksToSymlink(self):
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "relative-works-to-symlink"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "relative-works-to-symlink"))
 
     def testAbsoluteWorks(self):
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "absolute-works"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "absolute-works"))
 
     def testAbsoluteWorksToSymlink(self):
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "absolute-works-to-symlink"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "absolute-works-to-symlink"))
 
     def testTrailingSlashWorks(self):
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "trailing-slash-works"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "trailing-slash-works"))
 
     def testMultiLevelNestedSymlinks(self):
         # target/first-link -> ../target/second-link -> ../target
@@ -171,8 +171,8 @@ class IsBrokenSymlinkTests(unittest.TestCase):
         os.mkdir(os.path.join(self.testdir, "target"))
         self.symlink("../target", "target/second-link")
         self.symlink("../target/second-link", "target/first-link")
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "target/first-link"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "target/first-link"))
 
     def testMultiLevelNestedAbsoluteSymlinks(self):
         # first-link -> /second-link/final-target
@@ -182,5 +182,5 @@ class IsBrokenSymlinkTests(unittest.TestCase):
         os.mkdir(os.path.join(self.testdir, "final-dir/final-target"))
         self.symlink("/second-link/final-target", "first-link")
         self.symlink("/final-dir", "second-link")
-        self.failIf(is_broken_symlink(self.testdir, self.testdir,
-                                      "first-link"))
+        self.assertFalse(is_broken_symlink(self.testdir, self.testdir,
+                                           "first-link"))


=====================================
tests/unittests.py
=====================================
@@ -59,15 +59,15 @@ class PackagesDbTests(unittest.TestCase):
 
     def testNoPackages(self):
         p = self.reserve("")
-        self.failUnlessEqual(p, None)
+        self.assertEqual(p, None)
 
     def testNoDeps(self):
         p = self.reserve("""\
 Package: foo
 Version: 1.0-1
 """)
-        self.failIfEqual(p, None)
-        self.failUnlessEqual(p["Package"], "foo")
+        self.assertNotEqual(p, None)
+        self.assertEqual(p["Package"], "foo")
 
 
 if __name__ == "__main__":



View it on GitLab: https://salsa.debian.org/debian/piuparts/compare/42a2993958893d22025fe24cc54a7fd0250e0a05...2a4f9596e3449dec3e2497238eb547aebb1d6b09

-- 
View it on GitLab: https://salsa.debian.org/debian/piuparts/compare/42a2993958893d22025fe24cc54a7fd0250e0a05...2a4f9596e3449dec3e2497238eb547aebb1d6b09
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/piuparts-devel/attachments/20190730/f8ad8d22/attachment-0001.html>


More information about the Piuparts-devel mailing list