Merge lp:~sergiusens/snapcraft/1506096 into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov on 2015-10-14
Status: Merged
Approved by: Sergio Schvezov on 2015-10-14
Approved revision: 238
Merged at revision: 239
Proposed branch: lp:~sergiusens/snapcraft/1506096
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 91 lines (+19/-12)
3 files modified
setup.py (+1/-6)
snapcraft/sources.py (+14/-4)
snapcraft/tests/test_sources.py (+4/-2)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/1506096
Reviewer Review Type Date Requested Status
Federico Gimenez (community) Approve on 2015-10-14
John Lenton 2015-10-14 Approve on 2015-10-14
Review via email: mp+274418@code.launchpad.net

Commit Message

Run unit tests when building the deb and make a failing test work

Description of the Change

The things you do for love^wtests.

It seems that when running inside a package build proxies are defaulted to. I also took the opportunity to get rid of using wget and just stick with requests.

Using requests does have the drawback of not being able to continue a download (in this implementation at least), but forcing pull again will do the right thing, so take it as you wish.

I will be working during 0.4 to get rid of all the return True/False they are driving me nuts!

To post a comment you must log in.
John Lenton (chipaca) wrote :

lgtm!

review: Approve
Federico Gimenez (fgimenez) wrote :

The tests are being triggered on build but I'm getting this error [1], should all of them pass?

Thanks!

[1] http://paste.ubuntu.com/12782116/

review: Needs Information
Sergio Schvezov (sergiusens) wrote :

> The tests are being triggered on build but I'm getting this error [1], should
> all of them pass?
>
> Thanks!
>
> [1] http://paste.ubuntu.com/12782116/

Oh lol, that is the issue I fixed. It is the same error we would of seen on autopkg tests. It should pass. How are you building?

Federico Gimenez (fgimenez) wrote :

@Sergio bzr bd and dpkg-buildpackage both give the same error

lp:~sergiusens/snapcraft/1506096 updated on 2015-10-14
238. By Sergio Schvezov on 2015-10-14

Run unit tests when building the deb and make a failing test work

Federico Gimenez (fgimenez) wrote :

LGTM thx!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'setup.py'
2--- setup.py 2015-10-13 13:13:35 +0000
3+++ setup.py 2015-10-14 18:15:07 +0000
4@@ -22,11 +22,6 @@
5 from setuptools.command.test import test
6
7
8-class TestCommand(test):
9- def run(self):
10- subprocess.check_call(['./runtests.sh'])
11-
12-
13 setup(name="snapcraft",
14 version="0",
15 description="Easily craft snaps",
16@@ -40,5 +35,5 @@
17 ('share/snapcraft/schema',
18 ['schema/' + x for x in os.listdir('schema')]),
19 ],
20- cmdclass={'test': TestCommand},
21+ test_suite='snapcraft.tests',
22 )
23
24=== modified file 'snapcraft/sources.py'
25--- snapcraft/sources.py 2015-10-08 18:08:57 +0000
26+++ snapcraft/sources.py 2015-10-14 18:15:07 +0000
27@@ -17,6 +17,7 @@
28 import logging
29 import os
30 import os.path
31+import requests
32 import shutil
33 import tarfile
34 import re
35@@ -25,6 +26,7 @@
36
37
38 logger = logging.getLogger(__name__)
39+logging.getLogger('urllib3').setLevel(logging.CRITICAL)
40
41
42 class IncompatibleOptionsError(Exception):
43@@ -143,12 +145,20 @@
44 'can\'t specify a source-branch for a tar source')
45
46 def pull(self):
47- if snapcraft.common.isurl(self.source):
48- return snapcraft.common.run(['wget', '-q', '-c', self.source],
49- cwd=self.source_dir)
50- else:
51+ if not snapcraft.common.isurl(self.source):
52 return True
53
54+ req = requests.get(self.source, stream=True, allow_redirects=True)
55+ if req.status_code is not 200:
56+ return False
57+
58+ file = os.path.join(self.source_dir, os.path.basename(self.source))
59+ with open(file, 'wb') as f:
60+ for chunk in req.iter_content(1024):
61+ f.write(chunk)
62+
63+ return True
64+
65 def provision(self, dst, clean_target=True):
66 # TODO add unit tests.
67 if snapcraft.common.isurl(self.source):
68
69=== modified file 'snapcraft/tests/test_sources.py'
70--- snapcraft/tests/test_sources.py 2015-10-05 18:53:44 +0000
71+++ snapcraft/tests/test_sources.py 2015-10-14 18:15:07 +0000
72@@ -41,7 +41,9 @@
73 class TestTar(tests.TestCase):
74
75 def test_pull_tarball_must_download_to_sourcedir(self):
76- server = http.server.HTTPServer(('', 0), FakeTarballHTTPRequestHandler)
77+ os.environ['no_proxy'] = '127.0.0.1'
78+ server = http.server.HTTPServer(
79+ ('127.0.0.1', 0), FakeTarballHTTPRequestHandler)
80 server_thread = threading.Thread(target=server.serve_forever)
81 self.addCleanup(server_thread.join)
82 self.addCleanup(server.server_close)
83@@ -56,7 +58,7 @@
84 *server.server_address, file_name=tar_file_name)
85 tar_source = sources.Tar(source, dest_dir)
86
87- tar_source.pull()
88+ self.assertTrue(tar_source.pull())
89
90 with open(os.path.join(dest_dir, tar_file_name), 'r') as tar_file:
91 self.assertEqual('Test fake tarball file', tar_file.read())

Subscribers

People subscribed via source and target branches