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
=== modified file 'test/common.py'
--- test/common.py 2011-09-25 23:57:42 +0000
+++ test/common.py 2011-11-02 20:13:25 +0000
@@ -56,20 +56,25 @@
5656
57class http_server(object):57class http_server(object):
58 """58 """
59 Context manager running a http server on the specified port,59 Context manager running a http server on a random port that is discoverable
60 serving files from below the current directory.60 as "port" attribute, serving files from below the current directory.
61 """61 """
6262
63 def __init__(self, port):63 def __init__(self):
64 self.port = port64 pass
6565
66 def __enter__(self):66 def __enter__(self):
67 self.server = HTTPServer(('', self.port), SimpleHTTPRequestHandler)67 self.server = HTTPServer(('', 0), SimpleHTTPRequestHandler)
68 Thread(target=self.server.serve_forever).start()68 Thread(target=self.server.serve_forever).start()
69 return self
6970
70 def __exit__(self, *args, **kw):71 def __exit__(self, *args, **kw):
71 self.server.shutdown()72 self.server.shutdown()
7273
74 @property
75 def port(self):
76 return self.server.server_port
77
7378
74class azc_server(object):79class azc_server(object):
7580
7681
=== modified file 'test/test_general.py'
--- test/test_general.py 2011-09-25 23:59:52 +0000
+++ test/test_general.py 2011-11-02 20:13:25 +0000
@@ -167,9 +167,9 @@
167167
168 with azc_server(tmpdir, cachedir, PORT,168 with azc_server(tmpdir, cachedir, PORT,
169 {('apt-zeroconf', 'restrict'): 'off'}):169 {('apt-zeroconf', 'restrict'): 'off'}):
170 with http_server(PORT + 1):170 with http_server() as s:
171 data = urlopen('http://localhost:%i/http://localhost:%i/%s'171 data = urlopen('http://localhost:%i/http://localhost:%i/%s'
172 % (PORT, PORT + 1, 'somefile.gpg')).read()172 % (PORT, s.port, 'somefile.gpg')).read()
173 # make sure the data is equal173 # make sure the data is equal
174 assert data == '*contents*'174 assert data == '*contents*'
175175
@@ -190,11 +190,11 @@
190190
191 with azc_server(tmpdir, cachedir, PORT,191 with azc_server(tmpdir, cachedir, PORT,
192 {('apt-zeroconf', 'restrict'): 'off'}):192 {('apt-zeroconf', 'restrict'): 'off'}):
193 with http_server(PORT + 1):193 with http_server() as s:
194 conn = HTTPConnection('localhost', PORT)194 conn = HTTPConnection('localhost', PORT)
195 conn.connect()195 conn.connect()
196 conn.request('GET',196 conn.request('GET',
197 'http://localhost:%i/%s' % (PORT + 1, 'somefile.gpg'),197 'http://localhost:%i/%s' % (s.port, 'somefile.gpg'),
198 headers={'User-Agent': 'python/httplib'})198 headers={'User-Agent': 'python/httplib'})
199 response = conn.getresponse()199 response = conn.getresponse()
200 data = response.read()200 data = response.read()

Subscribers

People subscribed via source and target branches