[Reportbug-commits] [SCM] Reportbug - reports bugs in the Debian distribution branch, master, updated. 4.9-140-g5ccf988

Sandro Tosi morph at debian.org
Thu Dec 2 00:06:41 UTC 2010


The following commit has been merged in the master branch:
commit 0ace4161cc1bfcc896ae68d275ef18d6e17b2e02
Author: Sandro Tosi <morph at debian.org>
Date:   Wed Sep 1 10:42:46 2010 +0200

    completely rewritten test suite

diff --git a/module.mk b/module.mk
deleted file mode 100644
index 152b17a..0000000
--- a/module.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-# :vim: filetype=make : -*- makefile; coding: utf-8; -*-
-
-# module.mk
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+debian at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-# Makefile module for reportbug Python package
-
-MODULE_DIR := .
-
-CODE_MODULES += $(shell find ${CODE_PACKAGE_DIR} \
-	-path ${CODE_PACKAGE_DIR}/${TEST_DIR} -prune -o \
-	-name '*.py' -print)
-
-CODE_PROGRAM_NAMES += reportbug
-CODE_PROGRAM_NAMES += querybts
-CODE_PROGRAM_NAMES += handle_bugscript
-CODE_PROGRAM_NAMES += script
-
-CODE_PROGRAMS += $(addprefix ${CODE_PROGRAM_DIR}/,${CODE_PROGRAM_NAMES})
-
-GENERATED_FILES += $(shell find ${MODULE_DIR} -name '*.pyc')
-
-PYTHON = python
diff --git a/test/__init__.py b/test/__init__.py
index e69de29..792d600 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -0,0 +1 @@
+#
diff --git a/test/module.mk b/test/module.mk
deleted file mode 100644
index 8c2b91e..0000000
--- a/test/module.mk
+++ /dev/null
@@ -1,83 +0,0 @@
-# :vim: filetype=make : -*- makefile; coding: utf-8; -*-
-
-# test/module.mk
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+debian at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-# Makefile module for test suite
-
-MODULE_DIR := ${TEST_DIR}
-
-NOSETESTS = nosetests
-NOSETESTS_OPTS = --exclude='^(?!test_)'
-PYFLAKES = pyflakes
-PYLINT = pylint
-COVERAGE = python-coverage
-DATE = date
-DATE_FORMAT = '%Y-%m-%d %H:%M:%S'
-INWAIT = inotifywait
-inwait_event_opts += -e create
-inwait_event_opts += -e modify
-inwait_event_opts += -e delete
-INWAIT_OPTS = -q -r -t 0 ${inwait_event_opts}
-TEST_INWAIT_FILES = ${CODE_PACKAGE_DIR} ${CODE_PROGRAMS} ${TEST_DIR}
-
-NOSETESTS_FILES = ${TEST_DIR}
-nosetests_cmd = $(NOSETESTS) ${NOSETESTS_OPTS} ${NOSETESTS_FILES}
-
-coverage_files += ${CODE_MODULES}
-# Not until python-coverage is updated with upstream fixes (2008-05-04)
-#coverage_files += ${CODE_PROGRAMS}
-
-GENERATED_FILES += .coverage
-
-
-# usage: $(call test-output-banner,message)
-define test-output-banner
-	@ echo -n ${1} ; \
-	$(DATE) +${DATE_FORMAT}
-endef
-
-
-.PHONY: nosetests
-nosetests:
-	$(call test-output-banner, "Test run: " )
-	$(nosetests_cmd)
-
-test: nosetests
-
-# usage: $(call test-wait)
-define test-wait
-	$(INWAIT) ${INWAIT_OPTS} ${TEST_INWAIT_FILES}
-endef
-
-.PHONY: test-continuous
-test-continuous:
-	while true ; do \
-		clear ; \
-		$(MAKE) test ; \
-		$(call test-wait) ; \
-	done
-
-
-.PHONY: pyflakes
-pyflakes:
-	$(PYFLAKES) .
-
-.PHONY: pylint
-pylint:
-	$(PYLINT) ${CODE_PACKAGE_DIR}
-	$(PYLINT) ${CODE_PROGRAMS}
-	$(PYLINT) ${TEST_DIR}
-
-.PHONY: coverage
-coverage: NOSETEST_OPTS += --with-coverage
-coverage:
-	$(nosetests_cmd)
-	$(COVERAGE) -r -m ${coverage_files}
-
-qa: pyflakes coverage
diff --git a/test/scaffold.py b/test/scaffold.py
deleted file mode 100644
index 2b3f6a1..0000000
--- a/test/scaffold.py
+++ /dev/null
@@ -1,259 +0,0 @@
-# -*- coding: utf-8 -*-
-
-# scaffold.py
-#
-# Copyright © 2007-2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Scaffolding for unit test modules
-"""
-
-import unittest
-import os
-import sys
-
-test_dir = os.path.dirname(os.path.abspath(__file__))
-parent_dir = os.path.dirname(test_dir)
-if not test_dir in sys.path:
-    sys.path.insert(1, test_dir)
-if not parent_dir in sys.path:
-    sys.path.insert(1, parent_dir)
-bin_dir = os.path.join(parent_dir, 'bin')
-
-
-def suite(module_name):
-    """ Create the test suite for named module """
-    from sys import modules
-    loader = unittest.TestLoader()
-    suite = loader.loadTestsFromModule(modules[module_name])
-    return suite
-
-def unittest_main(argv=None):
-    """ Mainline function for each unit test module """
-
-    from sys import argv as sys_argv
-    if not argv:
-        argv = sys_argv
-
-    exitcode = None
-    try:
-        unittest.main(argv=argv, defaultTest='suite')
-    except SystemExit, e:
-        exitcode = e.code
-
-    return exitcode
-
-
-def make_module_from_file(module_name, file_name):
-    """ Make a new module object from the code in specified file """
-
-    from types import ModuleType
-    module = ModuleType(module_name)
-
-    module_file = open(file_name, 'r')
-    exec module_file in module.__dict__
-
-    return module
-
-
-class TestCase(unittest.TestCase):
-    """ Test case behaviour """
-
-    def failUnlessRaises(self, exc_class, func, *args, **kwargs):
-        """ Fail unless the function call raises the expected exception
-
-            Fail the test if an instance of the exception class
-            ``exc_class`` is not raised when calling ``func`` with the
-            arguments ``*args`` and ``**kwargs``.
-
-            """
-
-        try:
-            super(TestCase, self).failUnlessRaises(
-                exc_class, func, *args, **kwargs)
-        except self.failureException:
-            exc_class_name = exc_class.__name__
-            msg = (
-                "Exception %(exc_class_name)s not raised"
-                " for function call:"
-                " func=%(func)r args=%(args)r kwargs=%(kwargs)r"
-                ) % vars()
-            raise self.failureException(msg)
-
-
-    def failIfIs(self, first, second, msg=None):
-        """ Fail if the two objects are identical
-
-            Fail the test if ``first`` and ``second`` are identical,
-            as determined by the ``is`` operator.
-
-            """
-
-        if first is second:
-            if msg is None:
-                msg = "%(first)r is %(second)r" % vars()
-            raise self.failureException(msg)
-
-    def failUnlessIs(self, first, second, msg=None):
-        """ Fail unless the two objects are identical
-
-            Fail the test unless ``first`` and ``second`` are
-            identical, as determined by the ``is`` operator.
-
-            """
-
-        if first is not second:
-            if msg is None:
-                msg = "%(first)r is not %(second)r" % vars()
-            raise self.failureException(msg)
-
-    assertIs = failUnlessIs
-    assertNotIs = failIfIs
-
-    def failIfIn(self, first, second, msg=None):
-        """ Fail if the second object is in the first
-
-            Fail the test if ``first`` contains ``second``, as
-            determined by the ``in`` operator.
-
-            """
-
-        if second in first:
-            if msg is None:
-                msg = "%(second)r is in %(first)r" % vars()
-            raise self.failureException(msg)
-
-    def failUnlessIn(self, first, second, msg=None):
-        """ Fail unless the second object is in the first
-
-            Fail the test unless ``first`` contains ``second``, as
-            determined by the ``in`` operator.
-
-            """
-
-        if second not in first:
-            if msg is None:
-                msg = "%(second)r is not in %(first)r" % vars()
-            raise self.failureException(msg)
-
-    assertIn = failUnlessIn
-    assertNotIn = failIfIn
-
-    def failUnlessOutputCheckerMatch(self, want, got, msg=None):
-        """ Fail unless the specified string matches the expected
-
-            Fail the test unless ``want`` matches ``got``, as
-            determined by a ``doctest.OutputChecker`` instance. This
-            is not an equality check, but a pattern match according to
-            the OutputChecker rules.
-
-            """
-
-        checker = doctest.OutputChecker()
-        want = textwrap.dedent(want)
-        got = textwrap.dedent(got)
-        if not checker.check_output(want, got, doctest.ELLIPSIS):
-            if msg is None:
-                msg = ("Expected %(want)r, got %(got)r:"
-                       "\n--- want: ---\n%(want)s"
-                       "\n--- got: ---\n%(got)s") % vars()
-            raise self.failureException(msg)
-
-    assertOutputCheckerMatch = failUnlessOutputCheckerMatch
-
-    def failIfIsInstance(self, obj, classes):
-        """ Fail if the object is an instance of the specified classes
-
-            Fail the test if the object ``obj`` is an instance of any
-            of ``classes``.
-
-            """
-
-        if isinstance(obj, classes):
-            msg = "%(obj)r is an instance of one of %(classes)r" % vars()
-            raise self.failureException(msg)
-
-    def failUnlessIsInstance(self, obj, classes):
-        """ Fail unless the object is an instance of the specified classes
-
-            Fail the test unless the object ``obj`` is an instance of
-            any of ``classes``.
-
-            """
-
-        if not isinstance(obj, classes):
-            msg = "%(obj)r is not an instance of any of %(classes)r" % vars()
-            raise self.failureException(msg)
-
-    assertIsInstance = failUnlessIsInstance
-    assertNotIsInstance = failIfIsInstance
-
-    def failUnlessFunctionInTraceback(self, traceback, function):
-        """ Fail if the function is not in the traceback
-
-            Fail the test if the function ``function`` is not at any
-            of the levels in the traceback object ``traceback``.
-
-            """
-
-        func_in_traceback = False
-        expect_code = function.func_code
-        current_traceback = traceback
-        while current_traceback is not None:
-            if expect_code is current_traceback.tb_frame.f_code:
-                func_in_traceback = True
-                break
-            current_traceback = current_traceback.tb_next
-
-        if not func_in_traceback:
-            msg = ("Traceback did not lead to original function"
-                " %(function)s"
-                ) % vars()
-            raise self.failureException(msg)
-
-    assertFunctionInTraceback = failUnlessFunctionInTraceback
-
-
-class Test_Exception(TestCase):
-    """ Test cases for exception classes """
-
-    def __init__(self, *args, **kwargs):
-        """ Set up a new instance """
-        self.valid_exceptions = NotImplemented
-        super(Test_Exception, self).__init__(*args, **kwargs)
-
-    def setUp(self):
-        """ Set up test fixtures """
-        for exc_type, params in self.valid_exceptions.items():
-            args = (None,) * params['min_args']
-            params['args'] = args
-            instance = exc_type(*args)
-            params['instance'] = instance
-
-        self.iterate_params = make_params_iterator(
-            default_params_dict = self.valid_exceptions
-            )
-
-        super(Test_Exception, self).setUp()
-
-    def test_exception_instance(self):
-        """ Exception instance should be created """
-        for key, params in self.iterate_params():
-            instance = params['instance']
-            self.failIfIs(None, instance)
-
-    def test_exception_types(self):
-        """ Exception instances should match expected types """
-        for key, params in self.iterate_params():
-            instance = params['instance']
-            for match_type in params['types']:
-                match_type_name = match_type.__name__
-                fail_msg = (
-                    "%(instance)r is not an instance of"
-                    " %(match_type_name)s"
-                    ) % vars()
-                self.failUnless(
-                    isinstance(instance, match_type),
-                    msg=fail_msg)
diff --git a/test/test_bugreport.py b/test/test_bugreport.py
new file mode 100644
index 0000000..12b8590
--- /dev/null
+++ b/test/test_bugreport.py
@@ -0,0 +1,16 @@
+import unittest2
+
+from reportbug.bugreport import bugreport
+
+class TestBugreport(unittest2.TestCase):
+
+# TODO: differentiate for all possible cases? f.e. sysinfo True/False and then change if 'System Information' in self.text?
+
+    def test_bugreport(self):
+        self.body = 'test'
+        self.package = 'reportbug'
+        self.bugreport = bugreport(package=self.package, body=self.body)
+        self.text = self.bugreport.__unicode__()
+
+        self.assertIn(self.body, self.text)
+        self.assertIn(self.package, self.text)
diff --git a/test/test_checkbuildd.py b/test/test_checkbuildd.py
index cb708b8..d25d86c 100644
--- a/test/test_checkbuildd.py
+++ b/test/test_checkbuildd.py
@@ -1,16 +1,9 @@
-# -*- coding: utf-8; -*-
+import unittest2
 
-# test/test_checkbuildd.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.checkbuildd module
-"""
+from reportbug import checkbuildd
 
-import scaffold
+class TestCheckbuildd(unittest2.TestCase):
 
-from reportbug import checkbuildd
+    def test_archname(self):
+        archname = checkbuildd.archname()
+        self.assertNotEqual(archname, '')
diff --git a/test/test_checkversions.py b/test/test_checkversions.py
index 1a46f8f..2459096 100644
--- a/test/test_checkversions.py
+++ b/test/test_checkversions.py
@@ -1,16 +1,17 @@
-# -*- coding: utf-8; -*-
+import unittest2
 
-# test/test_checkversions.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
+from reportbug import checkversions
 
-""" Unit test for reportbuglib.checkversions module
-"""
+class TestCheckversions(unittest2.TestCase):
 
-import scaffold
+    def test_compare_versions(self):
+        # <current, upstream>
+        # 1 upstream newer than current
+        # 0 same version or upsteam none
+        # -1 current newer than upstream
+        self.assertEqual(checkversions.compare_versions('1.2.3', '1.2.4'), 1)
 
-from reportbug import checkversions
+        self.assertEqual(checkversions.compare_versions('123', None), 0)
+        self.assertEqual(checkversions.compare_versions('1.2.3', '1.2.3'), 0)
+
+        self.assertEqual(checkversions.compare_versions('1.2.4', '1.2.3'), -1)
diff --git a/test/test_debianbts.py b/test/test_debianbts.py
index 01290f3..a56f26e 100644
--- a/test/test_debianbts.py
+++ b/test/test_debianbts.py
@@ -1,16 +1,49 @@
-# -*- coding: utf-8; -*-
+import unittest2
 
-# test/test_debianbts.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
+from reportbug import utils
+from reportbug import debianbts
 
-""" Unit test for reportbuglib.debianbts module
-"""
+class TestDebianbts(unittest2.TestCase):
 
-import scaffold
+    def test_get_tags(self):
 
-from reportbug import debianbts
+        # for each severity, for each mode
+        self.assertItemsEqual(debianbts.get_tags('critical', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('grave', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('serious', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('important', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('does-not-build', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('normal', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('non-critical', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('minor', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('wishlist', utils.MODE_NOVICE).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+
+        self.assertItemsEqual(debianbts.get_tags('critical', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('grave', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('serious', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'security', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('important', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('does-not-build', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('normal', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('non-critical', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('minor', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+        self.assertItemsEqual(debianbts.get_tags('wishlist', utils.MODE_STANDARD).keys(), ['lfs', 'l10n', 'd-i', 'upstream', 'ipv6', 'patch'])
+
+        self.assertItemsEqual(debianbts.get_tags('critical', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('grave', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('serious', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('important', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('does-not-build', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('normal', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('non-critical', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('minor', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('wishlist', utils.MODE_ADVANCED).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+
+        self.assertItemsEqual(debianbts.get_tags('critical', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('grave', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('serious', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'security', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('important', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('does-not-build', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('normal', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('non-critical', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('minor', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
+        self.assertItemsEqual(debianbts.get_tags('wishlist', utils.MODE_EXPERT).keys(), ['sid', 'lenny', 'l10n', 'd-i', 'ipv6', 'patch', 'lfs', 'upstream', 'squeeze', 'experimental'])
diff --git a/test/test_exception.py b/test/test_exception.py
new file mode 100644
index 0000000..02a5219
--- /dev/null
+++ b/test/test_exception.py
@@ -0,0 +1,47 @@
+from __future__ import with_statement
+
+import unittest2
+
+from reportbug import exceptions
+
+class TestExceptions(unittest2.TestCase):
+
+    def test_raises_reportbug_exception(self):
+        with self.assertRaises(exceptions.reportbug_exception):
+            raise exceptions.reportbug_exception
+
+    def test_raises_reportbug_ui_exception(self):
+        with self.assertRaises(exceptions.reportbug_ui_exception):
+            raise exceptions.reportbug_ui_exception
+
+    def test_raises_UINotImportable(self):
+        with self.assertRaises(exceptions.UINotImportable):
+            raise exceptions.UINotImportable
+
+    def test_raises_NoPackage(self):
+        with self.assertRaises(exceptions.NoPackage):
+            raise exceptions.NoPackage
+
+    def test_raises_NoBugs(self):
+        with self.assertRaises(exceptions.NoBugs):
+            raise exceptions.NoBugs
+
+    def test_raises_NoReport(self):
+        with self.assertRaises(exceptions.NoReport):
+            raise exceptions.NoReport
+
+    def test_raises_UINotImplemented(self):
+        with self.assertRaises(exceptions.UINotImplemented):
+            raise exceptions.UINotImplemented
+
+    def test_raises_NoNetwork(self):
+        with self.assertRaises(exceptions.NoNetwork):
+            raise exceptions.NoNetwork
+
+    def test_raises_InvalidRegex(self):
+        with self.assertRaises(exceptions.InvalidRegex):
+            raise exceptions.InvalidRegex
+
+    def test_raises_NoMessage(self):
+        with self.assertRaises(exceptions.NoMessage):
+            raise exceptions.NoMessage
diff --git a/test/test_hiermatch.py b/test/test_hiermatch.py
index a6e5f79..c4b135c 100644
--- a/test/test_hiermatch.py
+++ b/test/test_hiermatch.py
@@ -1,32 +1,17 @@
-# -*- coding: utf-8; -*-
-
-# test/test_hiermatch.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.hiermatch module
-"""
-
-import scaffold
-from scaffold import TestCase
+import unittest2
 
 from reportbug import hiermatch
 
 test_strings_list = ['Beautiful is better than ugly.',
                      'Explicit is better than implicit.',
                      'Simple is better than complex.',
-                     'Complex is better than complicated.']
+                     'Complex is better than complicated.',
+                     'Flat is better than nested.',
+                     'Sparse is better than dense.']
 
+class TestHiermatch(unittest2.TestCase):
 
-class Test_egrep_list(TestCase):
-    """Test cases for 'egrep_list' """
+    def test_egrep_list(self):
+        matches = hiermatch.egrep_list(test_strings_list, 'better')
 
-    def test_it_works(self):
-        """ Should return '4' matches """
-        counts = hiermatch.egrep_list(test_strings_list, 'better')
-        
-        self.failUnlessEqual(len(counts), 4, "Not 4 matches")
+        self.assertEqual(len(matches), 6)
diff --git a/test/test_querybts_program.py b/test/test_querybts_program.py
deleted file mode 100644
index ba5d686..0000000
--- a/test/test_querybts_program.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_querybts_program.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for querybts program
-"""
-
-import os
-
-import scaffold
-
-module_name = 'querybts'
-module_file_path = os.path.join(scaffold.bin_dir, "querybts")
-querybts = scaffold.make_module_from_file(module_name, module_file_path)
diff --git a/test/test_rbtempfile.py b/test/test_rbtempfile.py
deleted file mode 100644
index 1806aa2..0000000
--- a/test/test_rbtempfile.py
+++ /dev/null
@@ -1,61 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_rbtempfile.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.rbtempfile module
-"""
-
-import os
-
-import scaffold
-from scaffold import TestCase
-
-from reportbug import tempfiles as rbtempfile
-
-
-class Test_cleanup_temp_file(TestCase):
-    """ Test cases for 'cleanup_temp_file' function """
-
-    def setUp(self):
-        """ Set up test fixtures """
-        self.mock_state = {
-            'os.unlink': None,
-            }
-        self.temp_filename = "foo.bar"
-        def mock_os_unlink(path):
-            if path != self.temp_filename:
-                raise IOError("Not found: %(path)s" % vars())
-            self.mock_state['os.unlink'] = path
-
-        self.os_unlink_prev = os.unlink
-        os.unlink = mock_os_unlink
-
-        def mock_os_path_exists(path):
-            exists = (path == self.temp_filename)
-            return exists
-
-        self.os_path_exists_prev = os.path.exists
-        os.path.exists = mock_os_path_exists
-
-    def tearDown(self):
-        """ Tear down test fixtures """
-        os.unlink = self.os_unlink_prev
-        os.path.exists = self.os_path_exists_prev
-
-    def test_unlink_file_if_exists(self):
-        """ Should unlink the named file if it exists """
-        path = self.temp_filename
-        rbtempfile.cleanup_temp_file(path)
-        self.failUnlessEqual(path, self.mock_state['os.unlink'])
-
-    def test_does_not_unlink_if_file_not_exist(self):
-        """ Should not call 'os.unlink' if file does not exist """
-        path = "bogus"
-        rbtempfile.cleanup_temp_file(path)
-        self.failUnlessEqual(None, self.mock_state['os.unlink'])
diff --git a/test/test_reportbug.py b/test/test_reportbug.py
deleted file mode 100644
index 1fc7263..0000000
--- a/test/test_reportbug.py
+++ /dev/null
@@ -1,147 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.reportbug module
-"""
-
-import os
-
-import scaffold
-from scaffold import TestCase
-
-from reportbug import utils as reportbug
-
-
-class Test_glob_escape(TestCase):
-    """ Test cases for 'glob_escape' function """
-
-    def test_preserves_non_specials(self):
-        """ glob_escape should preserve non-special characters
-        """
-        in_filename = r"foo-bar_baz"
-        expect_filename = in_filename
-        out_filename = reportbug.glob_escape(in_filename)
-        self.failUnlessEqual(expect_filename, out_filename)
-
-    def test_escapes_wildcard(self):
-        """ glob_escape should escape wildcard characters
-
-            Filename glob wildcard characters are '?' and '*'. These
-            should be escaped by a preceding backslash ('\').
-
-            """
-        in_filename = r"foo*bar?baz"
-        expect_filename = r"foo\*bar\?baz"
-        out_filename = reportbug.glob_escape(in_filename)
-        self.failUnlessEqual(expect_filename, out_filename)
-
-    def test_escapes_character_class(self):
-        """ glob_escape should escape character-class characters
-
-            Filename globs can have character classes enclosed by
-            brackets ('[', ']'). These should be escaped by a
-            preceding backslash ('\').
-
-            """
-        in_filename = r"foo[bar]baz"
-        expect_filename = r"foo\[bar\]baz"
-        out_filename = reportbug.glob_escape(in_filename)
-        self.failUnlessEqual(expect_filename, out_filename)
-
-
-class Test_which_editor(TestCase):
-    """ Test cases for 'which_editor' function """
-
-    def setUp(self):
-        """ Set up test fixtures """
-
-        stub_os_environ = {}
-        self.os_environ_prev = os.environ
-        os.environ = stub_os_environ
-
-        self.debian_default_editor = "bogus-default"
-
-    def tearDown(self):
-        """ Tear down test fixtures """
-        os.environ = self.os_environ_prev
-
-    def test_prefers_specified_default_editor_over_all(self):
-        """ Should return specified `default_editor`
-
-            The `default_editor` parameter should override all other
-            sources for an editor setting.
-
-            """
-        specified_editor = "foo-specified"
-        os.environ.update({
-            "VISUAL": "bogus-visual",
-            "EDITOR": "bogus-editor",
-            })
-        editor = reportbug.which_editor(specified_editor)
-        expect_editor = specified_editor
-        self.failUnlessEqual(expect_editor, editor)
-
-    def test_prefers_visual_variable_over_editor_variable(self):
-        """ Should return 'VISUAL' variable rather than 'EDITOR'
-
-            The 'VISUAL' environment variable should be preferred over
-            the 'EDITOR' variable.
-
-            """
-        os.environ.update({
-            "VISUAL": "foo-visual",
-            "EDITOR": "bogus-editor",
-            })
-        editor = reportbug.which_editor()
-        expect_editor = os.environ["VISUAL"]
-        self.failUnlessEqual(expect_editor, editor)
-
-    def test_prefers_editor_variable_over_debian_default(self):
-        """ Should return 'EDITOR' variable rather than Debian default
-
-            The 'EDITOR' environment variable should be preferred over
-            the Debian default editor.
-
-            """
-        os.environ.update({
-            "EDITOR": "foo-editor",
-            })
-        editor = reportbug.which_editor()
-        expect_editor = os.environ["EDITOR"]
-        self.failUnlessEqual(expect_editor, editor)
-
-    def test_prefers_debian_default_over_nothing(self):
-        """ Should return Debian default when no other alternative
-
-            The Debian default editor should be returned when no other
-            alternative is set.
-
-            """
-        self.debian_default_editor = "/usr/bin/sensible-editor"
-        editor = reportbug.which_editor()
-        expect_editor = self.debian_default_editor
-        self.failUnlessEqual(expect_editor, editor)
-
-    def test_empty_string_value_skipped_in_precendence(self):
-        """ Should skip an empty string value in the precedence check
-
-            An empty string value should cause the precedence check to
-            skip the value as though it were unset.
-
-            """
-        specified_editor = ""
-        os.environ.update({
-            "VISUAL": "",
-            "EDITOR": "",
-            })
-        self.debian_default_editor = "/usr/bin/sensible-editor"
-        editor = reportbug.which_editor(specified_editor)
-        expect_editor = self.debian_default_editor
-        self.failUnlessEqual(expect_editor, editor)
diff --git a/test/test_reportbug_exceptions.py b/test/test_reportbug_exceptions.py
deleted file mode 100644
index e948324..0000000
--- a/test/test_reportbug_exceptions.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug_exceptions.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.reportbug_exceptions module
-"""
-
-import scaffold
-
-from reportbug import exceptions as reportbug_exceptions
diff --git a/test/test_reportbug_program.py b/test/test_reportbug_program.py
deleted file mode 100644
index e261db1..0000000
--- a/test/test_reportbug_program.py
+++ /dev/null
@@ -1,180 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug_program.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbug program
-"""
-
-import __builtin__
-import os
-from StringIO import StringIO
-
-import scaffold
-from scaffold import TestCase
-
-module_name = 'reportbug'
-module_file_path = os.path.join(scaffold.bin_dir, "reportbug")
-reportbug = scaffold.make_module_from_file(module_name, module_file_path)
-
-
-def setup_include_file_in_report_fixture(testcase):
-    """ Set up test fixtures for 'include_file_in_report' function """
-
-    testcase.temp_filename = "bogus"
-    testcase.temp_file = StringIO()
-    testcase.temp_file.actually_close = testcase.temp_file.close
-    testcase.temp_file.close = lambda: None
-
-    def stub_temp_file(
-        suffix="", prefix=None, dir=None, text=True,
-        mode="w+", bufsize=-1):
-        """ Return a stub file and filename
-
-
-            :return value:
-                Tuple (`temp_file`, `temp_filename`)
-
-                The filename will be as set in the testcase's
-                `temp_filename` attribute.
-
-                The file returned will be a StringIO buffer, with the
-                `close` method disabled. The `actually_close` method
-                will free the buffer.
-
-            """
-        temp_filename = testcase.temp_filename
-        temp_file = testcase.temp_file
-        return (temp_file, temp_filename)
-    testcase.stub_temp_file = stub_temp_file
-
-
-class Test_include_file_in_report(TestCase):
-    """ Test cases for 'include_file_in_report' function """
-
-    def setUp(self):
-        """ Set up test fixtures """
-
-        setup_include_file_in_report_fixture(self)
-
-        self.temp_file_func_prev = reportbug.TempFile
-        reportbug.TempFile = self.stub_temp_file
-
-    def tearDown(self):
-        """ Tear down test fixtures """
-        reportbug.TempFile = self.temp_file_func_prev
-
-    def test_adds_include_filename_to_attachments(self):
-        """ Filename of include file should be added to attachments
-
-            When the `inline` parameter is not True, the filename of
-            the include file should be appended to the
-            attachment_filenames list.
-
-            """
-        message = ""
-        message_filename = "report"
-        attachment_filenames = ["foo", "bar"]
-        package_name = "spam"
-        charset = 'utf-8'
-        include_filename = self.temp_filename
-        expect_attachment_filenames = attachment_filenames
-        expect_attachment_filenames.append(include_filename)
-        (nil, nil, attachment_filenames) = reportbug.include_file_in_report(
-            message, message_filename, attachment_filenames, package_name,
-            include_filename, charset)
-        self.failUnlessEqual(
-            expect_attachment_filenames, attachment_filenames)
-
-class Test_include_file_in_report_inline(TestCase):
-    """ Test cases for 'include_file_in_report' function, inline=True """
-
-    def setUp(self):
-        """ Set up test fixtures """
-
-        setup_include_file_in_report_fixture(self)
-
-        self.temp_file_func_prev = reportbug.TempFile
-        reportbug.TempFile = self.stub_temp_file
-
-        self.message = """
-            Lorem ipsum.
-            Lorem ipsum.
-            """
-        self.message_filename = "report"
-        self.attachment_filenames = []
-        self.package_name = "spam"
-        self.charset = "utf-8"
-
-        self.include_filename = "bogus_include"
-        self.include_file_content = """
-            Phasellus posuere. Nulla malesuada lacinia justo.
-            Nunc condimentum ante vitae erat.
-            """
-        self.include_file = StringIO(self.include_file_content)
-
-        self.builtin_file_prev = __builtin__.file
-        def stub_builtin_file(path, mode=None, buffering=None):
-            if path != self.include_filename:
-                raise IOError("Not found: %(path)s" % vars())
-            return self.include_file
-        __builtin__.file = stub_builtin_file
-
-        self.os_unlink_prev = os.unlink
-        def stub_os_unlink(filename):
-            pass
-        os.unlink = stub_os_unlink
-
-    def tearDown(self):
-        """ Tear down test fixtures """
-        self.temp_file.actually_close()
-        reportbug.TempFile = self.temp_file_func_prev
-        __builtin__.file = self.builtin_file_prev
-        os.unlink = self.os_unlink_prev
-
-    def test_adds_include_file_content_to_message(self):
-        """ Content of include file should be added to message
-
-            When the `inline` parameter is True, the content of the
-            include file should be added into the report message.
-
-            """
-        (message, nil, nil) = reportbug.include_file_in_report(
-            self.message, self.message_filename,
-            self.attachment_filenames, self.package_name,
-            self.include_filename, self.charset, inline=True)
-        self.failUnlessIn(message, self.include_file_content)
-
-    def test_returns_new_temp_filename_as_message_filename(self):
-        """ New message filename should be as generated by TempFile
-
-            When the `inline` parameter is True, the returned message
-            filename should be that of the generated temporary file.
-
-            """
-        (nil, message_filename, nil) = reportbug.include_file_in_report(
-            self.message, self.message_filename,
-            self.attachment_filenames, self.package_name,
-            self.include_filename, self.charset, inline=True)
-        temp_filename = self.temp_filename
-        self.failUnlessEqual(message_filename, temp_filename)
-
-    def test_writes_new_message_content_to_report_file(self):
-        """ New message content should be written to report file
-
-            When the `inline` parameter is True, the updated content
-            of the message should be written to the report file.
-
-            """
-        (message, nil, nil) = reportbug.include_file_in_report(
-            self.message, self.message_filename,
-            self.attachment_filenames, self.package_name,
-            self.include_filename, self.charset, inline=True)
-        temp_filename = self.temp_filename
-        temp_file = self.temp_file
-        self.failUnlessEqual(message, temp_file.getvalue())
diff --git a/test/test_reportbug_submit.py b/test/test_reportbug_submit.py
deleted file mode 100644
index c81addc..0000000
--- a/test/test_reportbug_submit.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug_submit.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.reportbug_submit module
-"""
-
-import scaffold
-
-from reportbug import submit as reportbug_submit
diff --git a/test/test_reportbug_ui_text.py b/test/test_reportbug_ui_text.py
deleted file mode 100644
index 04e35fe..0000000
--- a/test/test_reportbug_ui_text.py
+++ /dev/null
@@ -1,16 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug_ui_text.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.reportbug_ui_text module
-"""
-
-import scaffold
-
-from reportbug.ui import text_ui as reportbug_ui_text
diff --git a/test/test_reportbug_ui_urwid.py b/test/test_reportbug_ui_urwid.py
deleted file mode 100644
index 820cf89..0000000
--- a/test/test_reportbug_ui_urwid.py
+++ /dev/null
@@ -1,47 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_reportbug_ui_urwid.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.reportbug_ui_urwid module
-"""
-
-import scaffold
-from scaffold import TestCase
-
-from reportbug.ui import urwid_ui as reportbug_ui_urwid
-from reportbug.ui import text_ui as reportbug_ui_text
-
-
-class Test_ewrite(TestCase):
-    """ Test cases for 'ewrite' """
-
-    def test_is_expected_object(self):
-        """ Module should have expected 'ewrite' attribute """
-        attribute_name = 'ewrite'
-        func = getattr(reportbug_ui_urwid, attribute_name)
-        expect_func = getattr(reportbug_ui_text, attribute_name)
-        fail_msg = (
-            "Module attribute %(attribute_name)r"
-            " should be object %(expect_func)r"
-            ) % vars()
-        self.failUnlessIs(expect_func, func, msg=fail_msg)
-
-class Test_spawn_editor(TestCase):
-    """ Test cases for 'spawn_editor' """
-
-    def test_is_expected_object(self):
-        """ Module should have expected 'spawn_editor' attribute """
-        attribute_name = 'spawn_editor'
-        func = getattr(reportbug_ui_urwid, attribute_name)
-        expect_func = getattr(reportbug_ui_text, attribute_name)
-        fail_msg = (
-            "Module attribute %(attribute_name)r"
-            " should be object %(expect_func)r"
-            ) % vars()
-        self.failUnlessIs(expect_func, func, msg=fail_msg)
diff --git a/test/test_tempfiles.py b/test/test_tempfiles.py
new file mode 100644
index 0000000..d984f96
--- /dev/null
+++ b/test/test_tempfiles.py
@@ -0,0 +1,22 @@
+import unittest2
+
+from reportbug import tempfiles
+
+class TestTempfiles(unittest2.TestCase):
+
+    def test_tempfile_prefix(self):
+
+        extra = 'dummystring'
+
+        prefix = tempfiles.tempfile_prefix()
+        self.assertIn('reportbug', prefix)
+
+        prefix = tempfiles.tempfile_prefix(package='dpkg')
+        self.assertIn('dpkg', prefix)
+
+        prefix = tempfiles.tempfile_prefix(package='', extra=extra)
+        self.assertIn(extra, prefix)
+
+        prefix = tempfiles.tempfile_prefix(package='dpkg', extra=extra)
+        self.assertIn('dpkg', prefix)
+        self.assertIn(extra, prefix)
diff --git a/test/test_ui.py b/test/test_ui.py
new file mode 100644
index 0000000..7a80105
--- /dev/null
+++ b/test/test_ui.py
@@ -0,0 +1,12 @@
+""" Unit test for reportbug.ui module """
+
+import unittest2
+
+from reportbug import utils
+from reportbug import ui
+
+class TestUI(unittest2.TestCase):
+
+    def test_ui(self):
+        self.assertItemsEqual(ui.AVAILABLE_UIS, ['text', 'urwid', 'gtk2'])
+        
diff --git a/test/test_urlutils.py b/test/test_urlutils.py
deleted file mode 100644
index 2552b45..0000000
--- a/test/test_urlutils.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# -*- coding: utf-8; -*-
-
-# test/test_urlutils.py
-# Part of reportbug, a Debian bug reporting tool.
-#
-# Copyright © 2008 Ben Finney <ben+python at benfinney.id.au>
-# This is free software; you may copy, modify and/or distribute this work
-# under the terms of the GNU General Public License, version 2 or later.
-# No warranty expressed or implied. See the file LICENSE for details.
-
-""" Unit test for reportbuglib.urlutils module
-"""
-
-import httplib
-
-import scaffold
-from scaffold import TestCase
-
-from reportbug import exceptions as reportbug_exceptions
-from reportbug import urlutils
-
-
-class StubObject(object):
-    """ A stub object that allows any access. """
-
-    def __init__(self, *args, **kwargs):
-        pass
-
-    def __getattr__(self, name):
-        return StubObject()
-
-    def __call__(self, *args, **kwargs):
-        return StubObject()
-
-
-class Test_open_url(TestCase):
-    """ Test cases for urlopen function """
-
-    def setUp(self):
-        """ Set up test fixtures """
-        self.stub_opener = StubObject()
-        def stub_build_opener(*args, **kwargs):
-            return self.stub_opener
-
-        self.urllib2_prev = urlutils.urllib2
-        self.stub_urllib2 = StubObject()
-        urlutils.urllib2 = self.stub_urllib2
-
-        self.stub_urllib2.Request = StubObject
-        self.stub_urllib2.build_opener = stub_build_opener
-
-    def tearDown(self):
-        """ Tear down test fixtures """
-        urlutils.urllib2 = self.urllib2_prev
-
-    def test_raises_no_network_when_http_exception(self):
-        """ Should raise NoNetwork when opener raises HTTPExeception """
-        class ArbitraryHTTPException(httplib.HTTPException):
-            pass
-        def stub_raise_bad_status_line(self, *args, **kwargs):
-            message = "Bad HTTP stuff happened!"
-            raise ArbitraryHTTPException(message)
-        self.stub_opener.open = stub_raise_bad_status_line
-
-        url = "foo"
-        expect_exception = reportbug_exceptions.NoNetwork
-        self.failUnlessRaises(
-            expect_exception,
-            urlutils.open_url, url)
diff --git a/test/test_utils.py b/test/test_utils.py
new file mode 100644
index 0000000..4d7f6ae
--- /dev/null
+++ b/test/test_utils.py
@@ -0,0 +1,98 @@
+import unittest2
+
+from reportbug import utils
+
+class TestUtils(unittest2.TestCase):
+
+    def test_modes_and_modelist(self):
+        """Check MODES items and MODELIST are in sync"""
+
+        self.assertItemsEqual(utils.MODES.keys(), utils.MODELIST)
+
+class TestEmail(unittest2.TestCase):
+
+    def test_check_email_addr(self):
+        
+        real_addr = 'reportbug-maint at lists.alioth.debian.org'
+
+        self.assertTrue(utils.check_email_addr(real_addr))
+        self.assertFalse(utils.check_email_addr('dummy'))
+        self.assertFalse(utils.check_email_addr('nouser at nodomain'))
+
+    def test_get_email_addr(self):
+
+        email = 'Reportbug Maintainers <reportbug-maint at lists.alioth.debian.org>'
+        name, email_addr = utils.get_email_addr(email)
+
+        self.assertEqual(name, 'Reportbug Maintainers')
+        self.assertEqual(email_addr, 'reportbug-maint at lists.alioth.debian.org')
+
+class TestPackages(unittest2.TestCase):
+
+    def test_get_package_status(self):
+
+        status = utils.get_package_status('non-existing-package')
+
+        (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
+         installed, origin, vendor, reportinfo, priority, desc, src_name,
+         fulldesc, state, suggests) = status
+
+        self.assertIsNone(pkgversion)
+        self.assertIsNone(pkgavail)
+        self.assertEqual(depends, ())
+        self.assertEqual(recommends, ())
+        self.assertEqual(conffiles, ())
+        self.assertIsNone(maintainer)
+        self.assertFalse(installed)
+        self.assertIsNone(origin)
+        self.assertEqual(vendor, '')
+        self.assertIsNone(reportinfo)
+        self.assertIsNone(priority)
+        self.assertIsNone(desc)
+        self.assertIsNone(src_name)
+        self.assertEqual(fulldesc, '')
+        self.assertEqual(state, '')
+        self.assertEqual(suggests, ())
+
+        # Using an 'Essential: yes' package, what's better than 'dpkg'?
+        status = utils.get_package_status('dpkg')
+
+        (pkgversion, pkgavail, depends, recommends, conffiles, maintainer,
+         installed, origin, vendor, reportinfo, priority, desc, src_name,
+         fulldesc, state, suggests) = status
+
+        self.assertIsNotNone(pkgversion)
+        self.assertEqual(pkgavail, 'dpkg')
+        # let's just check Depends is not null
+        self.assertIsNotNone(depends)
+        self.assertIsNotNone(maintainer)
+        self.assertTrue(installed)
+        self.assertEqual(origin, 'debian')
+        self.assertEqual(priority, 'required')
+        self.assertIsNotNone(desc)
+        self.assertIsNotNone(fulldesc)
+        self.assertEqual(state, 'installed')
+
+ at unittest2.skip("Too slow")
+class TestSourcePackages(unittest2.TestCase):
+
+    def test_get_source_name(self):
+        binpkg = 'python-reportbug'
+        src = utils.get_source_name(binpkg)
+        self.assertEqual(src, 'reportbug')
+
+    def test_get_source_package(self):
+        src = 'reportbug'
+        binpkgs = utils.get_source_package(src)
+        self.assertItemsEqual([bin[0] for bin in binpkgs], ['python-reportbug', 'reportbug'])
+
+        bin = 'python-reportbug'
+        binpkgs_frombin = utils.get_source_package(bin)
+        self.assertEqual(binpkgs, binpkgs_frombin)
+
+class TestSystemInformation(unittest2.TestCase):
+
+    def test_get_cpu_cores(self):
+
+        cores = utils.get_cpu_cores()
+        self.assertGreaterEqual(cores, 1)

-- 
Reportbug - reports bugs in the Debian distribution



More information about the Reportbug-commits mailing list