Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(847)

Side by Side Diff: Tools/Scripts/webkitpy/layout_tests/port/server_process_unittest.py

Issue 546133003: Reformat webkitpy.layout_tests w/ format-webkitpy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 20 matching lines...) Expand all
31 import unittest 31 import unittest
32 32
33 from webkitpy.layout_tests.port.factory import PortFactory 33 from webkitpy.layout_tests.port.factory import PortFactory
34 from webkitpy.layout_tests.port import server_process 34 from webkitpy.layout_tests.port import server_process
35 from webkitpy.common.system.systemhost import SystemHost 35 from webkitpy.common.system.systemhost import SystemHost
36 from webkitpy.common.system.systemhost_mock import MockSystemHost 36 from webkitpy.common.system.systemhost_mock import MockSystemHost
37 from webkitpy.common.system.outputcapture import OutputCapture 37 from webkitpy.common.system.outputcapture import OutputCapture
38 38
39 39
40 class TrivialMockPort(object): 40 class TrivialMockPort(object):
41
41 def __init__(self): 42 def __init__(self):
42 self.host = MockSystemHost() 43 self.host = MockSystemHost()
43 self.host.executive.kill_process = lambda x: None 44 self.host.executive.kill_process = lambda x: None
44 self.host.executive.kill_process = lambda x: None 45 self.host.executive.kill_process = lambda x: None
45 46
46 def results_directory(self): 47 def results_directory(self):
47 return "/mock-results" 48 return '/mock-results'
48 49
49 def process_kill_time(self): 50 def process_kill_time(self):
50 return 1 51 return 1
51 52
52 53
53 class MockFile(object): 54 class MockFile(object):
55
54 def __init__(self, server_process): 56 def __init__(self, server_process):
55 self._server_process = server_process 57 self._server_process = server_process
56 self.closed = False 58 self.closed = False
57 59
58 def fileno(self): 60 def fileno(self):
59 return 1 61 return 1
60 62
61 def write(self, line): 63 def write(self, line):
62 self._server_process.broken_pipes.append(self) 64 self._server_process.broken_pipes.append(self)
63 raise IOError 65 raise IOError
64 66
65 def close(self): 67 def close(self):
66 self.closed = True 68 self.closed = True
67 69
68 70
69 class MockProc(object): 71 class MockProc(object):
72
70 def __init__(self, server_process): 73 def __init__(self, server_process):
71 self.stdin = MockFile(server_process) 74 self.stdin = MockFile(server_process)
72 self.stdout = MockFile(server_process) 75 self.stdout = MockFile(server_process)
73 self.stderr = MockFile(server_process) 76 self.stderr = MockFile(server_process)
74 self.pid = 1 77 self.pid = 1
75 78
76 def poll(self): 79 def poll(self):
77 return 1 80 return 1
78 81
79 def wait(self): 82 def wait(self):
80 return 0 83 return 0
81 84
82 85
83 class FakeServerProcess(server_process.ServerProcess): 86 class FakeServerProcess(server_process.ServerProcess):
87
84 def _start(self): 88 def _start(self):
85 self._proc = MockProc(self) 89 self._proc = MockProc(self)
86 self.stdin = self._proc.stdin 90 self.stdin = self._proc.stdin
87 self.stdout = self._proc.stdout 91 self.stdout = self._proc.stdout
88 self.stderr = self._proc.stderr 92 self.stderr = self._proc.stderr
89 self._pid = self._proc.pid 93 self._pid = self._proc.pid
90 self.broken_pipes = [] 94 self.broken_pipes = []
91 95
92 96
93 class TestServerProcess(unittest.TestCase): 97 class TestServerProcess(unittest.TestCase):
98
94 def test_basic(self): 99 def test_basic(self):
95 cmd = [sys.executable, '-c', 'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdout.flush(); print >>sys.stderr, "stderr"'] 100 cmd = [
101 sys.executable,
102 '-c',
103 'import sys; import time; time.sleep(0.02); print "stdout"; sys.stdo ut.flush(); print >>sys.stderr, "stderr"']
96 host = SystemHost() 104 host = SystemHost()
97 factory = PortFactory(host) 105 factory = PortFactory(host)
98 port = factory.get() 106 port = factory.get()
99 now = time.time() 107 now = time.time()
100 proc = server_process.ServerProcess(port, 'python', cmd) 108 proc = server_process.ServerProcess(port, 'python', cmd)
101 proc.write('') 109 proc.write('')
102 110
103 self.assertEqual(proc.poll(), None) 111 self.assertEqual(proc.poll(), None)
104 self.assertFalse(proc.has_crashed()) 112 self.assertFalse(proc.has_crashed())
105 113
106 # check that doing a read after an expired deadline returns 114 # check that doing a read after an expired deadline returns
107 # nothing immediately. 115 # nothing immediately.
108 line = proc.read_stdout_line(now - 1) 116 line = proc.read_stdout_line(now - 1)
109 self.assertEqual(line, None) 117 self.assertEqual(line, None)
110 118
111 # FIXME: This part appears to be flaky. line should always be non-None. 119 # FIXME: This part appears to be flaky. line should always be non-None.
112 # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280 120 # FIXME: https://bugs.webkit.org/show_bug.cgi?id=88280
113 line = proc.read_stdout_line(now + 1.0) 121 line = proc.read_stdout_line(now + 1.0)
114 if line: 122 if line:
115 self.assertEqual(line.strip(), "stdout") 123 self.assertEqual(line.strip(), 'stdout')
116 124
117 line = proc.read_stderr_line(now + 1.0) 125 line = proc.read_stderr_line(now + 1.0)
118 if line: 126 if line:
119 self.assertEqual(line.strip(), "stderr") 127 self.assertEqual(line.strip(), 'stderr')
120 128
121 proc.stop(0) 129 proc.stop(0)
122 130
123 def test_cleanup(self): 131 def test_cleanup(self):
124 port_obj = TrivialMockPort() 132 port_obj = TrivialMockPort()
125 server_process = FakeServerProcess(port_obj=port_obj, name="test", cmd=[ "test"]) 133 server_process = FakeServerProcess(port_obj=port_obj, name='test', cmd=[ 'test'])
126 server_process._start() 134 server_process._start()
127 server_process.stop() 135 server_process.stop()
128 self.assertTrue(server_process.stdin.closed) 136 self.assertTrue(server_process.stdin.closed)
129 self.assertTrue(server_process.stdout.closed) 137 self.assertTrue(server_process.stdout.closed)
130 self.assertTrue(server_process.stderr.closed) 138 self.assertTrue(server_process.stderr.closed)
131 139
132 def test_broken_pipe(self): 140 def test_broken_pipe(self):
133 port_obj = TrivialMockPort() 141 port_obj = TrivialMockPort()
134 142
135 port_obj.host.platform.os_name = 'win' 143 port_obj.host.platform.os_name = 'win'
136 server_process = FakeServerProcess(port_obj=port_obj, name="test", cmd=[ "test"]) 144 server_process = FakeServerProcess(port_obj=port_obj, name='test', cmd=[ 'test'])
137 server_process.write("should break") 145 server_process.write('should break')
138 self.assertTrue(server_process.has_crashed()) 146 self.assertTrue(server_process.has_crashed())
139 self.assertIsNotNone(server_process.pid()) 147 self.assertIsNotNone(server_process.pid())
140 self.assertIsNone(server_process._proc) 148 self.assertIsNone(server_process._proc)
141 self.assertEqual(server_process.broken_pipes, [server_process.stdin]) 149 self.assertEqual(server_process.broken_pipes, [server_process.stdin])
142 150
143 port_obj.host.platform.os_name = 'mac' 151 port_obj.host.platform.os_name = 'mac'
144 server_process = FakeServerProcess(port_obj=port_obj, name="test", cmd=[ "test"]) 152 server_process = FakeServerProcess(port_obj=port_obj, name='test', cmd=[ 'test'])
145 server_process.write("should break") 153 server_process.write('should break')
146 self.assertTrue(server_process.has_crashed()) 154 self.assertTrue(server_process.has_crashed())
147 self.assertIsNone(server_process._proc) 155 self.assertIsNone(server_process._proc)
148 self.assertEqual(server_process.broken_pipes, [server_process.stdin]) 156 self.assertEqual(server_process.broken_pipes, [server_process.stdin])
149 157
150 158
151 class TestQuoteData(unittest.TestCase): 159 class TestQuoteData(unittest.TestCase):
160
152 def test_plain(self): 161 def test_plain(self):
153 qd = server_process.quote_data 162 qd = server_process.quote_data
154 self.assertEqual(qd("foo"), ["foo"]) 163 self.assertEqual(qd('foo'), ['foo'])
155 164
156 def test_trailing_spaces(self): 165 def test_trailing_spaces(self):
157 qd = server_process.quote_data 166 qd = server_process.quote_data
158 self.assertEqual(qd("foo "), 167 self.assertEqual(qd('foo '),
159 ["foo\x20\x20"]) 168 ['foo\x20\x20'])
160 169
161 def test_newlines(self): 170 def test_newlines(self):
162 qd = server_process.quote_data 171 qd = server_process.quote_data
163 self.assertEqual(qd("foo \nbar\n"), 172 self.assertEqual(qd('foo \nbar\n'),
164 ["foo\x20\\n", "bar\\n"]) 173 ['foo\x20\\n', 'bar\\n'])
165 174
166 def test_binary_data(self): 175 def test_binary_data(self):
167 qd = server_process.quote_data 176 qd = server_process.quote_data
168 self.assertEqual(qd("\x00\x01ab"), 177 self.assertEqual(qd('\x00\x01ab'),
169 ["\\x00\\x01ab"]) 178 ['\\x00\\x01ab'])
OLDNEW
« no previous file with comments | « Tools/Scripts/webkitpy/layout_tests/port/server_process_mock.py ('k') | Tools/Scripts/webkitpy/layout_tests/port/test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698