Merge lp:~barry/pkgme/test-fixes into lp:pkgme

Proposed by Barry Warsaw
Status: Merged
Merged at revision: 42
Proposed branch: lp:~barry/pkgme/test-fixes
Merge into: lp:pkgme
Diff against target: 186 lines (+63/-32)
6 files modified
pkgme/backend.py (+41/-4)
pkgme/testing.py (+14/-0)
pkgme/tests/__init__.py (+0/-19)
pkgme/tests/test_python_backend.py (+2/-4)
pkgme/tests/test_vala_backend.py (+5/-5)
setup.py (+1/-0)
To merge this branch: bzr merge lp:~barry/pkgme/test-fixes
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+44121@code.launchpad.net

Description of the change

This fixes all the tests for me.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

80 + def __repr__(self):
81 + return '<TempdirFixture: {0}'.format(self.path)
82 +

Missing ">"?

92 +def command_exists(command_name):
93 + try:
94 + subprocess.call(command_name)
95 + except OSError:
96 + # Assume command not found.
97 + return False
98 + else:
99 + return True

Could we have this be a str(e)/None interface or similar? That way we can include the reason in the skip message, and people won't be confused when it is saying that vala-dep-scanner isn't installed when it's just not executable or something.

105 -import unittest
106 -
107 -def test_suite():
108 - module_names = [
109 - 'pkgme.tests.test_backend',
110 - 'pkgme.tests.test_distutils_command',
111 - 'pkgme.tests.test_info_elements',
112 - 'pkgme.tests.test_package_files',
113 - 'pkgme.tests.test_project_info',
114 - 'pkgme.tests.test_python_backend',
115 - 'pkgme.tests.test_script',
116 - 'pkgme.tests.test_template_file',
117 - 'pkgme.tests.test_vala_backend',
118 - 'pkgme.tests.test_write',
119 - 'pkgme.tests.test_write_packaging',
120 - ]
121 - loader = unittest.TestLoader()
122 - suite = loader.loadTestsFromNames(module_names)
123 - return suite

Can we keep this? I use testr to run the tests, and I don't think there's
a way to get subunit output from "setup.py test"?

Otherwise this change looks good to me.

Thanks,

James

review: Approve
Revision history for this message
Barry Warsaw (barry) wrote :

On Dec 18, 2010, at 01:23 AM, James Westby wrote:

>Review: Approve
>80 + def __repr__(self):
>81 + return '<TempdirFixture: {0}'.format(self.path)
>82 +
>
>Missing ">"?

Yep, thanks.

>
>92 +def command_exists(command_name):
>93 + try:
>94 + subprocess.call(command_name)
>95 + except OSError:
>96 + # Assume command not found.
>97 + return False
>98 + else:
>99 + return True
>
>Could we have this be a str(e)/None interface or similar? That way we can include the reason in the skip message, and people won't be confused when it is saying that vala-dep-scanner isn't installed when it's just not executable or something.

Good idea.

>105 -import unittest
>106 -
>107 -def test_suite():
>108 - module_names = [
>109 - 'pkgme.tests.test_backend',
>110 - 'pkgme.tests.test_distutils_command',
>111 - 'pkgme.tests.test_info_elements',
>112 - 'pkgme.tests.test_package_files',
>113 - 'pkgme.tests.test_project_info',
>114 - 'pkgme.tests.test_python_backend',
>115 - 'pkgme.tests.test_script',
>116 - 'pkgme.tests.test_template_file',
>117 - 'pkgme.tests.test_vala_backend',
>118 - 'pkgme.tests.test_write',
>119 - 'pkgme.tests.test_write_packaging',
>120 - ]
>121 - loader = unittest.TestLoader()
>122 - suite = loader.loadTestsFromNames(module_names)
>123 - return suite
>
>Can we keep this? I use testr to run the tests, and I don't think there's
>a way to get subunit output from "setup.py test"?

We can keep it, but I'll add a note that it is ignored by 'setup.py test'. I
don't know much about hooking up subunit to that. I'll try to investigate a
little bit.

>Otherwise this change looks good to me.

Thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== removed directory 'bin'
=== modified file 'pkgme/backend.py'
--- pkgme/backend.py 2010-12-13 01:34:21 +0000
+++ pkgme/backend.py 2010-12-18 01:04:12 +0000
@@ -1,6 +1,13 @@
1import os1import os
2import sys
2import subprocess3import subprocess
34
5try:
6 from sysconfig import get_platform
7except ImportError:
8 # Python < 2.7
9 from distutils.util import get_platform
10
4from pkgme.project_info import (11from pkgme.project_info import (
5 ExternalHelperFailed,12 ExternalHelperFailed,
6 MultipleExternalHelpersInfo,13 MultipleExternalHelpersInfo,
@@ -9,10 +16,40 @@
916
1017
11EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]18EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
12root_dir = os.path.join(19
13 os.path.dirname(os.path.abspath(__file__)), os.pardir)20
14if os.path.exists(os.path.join(root_dir, "setup.py")):21def get_backend_dir(underunder_file, backend):
15 EXTERNAL_BACKEND_PATHS.insert(0, os.path.join(root_dir, "pkgme", "backends"))22 backend_dir = os.path.normpath(
23 os.path.join(
24 os.path.dirname(underunder_file), os.pardir,
25 'backends', backend))
26 # When 'python setup.py test' is run with virtualenv, backend_dir will not
27 # point to the right place. It will point into the
28 # build/lib.{platform}-{version} directory and that cannot be used as a
29 # landmark to find the backends directory. Assuming we're running the
30 # tests from the top of the tree, we do the best we can to find the actual
31 # landmark.
32 parts = backend_dir.split(os.sep)
33 try:
34 i = parts.index('build')
35 # Stolen from site.py's addbuilddir().
36 s = 'lib.%s-%.3s' % (get_platform(), sys.version)
37 if hasattr(sys, 'gettotalrefcount'):
38 s += '-pydebug'
39 if parts[i + 1] == s:
40 del parts[i:i+2]
41 backend_dir = os.sep.join(parts)
42 except (ValueError, IndexError):
43 # We're (probably) not in the build environment.
44 pass
45 return backend_dir
46
47
48root_dir = os.path.dirname(get_backend_dir(__file__, ''))
49
50if os.path.exists(os.path.join(root_dir, 'setup.py')):
51 EXTERNAL_BACKEND_PATHS.insert(
52 0, os.path.join(root_dir, 'pkgme', 'backends'))
1653
1754
18def get_info_for(path, loader=None, selector_cls=None):55def get_info_for(path, loader=None, selector_cls=None):
1956
=== modified file 'pkgme/testing.py'
--- pkgme/testing.py 2010-11-09 19:49:39 +0000
+++ pkgme/testing.py 2010-12-18 01:04:12 +0000
@@ -1,6 +1,7 @@
1import os1import os
2import shutil2import shutil
3import tempfile3import tempfile
4import subprocess
45
5from debian import deb8226from debian import deb822
6from fixtures import Fixture7from fixtures import Fixture
@@ -78,6 +79,9 @@
78 self.path = tempfile.mkdtemp(prefix="pkgme-tests-")79 self.path = tempfile.mkdtemp(prefix="pkgme-tests-")
79 self.addCleanup(shutil.rmtree, self.path)80 self.addCleanup(shutil.rmtree, self.path)
8081
82 def __repr__(self):
83 return '<TempdirFixture: {0}'.format(self.path)
84
8185
82class ExecutableFileFixture(Fixture):86class ExecutableFileFixture(Fixture):
8387
@@ -185,3 +189,13 @@
185189
186 def describe(self):190 def describe(self):
187 return "Has key %s" % self.key191 return "Has key %s" % self.key
192
193
194def command_exists(command_name):
195 try:
196 subprocess.call(command_name)
197 except OSError:
198 # Assume command not found.
199 return False
200 else:
201 return True
188202
=== modified file 'pkgme/tests/__init__.py'
--- pkgme/tests/__init__.py 2010-11-13 02:54:02 +0000
+++ pkgme/tests/__init__.py 2010-12-18 01:04:12 +0000
@@ -1,19 +0,0 @@
1import unittest
2
3def test_suite():
4 module_names = [
5 'pkgme.tests.test_backend',
6 'pkgme.tests.test_distutils_command',
7 'pkgme.tests.test_info_elements',
8 'pkgme.tests.test_package_files',
9 'pkgme.tests.test_project_info',
10 'pkgme.tests.test_python_backend',
11 'pkgme.tests.test_script',
12 'pkgme.tests.test_template_file',
13 'pkgme.tests.test_vala_backend',
14 'pkgme.tests.test_write',
15 'pkgme.tests.test_write_packaging',
16 ]
17 loader = unittest.TestLoader()
18 suite = loader.loadTestsFromNames(module_names)
19 return suite
200
=== modified file 'pkgme/tests/test_python_backend.py'
--- pkgme/tests/test_python_backend.py 2010-11-10 21:53:56 +0000
+++ pkgme/tests/test_python_backend.py 2010-12-18 01:04:12 +0000
@@ -3,13 +3,11 @@
3from fixtures import TestWithFixtures3from fixtures import TestWithFixtures
4from testtools import TestCase4from testtools import TestCase
55
6from pkgme.backend import ExternalHelpersBackend6from pkgme.backend import ExternalHelpersBackend, get_backend_dir
7from pkgme.testing import TempdirFixture7from pkgme.testing import TempdirFixture
88
99
10backend_dir = os.path.join(10backend_dir = get_backend_dir(__file__, 'python')
11 os.path.dirname(os.path.abspath(__file__)), os.pardir,
12 "backends", "python")
1311
1412
15class PythonBackendTests(TestCase, TestWithFixtures):13class PythonBackendTests(TestCase, TestWithFixtures):
1614
=== modified file 'pkgme/tests/test_vala_backend.py'
--- pkgme/tests/test_vala_backend.py 2010-11-30 14:49:35 +0000
+++ pkgme/tests/test_vala_backend.py 2010-12-18 01:04:12 +0000
@@ -23,14 +23,12 @@
23from fixtures import TestWithFixtures23from fixtures import TestWithFixtures
24from testtools import TestCase24from testtools import TestCase
2525
26from pkgme.backend import ExternalHelpersBackend26from pkgme.backend import ExternalHelpersBackend, get_backend_dir
27from pkgme.testing import TempdirFixture27from pkgme.testing import TempdirFixture, command_exists
28from pkgme.write import write_file28from pkgme.write import write_file
2929
3030
31backend_dir = os.path.join(31backend_dir = get_backend_dir(__file__, 'vala')
32 os.path.dirname(os.path.abspath(__file__)), os.pardir,
33 "backends", "vala")
3432
3533
36class PythonBackendTests(TestCase, TestWithFixtures):34class PythonBackendTests(TestCase, TestWithFixtures):
@@ -90,6 +88,8 @@
90 {"buildsystem": "autoconf"}, info.get_all(["buildsystem"]))88 {"buildsystem": "autoconf"}, info.get_all(["buildsystem"]))
9189
92 def test_build_depends(self):90 def test_build_depends(self):
91 if not command_exists('vala-dep-scanner'):
92 self.skipTest('vala-dep-scanner is missing')
93 self.write_file_in_tempdir("main.vala", "Gtk.Window win;")93 self.write_file_in_tempdir("main.vala", "Gtk.Window win;")
94 info = self.get_info()94 info = self.get_info()
95 self.assertEqual(95 self.assertEqual(
9696
=== modified file 'setup.py'
--- setup.py 2010-12-08 02:00:29 +0000
+++ setup.py 2010-12-18 01:04:12 +0000
@@ -47,6 +47,7 @@
47 'argparse',47 'argparse',
48 'cheetah',48 'cheetah',
49 'fixtures',49 'fixtures',
50 'testtools',
50 ],51 ],
51 entry_points = {52 entry_points = {
52 'console_scripts': ['pkgme=pkgme.bin.main:main'],53 'console_scripts': ['pkgme=pkgme.bin.main:main'],

Subscribers

People subscribed via source and target branches

to all changes: