Merge lp:~james-w/pkgme/informative-skip-message into lp:pkgme

Proposed by James Westby
Status: Merged
Merged at revision: 58
Proposed branch: lp:~james-w/pkgme/informative-skip-message
Merge into: lp:pkgme
Diff against target: 54 lines (+18/-5)
2 files modified
pkgme/testing.py (+15/-0)
pkgme/tests/test_vala_backend.py (+3/-5)
To merge this branch: bzr merge lp:~james-w/pkgme/informative-skip-message
Reviewer Review Type Date Requested Status
Jonathan Lange Approve
pkgme committers Pending
Review via email: mp+66538@code.launchpad.net

Description of the change

Hi,

This adds a helper for requiring a command for a test method.

It's main use it to give an informative error message with little typing.

It's used to make the one use of require_command with skipTest be more
informative.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

This is good. I would probably have implemented it as, well, anything other than a mixin. e.g. testtools provides @skipIf and @skipUnless decorators. They wouldn't be as informative as this, but you could build something more informative from them.

Huh. I guess this is a useful prompt for testtools to have something to make this easier, much like bzr's feature thing.

Anyway, I'd be happy merging this.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkgme/testing.py'
2--- pkgme/testing.py 2010-12-18 14:40:42 +0000
3+++ pkgme/testing.py 2011-07-01 02:04:33 +0000
4@@ -205,3 +205,18 @@
5 return str(error)
6 else:
7 return None
8+
9+
10+class CommandRequiredTestCase(object):
11+
12+ def skipTestIfCommandNotExecutable(self, command_name):
13+ """Skip the test if a particular command can't be run.
14+
15+ Try running the passed command, and if it fails then skip the test.
16+ :param command_name: the name of the command to check
17+ :return: None
18+ :raises: TestSkipped if command_name can't be run.
19+ """
20+ find_error = require_command(command_name)
21+ if find_error is not None:
22+ self.skipTest("'%s' not executable: %s" % (command_name, find_error))
23
24=== modified file 'pkgme/tests/test_vala_backend.py'
25--- pkgme/tests/test_vala_backend.py 2011-01-16 19:04:50 +0000
26+++ pkgme/tests/test_vala_backend.py 2011-07-01 02:04:33 +0000
27@@ -24,14 +24,14 @@
28 from testtools import TestCase
29
30 from pkgme.backend import ExternalHelpersBackend, get_backend_dir
31-from pkgme.testing import TempdirFixture, require_command
32+from pkgme.testing import CommandRequiredTestCase, TempdirFixture
33 from pkgme.write import write_file
34
35
36 backend_dir = get_backend_dir(__file__, 'vala')
37
38
39-class ValaBackendTests(TestCase, TestWithFixtures):
40+class ValaBackendTests(TestCase, TestWithFixtures, CommandRequiredTestCase):
41
42 def setUp(self):
43 super(ValaBackendTests, self).setUp()
44@@ -88,9 +88,7 @@
45 {"buildsystem": "autoconf"}, info.get_all(["buildsystem"]))
46
47 def test_build_depends(self):
48- find_error = require_command('vala-dep-scanner')
49- if find_error is not None:
50- self.skipTest(find_error)
51+ self.skipTestIfCommandNotExecutable('vala-dep-scanner')
52 self.write_file_in_tempdir("main.vala", "Gtk.Window win;")
53 info = self.get_info()
54 self.assertEqual(

Subscribers

People subscribed via source and target branches

to all changes: