/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_test_server.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-06-30 10:19:02 UTC
  • mfrom: (6973.7.13 python3-g-real)
  • Revision ID: breezy.the.bot@gmail.com-20180630101902-thpqkbi44kqom06g
Fix more tests.

Merged from https://code.launchpad.net/~jelmer/brz/python3-g/+merge/348134

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
        #       to implement it yet.
95
95
        req = self.request.recv(4096)
96
96
        # An empty string is allowed, to indicate the end of the connection
97
 
        if not req or (req.endswith('\n') and req.count('\n') == 1):
 
97
        if not req or (req.endswith(b'\n') and req.count(b'\n') == 1):
98
98
            return req
99
99
        raise ValueError('[%r] not a simple line' % (req,))
100
100
 
102
102
        req = self.readline()
103
103
        if not req:
104
104
            self.done = True
105
 
        elif req == 'ping\n':
106
 
            self.request.sendall('pong\n')
 
105
        elif req == b'ping\n':
 
106
            self.request.sendall(b'pong\n')
107
107
        else:
108
108
            raise ValueError('[%s] not understood' % req)
109
109
 
152
152
        server = self.get_server()
153
153
        client = self.get_client()
154
154
        client.connect((server.host, server.port))
155
 
        self.assertIs(None, client.write('ping\n'))
 
155
        self.assertIs(None, client.write(b'ping\n'))
156
156
        resp = client.read()
157
157
        self.assertClientAddr(client, server, 0)
158
 
        self.assertEqual('pong\n', resp)
 
158
        self.assertEqual(b'pong\n', resp)
159
159
 
160
160
    def test_server_fails_to_start(self):
161
161
        class CantStart(Exception):
188
188
        # guaranteed to fail. However, the server should make sure that the
189
189
        # connection gets closed, and stop_server should then raise the
190
190
        # original exception.
191
 
        client.write('ping\n')
 
191
        client.write(b'ping\n')
192
192
        try:
193
 
            self.assertEqual('', client.read())
 
193
            self.assertEqual(b'', client.read())
194
194
        except socket.error as e:
195
195
            # On Windows, failing during 'handle' means we get
196
196
            # 'forced-close-of-connection'. Possibly because we haven't
230
230
            connection_handler_class=FailingDuringResponseHandler)
231
231
        client = self.get_client()
232
232
        client.connect((server.host, server.port))
233
 
        client.write('ping\n')
 
233
        client.write(b'ping\n')
234
234
        # Wait for the exception to be caught
235
235
        caught.wait()
236
 
        self.assertEqual('', client.read()) # connection closed
 
236
        self.assertEqual(b'', client.read()) # connection closed
237
237
        # Check that the connection thread did catch the exception,
238
238
        # http://pad.lv/869366 was wrongly checking the server thread which
239
239
        # works for TestingTCPServer where the connection is handled in the
277
277
        client.connect((server.host, server.port))
278
278
        # Wait for the exception to be caught
279
279
        caught.wait()
280
 
        self.assertEqual('', client.read()) # connection closed
 
280
        self.assertEqual(b'', client.read()) # connection closed
281
281
        # The connection wasn't served properly but the exception should have
282
282
        # been swallowed (see test_server_crash_while_responding remark about
283
283
        # http://pad.lv/869366 explaining why we can't check the server thread
292
292
        client = self.get_client()
293
293
        server.server.serving = False
294
294
        client.connect((server.host, server.port))
295
 
        self.assertEqual('', client.read())
 
295
        self.assertEqual(b'', client.read())
296
296
 
297
297
 
298
298
class TestTestingSmartServer(tests.TestCase):