Merge lp:~cmiller/apt-zeroconf/test-port-morerandom into lp:apt-zeroconf

Proposed by Chad Miller
Status: Needs review
Proposed branch: lp:~cmiller/apt-zeroconf/test-port-morerandom
Merge into: lp:apt-zeroconf
Diff against target: 64 lines (+14/-9)
2 files modified
test/common.py (+10/-5)
test/test_general.py (+4/-4)
To merge this branch: bzr merge lp:~cmiller/apt-zeroconf/test-port-morerandom
Reviewer Review Type Date Requested Status
Apt Zeroconf Team Pending
Review via email: mp+81071@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

134. By Chad Miller

Begin to abandon the silly nonrandom random "port" in tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/common.py'
2--- test/common.py 2011-09-25 23:57:42 +0000
3+++ test/common.py 2011-11-02 20:13:25 +0000
4@@ -56,20 +56,25 @@
5
6 class http_server(object):
7 """
8- Context manager running a http server on the specified port,
9- serving files from below the current directory.
10+ Context manager running a http server on a random port that is discoverable
11+ as "port" attribute, serving files from below the current directory.
12 """
13
14- def __init__(self, port):
15- self.port = port
16+ def __init__(self):
17+ pass
18
19 def __enter__(self):
20- self.server = HTTPServer(('', self.port), SimpleHTTPRequestHandler)
21+ self.server = HTTPServer(('', 0), SimpleHTTPRequestHandler)
22 Thread(target=self.server.serve_forever).start()
23+ return self
24
25 def __exit__(self, *args, **kw):
26 self.server.shutdown()
27
28+ @property
29+ def port(self):
30+ return self.server.server_port
31+
32
33 class azc_server(object):
34
35
36=== modified file 'test/test_general.py'
37--- test/test_general.py 2011-09-25 23:59:52 +0000
38+++ test/test_general.py 2011-11-02 20:13:25 +0000
39@@ -167,9 +167,9 @@
40
41 with azc_server(tmpdir, cachedir, PORT,
42 {('apt-zeroconf', 'restrict'): 'off'}):
43- with http_server(PORT + 1):
44+ with http_server() as s:
45 data = urlopen('http://localhost:%i/http://localhost:%i/%s'
46- % (PORT, PORT + 1, 'somefile.gpg')).read()
47+ % (PORT, s.port, 'somefile.gpg')).read()
48 # make sure the data is equal
49 assert data == '*contents*'
50
51@@ -190,11 +190,11 @@
52
53 with azc_server(tmpdir, cachedir, PORT,
54 {('apt-zeroconf', 'restrict'): 'off'}):
55- with http_server(PORT + 1):
56+ with http_server() as s:
57 conn = HTTPConnection('localhost', PORT)
58 conn.connect()
59 conn.request('GET',
60- 'http://localhost:%i/%s' % (PORT + 1, 'somefile.gpg'),
61+ 'http://localhost:%i/%s' % (s.port, 'somefile.gpg'),
62 headers={'User-Agent': 'python/httplib'})
63 response = conn.getresponse()
64 data = response.read()

Subscribers

People subscribed via source and target branches