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
1=== removed directory 'bin'
2=== modified file 'pkgme/backend.py'
3--- pkgme/backend.py 2010-12-13 01:34:21 +0000
4+++ pkgme/backend.py 2010-12-18 01:04:12 +0000
5@@ -1,6 +1,13 @@
6 import os
7+import sys
8 import subprocess
9
10+try:
11+ from sysconfig import get_platform
12+except ImportError:
13+ # Python < 2.7
14+ from distutils.util import get_platform
15+
16 from pkgme.project_info import (
17 ExternalHelperFailed,
18 MultipleExternalHelpersInfo,
19@@ -9,10 +16,40 @@
20
21
22 EXTERNAL_BACKEND_PATHS = ["/usr/share/pkgme/backends/"]
23-root_dir = os.path.join(
24- os.path.dirname(os.path.abspath(__file__)), os.pardir)
25-if os.path.exists(os.path.join(root_dir, "setup.py")):
26- EXTERNAL_BACKEND_PATHS.insert(0, os.path.join(root_dir, "pkgme", "backends"))
27+
28+
29+def get_backend_dir(underunder_file, backend):
30+ backend_dir = os.path.normpath(
31+ os.path.join(
32+ os.path.dirname(underunder_file), os.pardir,
33+ 'backends', backend))
34+ # When 'python setup.py test' is run with virtualenv, backend_dir will not
35+ # point to the right place. It will point into the
36+ # build/lib.{platform}-{version} directory and that cannot be used as a
37+ # landmark to find the backends directory. Assuming we're running the
38+ # tests from the top of the tree, we do the best we can to find the actual
39+ # landmark.
40+ parts = backend_dir.split(os.sep)
41+ try:
42+ i = parts.index('build')
43+ # Stolen from site.py's addbuilddir().
44+ s = 'lib.%s-%.3s' % (get_platform(), sys.version)
45+ if hasattr(sys, 'gettotalrefcount'):
46+ s += '-pydebug'
47+ if parts[i + 1] == s:
48+ del parts[i:i+2]
49+ backend_dir = os.sep.join(parts)
50+ except (ValueError, IndexError):
51+ # We're (probably) not in the build environment.
52+ pass
53+ return backend_dir
54+
55+
56+root_dir = os.path.dirname(get_backend_dir(__file__, ''))
57+
58+if os.path.exists(os.path.join(root_dir, 'setup.py')):
59+ EXTERNAL_BACKEND_PATHS.insert(
60+ 0, os.path.join(root_dir, 'pkgme', 'backends'))
61
62
63 def get_info_for(path, loader=None, selector_cls=None):
64
65=== modified file 'pkgme/testing.py'
66--- pkgme/testing.py 2010-11-09 19:49:39 +0000
67+++ pkgme/testing.py 2010-12-18 01:04:12 +0000
68@@ -1,6 +1,7 @@
69 import os
70 import shutil
71 import tempfile
72+import subprocess
73
74 from debian import deb822
75 from fixtures import Fixture
76@@ -78,6 +79,9 @@
77 self.path = tempfile.mkdtemp(prefix="pkgme-tests-")
78 self.addCleanup(shutil.rmtree, self.path)
79
80+ def __repr__(self):
81+ return '<TempdirFixture: {0}'.format(self.path)
82+
83
84 class ExecutableFileFixture(Fixture):
85
86@@ -185,3 +189,13 @@
87
88 def describe(self):
89 return "Has key %s" % self.key
90+
91+
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
100
101=== modified file 'pkgme/tests/__init__.py'
102--- pkgme/tests/__init__.py 2010-11-13 02:54:02 +0000
103+++ pkgme/tests/__init__.py 2010-12-18 01:04:12 +0000
104@@ -1,19 +0,0 @@
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
124
125=== modified file 'pkgme/tests/test_python_backend.py'
126--- pkgme/tests/test_python_backend.py 2010-11-10 21:53:56 +0000
127+++ pkgme/tests/test_python_backend.py 2010-12-18 01:04:12 +0000
128@@ -3,13 +3,11 @@
129 from fixtures import TestWithFixtures
130 from testtools import TestCase
131
132-from pkgme.backend import ExternalHelpersBackend
133+from pkgme.backend import ExternalHelpersBackend, get_backend_dir
134 from pkgme.testing import TempdirFixture
135
136
137-backend_dir = os.path.join(
138- os.path.dirname(os.path.abspath(__file__)), os.pardir,
139- "backends", "python")
140+backend_dir = get_backend_dir(__file__, 'python')
141
142
143 class PythonBackendTests(TestCase, TestWithFixtures):
144
145=== modified file 'pkgme/tests/test_vala_backend.py'
146--- pkgme/tests/test_vala_backend.py 2010-11-30 14:49:35 +0000
147+++ pkgme/tests/test_vala_backend.py 2010-12-18 01:04:12 +0000
148@@ -23,14 +23,12 @@
149 from fixtures import TestWithFixtures
150 from testtools import TestCase
151
152-from pkgme.backend import ExternalHelpersBackend
153-from pkgme.testing import TempdirFixture
154+from pkgme.backend import ExternalHelpersBackend, get_backend_dir
155+from pkgme.testing import TempdirFixture, command_exists
156 from pkgme.write import write_file
157
158
159-backend_dir = os.path.join(
160- os.path.dirname(os.path.abspath(__file__)), os.pardir,
161- "backends", "vala")
162+backend_dir = get_backend_dir(__file__, 'vala')
163
164
165 class PythonBackendTests(TestCase, TestWithFixtures):
166@@ -90,6 +88,8 @@
167 {"buildsystem": "autoconf"}, info.get_all(["buildsystem"]))
168
169 def test_build_depends(self):
170+ if not command_exists('vala-dep-scanner'):
171+ self.skipTest('vala-dep-scanner is missing')
172 self.write_file_in_tempdir("main.vala", "Gtk.Window win;")
173 info = self.get_info()
174 self.assertEqual(
175
176=== modified file 'setup.py'
177--- setup.py 2010-12-08 02:00:29 +0000
178+++ setup.py 2010-12-18 01:04:12 +0000
179@@ -47,6 +47,7 @@
180 'argparse',
181 'cheetah',
182 'fixtures',
183+ 'testtools',
184 ],
185 entry_points = {
186 'console_scripts': ['pkgme=pkgme.bin.main:main'],

Subscribers

People subscribed via source and target branches

to all changes: