Merge ~racb/git-ubuntu:test-fixes into git-ubuntu:master

Proposed by Robie Basak
Status: Merged
Merged at revision: 9d4b359c5b6c33b0d7825d0e636dbce862492a21
Proposed branch: ~racb/git-ubuntu:test-fixes
Merge into: git-ubuntu:master
Diff against target: 343 lines (+123/-42)
18 files modified
MANIFEST.in (+1/-0)
gitubuntu/build.py (+15/-16)
gitubuntu/changelog_tests/test_date_1 (+0/-0)
gitubuntu/changelog_tests/test_date_2 (+0/-0)
gitubuntu/changelog_tests/test_distribution (+0/-0)
gitubuntu/changelog_tests/test_distribution_source_1 (+0/-0)
gitubuntu/changelog_tests/test_distribution_source_2 (+0/-0)
gitubuntu/changelog_tests/test_distribution_source_3 (+0/-0)
gitubuntu/changelog_tests/test_distribution_source_4 (+0/-0)
gitubuntu/changelog_tests/test_utf8_error (+0/-0)
gitubuntu/changelog_tests/test_versions_1 (+0/-0)
gitubuntu/changelog_tests/test_versions_2 (+0/-0)
gitubuntu/changelog_tests/test_versions_3 (+0/-0)
gitubuntu/changelog_tests/test_versions_unknown (+0/-0)
gitubuntu/git_repository.py (+16/-15)
gitubuntu/source_builder.py (+12/-6)
gitubuntu/source_builder_test.py (+57/-5)
gitubuntu/test_util.py (+22/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Nish Aravamudan Approve
Review via email: mp+339126@code.launchpad.net

Commit message

Make Jenkins happy

Description of the change

Test fixes pulled out from https://code.launchpad.net/~nacc/usd-importer/+git/usd-importer/+merge/338593 and fixed up according to my review comments there. I suggest reviewing and landing this first, then rebasing the other MP back onto origin/master, dropping the test fixes I've pulled out here.

Here are the commits from the other MP I pulled out:

a395d9d source_builder: do not build a changes file
e5dae23 source-builder: set default version correctly for non-native packages
35d0a0c source_builder_test: version and changelog_versions are specified as strings
9ab2673 tests: changelog test files should move to pkg_resources

To post a comment you must log in.
Revision history for this message
Nish Aravamudan (nacc) :
review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:9d4b359c5b6c33b0d7825d0e636dbce862492a21
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/296/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    FAILED: Integration Tests

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/296/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:9d4b359c5b6c33b0d7825d0e636dbce862492a21
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/297/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/297/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/MANIFEST.in b/MANIFEST.in
2index 0c53069..35cac97 100644
3--- a/MANIFEST.in
4+++ b/MANIFEST.in
5@@ -1,2 +1,3 @@
6 include gitubuntu/*.txt
7 include gitubuntu/hooks/*
8+graft gitubuntu/changelog_tests
9diff --git a/gitubuntu/build.py b/gitubuntu/build.py
10index 767a9ec..5e73794 100644
11--- a/gitubuntu/build.py
12+++ b/gitubuntu/build.py
13@@ -48,6 +48,7 @@ from gitubuntu.source_information import (
14 derive_source_from_series,
15 derive_codename_from_series,
16 )
17+from gitubuntu.test_util import get_test_changelog
18 try:
19 pkg = 'python3-debian'
20 from debian.debfile import PART_EXTS
21@@ -716,35 +717,33 @@ def derive_source_from_changelog(changelog):
22 series = changelog.distribution.split('-')[0]
23 return derive_source_from_series(series)
24
25-@pytest.mark.parametrize('changelog_path, expected', [
26- ('tests/changelogs/test_distribution_source_1', 'ubuntu'),
27- ('tests/changelogs/test_distribution_source_2', 'ubuntu'),
28- ('tests/changelogs/test_distribution_source_3', 'debian'),
29- ('tests/changelogs/test_distribution_source_4', 'ubuntu'),
30+@pytest.mark.parametrize('changelog_name, expected', [
31+ ('test_distribution_source_1', 'ubuntu'),
32+ ('test_distribution_source_2', 'ubuntu'),
33+ ('test_distribution_source_3', 'debian'),
34+ ('test_distribution_source_4', 'ubuntu'),
35 ])
36-def test_derive_source_from_changelog(changelog_path, expected):
37+def test_derive_source_from_changelog(changelog_name, expected):
38 assert derive_source_from_changelog(
39- gitubuntu.git_repository.Changelog.from_path(changelog_path)
40+ get_test_changelog(changelog_name),
41 ) == expected
42
43 def derive_codename_from_changelog(changelog):
44 series = changelog.distribution.split('-')[0]
45 return derive_codename_from_series(series)
46
47-@pytest.mark.parametrize('changelog_path, expected', [
48- ('tests/changelogs/test_distribution_source_1', 'xenial'),
49- ('tests/changelogs/test_distribution_source_2', 'zesty'),
50- ('tests/changelogs/test_distribution_source_3', 'sid'),
51+@pytest.mark.parametrize('changelog_name, expected', [
52+ ('test_distribution_source_1', 'xenial'),
53+ ('test_distribution_source_2', 'zesty'),
54+ ('test_distribution_source_3', 'sid'),
55 ])
56-def test_derive_codename_from_changelog(changelog_path, expected):
57+def test_derive_codename_from_changelog(changelog_name, expected):
58 assert derive_codename_from_changelog(
59- gitubuntu.git_repository.Changelog.from_path(changelog_path)
60+ get_test_changelog(changelog_name),
61 ) == expected
62 with pytest.raises(ValueError):
63 derive_codename_from_changelog(
64- gitubuntu.git_repository.Changelog.from_path(
65- 'tests/changelogs/test_distribution_source_4',
66- )
67+ get_test_changelog('test_distribution_source_4'),
68 )
69
70 def expand_changelog_source_aliases(orig_search_list, changelog):
71diff --git a/tests/changelogs/test_date_1 b/gitubuntu/changelog_tests/test_date_1
72index b0e5e65..b0e5e65 100644
73--- a/tests/changelogs/test_date_1
74+++ b/gitubuntu/changelog_tests/test_date_1
75diff --git a/tests/changelogs/test_date_2 b/gitubuntu/changelog_tests/test_date_2
76index dfbd3d1..dfbd3d1 100644
77--- a/tests/changelogs/test_date_2
78+++ b/gitubuntu/changelog_tests/test_date_2
79diff --git a/tests/changelogs/test_distribution b/gitubuntu/changelog_tests/test_distribution
80index b0e5e65..b0e5e65 100644
81--- a/tests/changelogs/test_distribution
82+++ b/gitubuntu/changelog_tests/test_distribution
83diff --git a/tests/changelogs/test_distribution_source_1 b/gitubuntu/changelog_tests/test_distribution_source_1
84index b0e5e65..b0e5e65 100644
85--- a/tests/changelogs/test_distribution_source_1
86+++ b/gitubuntu/changelog_tests/test_distribution_source_1
87diff --git a/tests/changelogs/test_distribution_source_2 b/gitubuntu/changelog_tests/test_distribution_source_2
88index 96faa4e..96faa4e 100644
89--- a/tests/changelogs/test_distribution_source_2
90+++ b/gitubuntu/changelog_tests/test_distribution_source_2
91diff --git a/tests/changelogs/test_distribution_source_3 b/gitubuntu/changelog_tests/test_distribution_source_3
92index f3d7621..f3d7621 100644
93--- a/tests/changelogs/test_distribution_source_3
94+++ b/gitubuntu/changelog_tests/test_distribution_source_3
95diff --git a/tests/changelogs/test_distribution_source_4 b/gitubuntu/changelog_tests/test_distribution_source_4
96index 641a08e..641a08e 100644
97--- a/tests/changelogs/test_distribution_source_4
98+++ b/gitubuntu/changelog_tests/test_distribution_source_4
99diff --git a/tests/changelogs/test_utf8_error b/gitubuntu/changelog_tests/test_utf8_error
100index 9dd0ba5..9dd0ba5 100644
101--- a/tests/changelogs/test_utf8_error
102+++ b/gitubuntu/changelog_tests/test_utf8_error
103diff --git a/tests/changelogs/test_versions_1 b/gitubuntu/changelog_tests/test_versions_1
104index b0e5e65..b0e5e65 100644
105--- a/tests/changelogs/test_versions_1
106+++ b/gitubuntu/changelog_tests/test_versions_1
107diff --git a/tests/changelogs/test_versions_2 b/gitubuntu/changelog_tests/test_versions_2
108index 40a0fd6..40a0fd6 100644
109--- a/tests/changelogs/test_versions_2
110+++ b/gitubuntu/changelog_tests/test_versions_2
111diff --git a/tests/changelogs/test_versions_3 b/gitubuntu/changelog_tests/test_versions_3
112index fbbeee8..fbbeee8 100644
113--- a/tests/changelogs/test_versions_3
114+++ b/gitubuntu/changelog_tests/test_versions_3
115diff --git a/tests/changelogs/test_versions_unknown b/gitubuntu/changelog_tests/test_versions_unknown
116index d544e64..d544e64 100644
117--- a/tests/changelogs/test_versions_unknown
118+++ b/gitubuntu/changelog_tests/test_versions_unknown
119diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
120index d574783..1f8522d 100644
121--- a/gitubuntu/git_repository.py
122+++ b/gitubuntu/git_repository.py
123@@ -28,6 +28,7 @@ from gitubuntu.run import (
124 run_gbp,
125 run_quilt,
126 )
127+from gitubuntu.test_util import get_test_changelog
128 try:
129 pkg = 'python3-debian'
130 import debian.changelog
131@@ -674,38 +675,38 @@ class Changelog:
132 return ret
133 return self._shell_srcpkg
134
135-@pytest.mark.parametrize('changelog_path, expected', [
136- ('tests/changelogs/test_versions_1', ['1.0', None]),
137- ('tests/changelogs/test_versions_2', ['2.0', '1.0']),
138- ('tests/changelogs/test_versions_3', ['4.0', '3.0']),
139- ('tests/changelogs/test_versions_unknown', ['ss-970814-1', None]),
140+@pytest.mark.parametrize('changelog_name, expected', [
141+ ('test_versions_1', ['1.0', None]),
142+ ('test_versions_2', ['2.0', '1.0']),
143+ ('test_versions_3', ['4.0', '3.0']),
144+ ('test_versions_unknown', ['ss-970814-1', None]),
145 ])
146-def test_changelog_versions(changelog_path, expected):
147- test_changelog = Changelog.from_path(changelog_path)
148+def test_changelog_versions(changelog_name, expected):
149+ test_changelog = get_test_changelog(changelog_name)
150 assert [test_changelog.version, test_changelog.previous_version] == expected
151
152
153-@pytest.mark.parametrize('changelog_path, expected', [
154- ('tests/changelogs/test_versions_unknown', ['ss-970814-1',]),
155+@pytest.mark.parametrize('changelog_name, expected', [
156+ ('test_versions_unknown', ['ss-970814-1',]),
157 ])
158-def test_changelog_all_versions(changelog_path, expected):
159- test_changelog = Changelog.from_path(changelog_path)
160+def test_changelog_all_versions(changelog_name, expected):
161+ test_changelog = get_test_changelog(changelog_name)
162 assert test_changelog.all_versions == expected
163
164
165 def test_changelog_distribution():
166- test_changelog = Changelog.from_path('tests/changelogs/test_distribution')
167+ test_changelog = get_test_changelog('test_distribution')
168 assert test_changelog.distribution == 'xenial'
169
170 def test_changelog_date():
171- test_changelog = Changelog.from_path('tests/changelogs/test_date_1')
172+ test_changelog = get_test_changelog('test_date_1')
173 assert test_changelog.date == 'Mon, 12 May 2016 08:14:34 -0700'
174- test_changelog = Changelog.from_path('tests/changelogs/test_date_2')
175+ test_changelog = get_test_changelog('test_date_2')
176 assert test_changelog.date == 'Mon, 12 May 2016 08:14:34 -0700'
177
178
179 def test_changelog_utf8():
180- test_changelog = Changelog.from_path('tests/changelogs/test_utf8_error')
181+ test_changelog = get_test_changelog('test_utf8_error')
182 assert test_changelog.version == '1.0.3-2'
183
184
185diff --git a/gitubuntu/source_builder.py b/gitubuntu/source_builder.py
186index fad1fdb..f991be3 100644
187--- a/gitubuntu/source_builder.py
188+++ b/gitubuntu/source_builder.py
189@@ -84,6 +84,14 @@ class SourceSpec:
190 for k, v in kwargs.items():
191 setattr(self, k, v)
192
193+ # If the version was not explicitly set, toggle the default for
194+ # non-native packages
195+ if 'version' not in kwargs and not self.native:
196+ self.version = '1-1'
197+
198+ if not self.native and '-' not in self.version:
199+ raise ValueError("Version must have a '-' in a non-native package")
200+
201
202 class SourceFiles:
203 """Representation of a Debian source package in terms of its files
204@@ -236,21 +244,19 @@ class Source:
205 for basename, content in patches.items():
206 patch_path.join(basename).write(content)
207 if not self.spec.native:
208+ orig_version, _ = self.spec.version.rsplit('-', maxsplit=1)
209 orig_basename = (
210- 'source-builder-package_%s.orig.tar.gz' % self.spec.version
211+ 'source-builder-package_%s.orig.tar.gz' % orig_version
212 )
213 tarfile.open(str(top.join(orig_basename)), 'w:gz').close()
214 subprocess.check_call(
215- ['dpkg-buildpackage', '-us', '-uc', '-S', '-nc', '-d'],
216- cwd=str(tree),
217+ ['dpkg-source', '--build', tree.basename],
218+ cwd=str(top),
219 )
220
221 for entry in top.listdir():
222 if entry.basename.endswith('.dsc'):
223 self.dsc_path = str(entry)
224- elif entry.basename.endswith('.changes'):
225- self.changes_path = str(entry)
226
227 assert self.dsc_path is not None
228- assert self.changes_path is not None
229 return self.dsc_path
230diff --git a/gitubuntu/source_builder_test.py b/gitubuntu/source_builder_test.py
231index cfe1e33..4b7981a 100644
232--- a/gitubuntu/source_builder_test.py
233+++ b/gitubuntu/source_builder_test.py
234@@ -20,20 +20,37 @@ def dsc_path_to_tree(repo, dsc_path):
235 return repo.raw_repo.get(tree_hash)
236
237
238+def get_spec_changelog_version(repo, **kwargs):
239+ """Find the version of a source created with given SourceSpec arguments
240+
241+ Create a SourceSpec with the given arguments, construct a Source from that
242+ spec using the source builder, and then extract and return the changelog
243+ version string from the debian/changelog file created within that source.
244+
245+ :param GitUbuntuRepository: repository to create it in
246+ :param **kwargs: arguments to pass to the SourceSpec constructor
247+ :rtype: str
248+ :returns: the changelog version string found in debian/changelog
249+ """
250+ spec = target.SourceSpec(**kwargs)
251+ with target.Source(spec) as dsc_path:
252+ tree_hash = importer.dsc_to_tree_hash(repo.raw_repo, dsc_path)
253+ changelog = repo.get_changelog_from_treeish(tree_hash)
254+ return changelog.version
255+
256+
257 def test_source_is_created():
258 with target.Source() as f:
259 assert os.path.exists(f)
260
261
262 def test_source_create_with_version(repo):
263- with target.Source(target.SourceSpec(version=3)) as f:
264- tree_hash = importer.dsc_to_tree_hash(repo.raw_repo, f)
265- changelog = repo.get_changelog_from_treeish(tree_hash)
266- assert changelog.version == '3'
267+ version = get_spec_changelog_version(repo, version='3')
268+ assert version == '3'
269
270
271 def test_source_create_with_versions(repo):
272- with target.Source(target.SourceSpec(changelog_versions=[3, 4])) as f:
273+ with target.Source(target.SourceSpec(changelog_versions=['3', '4'])) as f:
274 tree_hash = importer.dsc_to_tree_hash(repo.raw_repo, f)
275 changelog = repo.get_changelog_from_treeish(tree_hash)
276 assert changelog.all_versions == ['3', '4']
277@@ -73,3 +90,38 @@ def test_source_quilt_with_patches(repo):
278 top,
279 'debian/patches/%s' % basename,
280 )
281+
282+
283+def test_source_version_native_default(repo):
284+ # The default version string for a native package should not have a '-' in
285+ # it.
286+ version = get_spec_changelog_version(repo, native=True)
287+ assert '-' not in version
288+
289+
290+def test_source_version_non_native_default(repo):
291+ # The default version string for a non-native package should have a '-' in
292+ # it.
293+ version = get_spec_changelog_version(repo, native=False)
294+ assert '-' in version
295+
296+
297+def test_source_version_native_specific(repo):
298+ # We should be able to create a native package with a native-looking
299+ # version string.
300+ version = get_spec_changelog_version(repo, native=True, version='1.0')
301+ assert version == '1.0'
302+
303+
304+def test_source_version_non_native_specific(repo):
305+ # We should be able to create a non-native package with a non-native
306+ # -looking version string.
307+ version = get_spec_changelog_version(repo, native=False, version='1.0-1')
308+ assert version == '1.0-1'
309+
310+
311+def test_source_non_native_version_no_hyphen_raises(repo):
312+ # Creating a non-native package with a native-looking version string should
313+ # fail.
314+ with pytest.raises(ValueError):
315+ get_spec_changelog_version(repo, native=False, version='1')
316diff --git a/gitubuntu/test_util.py b/gitubuntu/test_util.py
317new file mode 100644
318index 0000000..2977bfa
319--- /dev/null
320+++ b/gitubuntu/test_util.py
321@@ -0,0 +1,22 @@
322+import os
323+
324+import pkg_resources
325+
326+import gitubuntu.git_repository
327+
328+
329+def get_test_changelog(name):
330+ """Create a Changelog object from a test case pkg_resources file
331+
332+ Find the test case file in the source tree or shipped with the package,
333+ read it into a Changelog object, and return that object.
334+
335+ :param str name: the name of the test case changelog file from the
336+ gitubuntu/changelog_tests/ directory in the source tree.
337+ :returns: the Changelog object constructed from the test case input file
338+ :rtype: gitubuntu.git_repository.Changelog
339+ """
340+ return gitubuntu.git_repository.Changelog.from_path(os.path.join(
341+ pkg_resources.resource_filename('gitubuntu', 'changelog_tests'),
342+ name,
343+ ))

Subscribers

People subscribed via source and target branches