[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, unittest2, updated. 4.9-133-g16415b1

Sandro Tosi morph at debian.org
Fri Nov 12 17:48:11 UTC 2010


The following commit has been merged in the unittest2 branch:
commit 16415b148800fad17154e5f2d7cdb01c019bc6cf
Author: Sandro Tosi <morph at debian.org>
Date:   Fri Nov 12 18:45:55 2010 +0100

    almost cover the whole reportbug.utils
    
    What's left it's either difficult to test (i.e. checks for un-existing files or
    unaccessible resources), code that could be remove or code that needs advanced
    "stuff" (like using crafted files to test all the corner cases)

diff --git a/tests/test_utils.py b/tests/test_utils.py
index 3904fd7..08afb21 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -1,6 +1,7 @@
 import unittest2
 
 from reportbug import utils
+import os.path
 
 class TestUtils(unittest2.TestCase):
 
@@ -32,6 +33,40 @@ class TestEmail(unittest2.TestCase):
         self.assertEqual(name, 'Reportbug Maintainers')
         self.assertEqual(email_addr, 'reportbug-maint at lists.alioth.debian.org')
 
+    def test_get_email(self):
+
+        name = 'Reportbug Maintainers'
+        mail = 'reportbug-maint at lists.alioth.debian.org'
+
+        n, m = utils.get_email(mail, name)
+
+        self.assertEqual(name, n)
+        self.assertEqual(mail, m)
+
+    def test_get_user_id(self):
+
+        name = 'Reportbug Maintainers'
+        mail = 'reportbug-maint at lists.alioth.debian.org'
+        addr = utils.get_user_id(mail, name)
+        self.assertEqual(addr, "%s <%s>" % (name, mail))
+
+        name = 'test'
+        mail = 'faked'
+        addr = utils.get_user_id(mail, name)
+        self.assertIn(mail+'@', addr)
+
+        mail = 'Reportbug Maintainers <reportbug-maint at lists.alioth.debian.org>'
+        addr = utils.get_user_id(mail)
+        self.assertEqual(mail, addr)
+
+        mail = 'reportbug-maint at lists.alioth.debian.org'
+        addr = utils.get_user_id(mail)
+        self.assertIn(mail, addr)
+
+
+    def test_find_rewritten(self):
+        unittest2.skip("Is utils.find_rewritten actually useful to someone? deprecate it?")
+
 class TestPackages(unittest2.TestCase):
 
     def test_get_package_status(self):
@@ -78,10 +113,54 @@ class TestPackages(unittest2.TestCase):
         self.assertIsNotNone(fulldesc)
         self.assertEqual(state, 'installed')
 
+        # it exploits the 'statuscache', it's already called before
+        # so it's now in the cache
+        status = utils.get_package_status('dpkg')
+
+        status = utils.get_package_status('reportbug', avail=True)
+
+        (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
+         installed, origin, vendor, reportinfo, priority, desc, src_name,
+         fulldesc, state, suggests) = status
+
+        self.assertIsNotNone(pkgversion)
+        self.assertEqual(pkgavail, 'reportbug')
+        # let's just check Depends is not null
+        self.assertIsNotNone(depends)
+        self.assertIsNotNone(maintainer)
+        self.assertEqual(priority, 'standard')
+        self.assertIsNotNone(desc)
+        self.assertIsNotNone(fulldesc)
+
+        status = utils.get_package_status('python-matplotlib')
+
+        (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
+         installed, origin, vendor, reportinfo, priority, desc, src_name,
+         fulldesc, state, suggests) = status
+
+        self.assertIsNotNone(recommends)
+
+
+    def test_get_changed_config_files(self):
+
+        status = utils.get_package_status('dpkg')
+
+        (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
+         installed, origin, vendor, reportinfo, priority, desc, src_name,
+         fulldesc, state, suggests) = status
+
+        confinfo, changed = utils.get_changed_config_files(conffiles)
+        self.assertIsNotNone(confinfo)
+
     def test_find_package_for(self):
         result = utils.find_package_for('dpkg')
         self.assertNotEqual(result[1], {})
 
+        filename = 'reportbug-bugfree'
+        result = utils.find_package_for(filename, pathonly=True)
+        self.assertEqual(result[0], filename)
+        self.assertIsNone(result[1])
+
         result = utils.find_package_for('/usr/bin/reportbug')
         self.assertNotEqual(result[1], {})
 
@@ -126,15 +205,32 @@ class TestPackages(unittest2.TestCase):
 
         self.assertGreater(len(result), 0)
 
+    def test_get_avail_database(self):
+        
+        avail_db = utils.get_avail_database()
+        entry = avail_db.next()
+        self.assertIsNotNone(entry)
+
+    def test_available_package_description(self):
+
+        descr = utils.available_package_description('reportbug')
+        self.assertEquals(descr, 'reports bugs in the Debian distribution')
+
+        descr = utils.available_package_description('reportbug-bugfree')
+        self.assertIsNone(descr)
+
 class TestSourcePackages(unittest2.TestCase):
 
-    @unittest2.skip("Too slow")
+    #@unittest2.skip("Too slow")
     def test_get_source_name(self):
         binpkg = 'python-reportbug'
         src = utils.get_source_name(binpkg)
         self.assertEqual(src, 'reportbug')
 
-    @unittest2.skip("Too slow")
+        src = utils.get_source_name('reportbug-bugfree')
+        self.assertIsNone(src)
+
+    #@unittest2.skip("Too slow")
     def test_get_source_package(self):
         src = 'reportbug'
         binpkgs = utils.get_source_package(src)
@@ -151,6 +247,12 @@ class TestSystemInformation(unittest2.TestCase):
         cores = utils.get_cpu_cores()
         self.assertGreaterEqual(cores, 1)
 
+
+    def test_lsb_release_info(self):
+
+        res = utils.lsb_release_info()
+        self.assertIn('Debian', res)
+
 class TestMua(unittest2.TestCase):
 
     def test_mua_is_supported(self):
@@ -163,7 +265,8 @@ class TestMua(unittest2.TestCase):
     def test_mua_exists(self):
 
         for mua in ('mh', 'nmh', 'gnus', 'mutt'):
-            self.assertTrue(utils.mua_exists(mua))
+            if not utils.mua_exists(mua):
+                self.fail("%s MUA program not available" % mua)
 
     def test_mua_name(self):
 
@@ -172,6 +275,7 @@ class TestMua(unittest2.TestCase):
 
         self.assertEqual(utils.mua_name('mua-of-my-dreams'), 'mua-of-my-dreams')
 
+
 class TestBugreportBody(unittest2.TestCase):
 
     def test_get_dependency_info(self):
@@ -183,3 +287,181 @@ class TestBugreportBody(unittest2.TestCase):
 
         result = utils.get_dependency_info('reportbug', [['dpkg']])
         self.assertIn('dpkg', result)
+
+        # check for the provides stuff
+        result = utils.get_dependency_info('reportbug', [['awk']])
+        self.assertIn('awk', result)
+
+    def test_cleanup_msg(self):
+
+        message = """Subject: unblock: reportbug/4.12.6
+Package: release.debian.org
+User: release.debian.org at packages.debian.org
+Usertags: unblock
+Severity: normal
+Morph: cool
+Continuation:
+ header
+
+Please unblock package reportbug
+
+(explain the reason for the unblock here)
+
+unblock reportbug/4.12.6
+
+-- System Information:
+Debian Release: squeeze/sid
+  APT prefers unstable
+  APT policy: (500, 'unstable'), (1, 'experimental')
+Architecture: amd64 (x86_64)
+
+Kernel: Linux 2.6.31-1-amd64 (SMP w/4 CPU cores)
+Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
+Shell: /bin/sh linked to /bin/bash"""
+        header = [u'X-Debbugs-CC: reportbug at packages.qa.debian.org']
+        pseudos = ['Morph: cool']
+        rtype = 'debbugs'
+        body, headers, pseudo = utils.cleanup_msg(message, header, pseudos,
+                                                  rtype)
+
+        # check body content
+        self.assertIn('reportbug/4.12.6', body)
+        self.assertIn('System Information', body)
+
+        # check expected headers are there
+        h = dict(headers)
+        self.assertIn('Subject', h)
+        self.assertIn('X-Debbugs-CC', h)
+
+        # check expected pseudo headers are there
+        p = dict([p.split(': ') for p in pseudo])
+        self.assertIn('Package', p)
+        self.assertIn('Severity', p)
+        self.assertIn('User', p)
+        self.assertIn('Usertags', p)
+        self.assertIn('Morph', p)
+
+
+    def test_generate_blank_report(self):
+
+        report = utils.generate_blank_report('reportbug', '1.2.3', 'normal',
+                                             '', '', '', type='debbugs')
+        self.assertIsNotNone(report)
+        self.assertIn('Package: reportbug', report)
+        self.assertIn('Version: 1.2.3', report)
+        self.assertIn('Severity: normal', report)
+
+
+class TestConfig(unittest2.TestCase):
+
+# Find a way to specify an "internal" file for testing
+#    def setUp(self):
+#        self._FILES = utils.FILES
+#        utils.FILES = os.path.dirname(__file__) + '/data/reportbugrc'
+#
+#    def tearDown(self):
+#        utils.FILES = self._FILES
+#
+# --> check the code in utils.parse_config_files to get all the checked params
+
+    def test_parse_config_files(self):
+        args = utils.parse_config_files()
+        self.assertIsNot(args, {})
+
+
+class TestControl(unittest2.TestCase):
+
+    def test_parse_bug_control_file(self):
+
+        ctrl_file = os.path.dirname(__file__) + '/data/control'
+
+        submitas, submitto, reportwith, supplemental = \
+            utils.parse_bug_control_file(ctrl_file)
+
+        self.assertEquals(submitas, 'reportbug2')
+        self.assertEquals(submitto, 'reportbug-maint at lists.alioth.debian.org')
+        self.assertIn('python', reportwith)
+        self.assertIn('perl', reportwith)
+        self.assertIn('python', supplemental)
+        self.assertIn('perl', supplemental)
+
+class TestPaths(unittest2.TestCase):
+
+    def test_search_path_for(self):
+
+        p = 'not-existing'
+        res = utils.search_path_for(p)
+        self.assertIsNone(res)
+
+        p = '/tmp'
+        res = utils.search_path_for(p)
+        self.assertEquals(p, res)
+
+        p = 'dpkg'
+        res = utils.search_path_for(p)
+        self.assertEquals(res, '/usr/bin/dpkg')
+
+class TestEditor(unittest2.TestCase):
+
+    def test_which_editor(self):
+
+        res = utils.which_editor()
+        self.assertIsNotNone(res)
+
+        e = 'reportbug-editor'
+        res = utils.which_editor(e)
+        self.assertEquals(e, res)
+        
+class TestSearch(unittest2.TestCase):
+
+    def test_search_pipe(self):
+
+        f = 'reportbug'
+
+        dlocate = True
+        pipe, dloc = utils.search_pipe(f, dlocate)
+        res = pipe.readlines()
+        pipe.close()
+
+        self.assertEquals(dloc, dlocate)
+        self.assertGreater(len(res), 0)
+
+        dlocate = False
+        pipe, dloc = utils.search_pipe(f, dlocate)
+        res = pipe.readlines()
+        pipe.close()
+
+        self.assertEquals(dloc, dlocate)
+        self.assertGreater(len(res), 0)
+
+class TestDpkg(unittest2.TestCase):
+
+    def test_query_dpkg_for(self):
+
+        p = 'reportbug'
+        dlocate = True
+        res = utils.query_dpkg_for(p, dlocate)
+
+        self.assertEquals(res[0], p)
+        self.assertGreater(len(res[1].keys()), 0)
+
+        dlocate = False
+        res = utils.query_dpkg_for(p, dlocate)
+
+        self.assertEquals(res[0], p)
+        self.assertGreater(len(res[1].keys()), 0)
+
+        # to trigger 'Try again without dlocate if no packages found'
+        p = 'blablabla'
+        dlocate = True
+        res = utils.query_dpkg_for(p, dlocate)
+
+        self.assertEquals(res[0], p)
+        self.assertEquals(res[1], {})
+
+class TestMisc(unittest2.TestCase):
+
+    def test_first_run(self):
+
+        isfirstrun = utils.first_run()
+        self.assertIsNotNone(isfirstrun)

-- 
Reportbug - reports bugs in the Debian distribution



More information about the Reportbug-commits mailing list