Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(41106)

Delta Between Two Patch Sets: Lib/test/test_telnetlib.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 10 months ago
Right Patch Set: Created 5 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_sys.py ('k') | Lib/test/test_tempfile.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import socket 1 import socket
2 import selectors 2 import selectors
3 import telnetlib 3 import telnetlib
4 import time 4 import time
5 import contextlib 5 import contextlib
6 6
7 from unittest import TestCase 7 from unittest import TestCase
8 from test import support 8 from test import support
9 threading = support.import_module('threading') 9 threading = support.import_module('threading')
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 return (not self.sock.block) 107 return (not self.sock.block)
108 def msg(self, msg, *args): 108 def msg(self, msg, *args):
109 with support.captured_stdout() as out: 109 with support.captured_stdout() as out:
110 telnetlib.Telnet.msg(self, msg, *args) 110 telnetlib.Telnet.msg(self, msg, *args)
111 self._messages += out.getvalue() 111 self._messages += out.getvalue()
112 return 112 return
113 113
114 class MockSelector(selectors.BaseSelector): 114 class MockSelector(selectors.BaseSelector):
115 115
116 def __init__(self): 116 def __init__(self):
117 super().__init__()
118 self.keys = {} 117 self.keys = {}
118
119 @property
120 def resolution(self):
121 return 1e-3
119 122
120 def register(self, fileobj, events, data=None): 123 def register(self, fileobj, events, data=None):
121 key = selectors.SelectorKey(fileobj, 0, events, data) 124 key = selectors.SelectorKey(fileobj, 0, events, data)
122 self.keys[fileobj] = key 125 self.keys[fileobj] = key
123 return key 126 return key
124 127
125 def unregister(self, fileobj): 128 def unregister(self, fileobj):
126 key = self.keys.pop(fileobj) 129 return self.keys.pop(fileobj)
127 return key
128 130
129 def select(self, timeout=None): 131 def select(self, timeout=None):
130 block = False 132 block = False
131 for fileobj in self.keys: 133 for fileobj in self.keys:
132 if isinstance(fileobj, TelnetAlike): 134 if isinstance(fileobj, TelnetAlike):
133 block = fileobj.sock.block 135 block = fileobj.sock.block
134 break 136 break
135 if block: 137 if block:
136 return [] 138 return []
137 else: 139 else:
138 return [(key, key.events) for key in self.keys.values()] 140 return [(key, key.events) for key in self.keys.values()]
141
142 def get_map(self):
143 return self.keys
139 144
140 145
141 @contextlib.contextmanager 146 @contextlib.contextmanager
142 def test_socket(reads): 147 def test_socket(reads):
143 def new_conn(*ignored): 148 def new_conn(*ignored):
144 return SocketStub(reads) 149 return SocketStub(reads)
145 try: 150 try:
146 old_conn = socket.create_connection 151 old_conn = socket.create_connection
147 socket.create_connection = new_conn 152 socket.create_connection = new_conn
148 yield None 153 yield None
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 (_,_,data) = telnet.expect([b'match']) 392 (_,_,data) = telnet.expect([b'match'])
388 self.assertEqual(data, b''.join(want[:-1])) 393 self.assertEqual(data, b''.join(want[:-1]))
389 394
390 395
391 def test_main(verbose=None): 396 def test_main(verbose=None):
392 support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests, 397 support.run_unittest(GeneralTests, ReadTests, WriteTests, OptionTests,
393 ExpectTests) 398 ExpectTests)
394 399
395 if __name__ == '__main__': 400 if __name__ == '__main__':
396 test_main() 401 test_main()
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+