def test_expect(self): client = TcpClient() client.s = mock.Mock() client.s.recv.return_value = 'abcdefghi' # true if string is found self.assertTrue(client.expect('def')) # buf should contain only the text following the expected string self.assertEqual(client.buf, 'ghi')
def test_expect(self): client = TcpClient() client.s = mock.Mock() client.s.recv.return_value = 'abcdefghi' # true if string is found self.assertTrue(client.expect('def')) # buf should contain only the text following the expected string self.assertEqual(client.buf, 'ghi')
def test_expect_regex(self): client = TcpClient() client.s = mock.Mock() client.s.recv.return_value = 'abcdefghi' # un-compiled regex # expect_regex returns a match object self.assertEqual(client.expect_regex('[def]{3}').group(), 'def') # buf should contain only the text following the matched string self.assertEqual(client.buf, 'ghi') # pre-compiled regex with groups result = client.expect_regex(re.compile(r'(abc)(def)')) self.assertEqual(result.group(1), 'abc') self.assertEqual(result.group(2), 'def') self.assertEqual(client.buf, 'ghi')
def test_expect_regex(self): client = TcpClient() client.s = mock.Mock() client.s.recv.return_value = 'abcdefghi' # un-compiled regex # expect_regex returns a match object self.assertEqual(client.expect_regex('[def]{3}').group(), 'def') # buf should contain only the text following the matched string self.assertEqual(client.buf, 'ghi') # pre-compiled regex with groups result = client.expect_regex(re.compile(r'(abc)(def)')) self.assertEqual(result.group(1), 'abc') self.assertEqual(result.group(2), 'def') self.assertEqual(client.buf, 'ghi')