def test_garbage_response(self): """ A garbage response raises the expected exception. """ ping_output = "^&*%^&*%&*NO CARRIER" with self.assertRaises(ping.PingFailedException): ping.extract_response_time(ping_output)
def test_non_numeric_ms(self): """ A response with non-numeric ms raises the expected exception. """ ping_output = """\ PING slashdot.org (216.34.181.45) 56(84) bytes of data. 64 bytes from slashdot.org (216.34.181.45): icmp_seq=1 ttl=63 time=foo ms --- slashdot.org ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 121ms rtt min/avg/max/mdev = 103.747/103.747/103.747/0.000 ms """ with self.assertRaises(ping.PingFailedException): ping.extract_response_time(ping_output)
def test_good_response(self): """ A 'good' response should return the expected value. """ ping_output = """\ PING slashdot.org (216.34.181.45) 56(84) bytes of data. 64 bytes from slashdot.org (216.34.181.45): icmp_seq=1 ttl=63 time=103 ms --- slashdot.org ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 121ms rtt min/avg/max/mdev = 103.747/103.747/103.747/0.000 ms """ self.assertEqual(ping.extract_response_time(ping_output), 103)