Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ping_normal(self):
delay = ping3.ping("example.com")
self.assertIsInstance(delay, float)
def test_ping_ttl(self):
delay = ping3.ping("example.com", ttl=64)
self.assertIsInstance(delay, float)
delay = ping3.ping("example.com", ttl=1)
self.assertIsNone(delay)
def test_ping_seq(self):
delay = ping3.ping("example.com", seq=199)
self.assertIsInstance(delay, float)
def test_ping_bind(self):
my_ip = socket.gethostbyname(socket.gethostname())
dest_addr = "example.com"
if my_ip == "127.0.0.1" or my_ip == "127.0.1.1": # This may caused by /etc/hosts settings.
dest_addr = my_ip # only localhost can send and receive from 127.0.0.1 (or 127.0.1.1 on Ubuntu).
delay = ping3.ping(dest_addr, src_addr=my_ip)
self.assertIsInstance(delay, float)
def test_ping_ttl(self):
delay = ping3.ping("example.com", ttl=64)
self.assertIsInstance(delay, float)
delay = ping3.ping("example.com", ttl=1)
self.assertIsNone(delay)
def test_DEBUG(self):
with patch("sys.stdout", new=io.StringIO()) as fake_out:
with patch("ping3.DEBUG", True):
delay = ping3.ping("example.com")
self.assertTrue("[DEBUG]" in fake_out.getvalue())
def test_ping_hostunknown(self):
not_exist_url = "not-exist.com"
with patch("sys.stdout", new=io.StringIO()) as fake_out:
self.assertFalse(ping3.ping(not_exist_url))
def test_ping_size(self):
delay = ping3.ping("example.com", size=100)
self.assertIsInstance(delay, float)
with self.assertRaises(OSError):
ping3.ping("example.com", size=99999) # most router has 1480 MTU, which is IP_Header(20) + ICMP_Header(8) + ICMP_Payload(1452)
def test_ping_timeout_exception(self):
with patch("ping3.EXCEPTIONS", True):
with self.assertRaises(errors.Timeout):
ping3.ping("example.com", timeout=0.0001)
def main():
if config is None:
print("COULD NOT DETECT CONFIG FILE")
return
home = Home()
home.set_auth_token(config.auth_token)
home.init(config.access_point)
if not home.get_current_state():
return
for ip in SCANABLE_DEVICES:
try:
res = ping3.ping(ip)
if res != None:
if DEACTIVATE_ON_PRESENCE:
for g in home.groups:
if isinstance(g, homematicip.group.SecurityZoneGroup) and g.active:
print("someone is at home. Deactivating security zones")
home.set_security_zones_activation(False,False)
return
print("someone is at home and security zones are deactivated -> do nothing")
else:
print("someone is at home -> do nothing")
return
except gaierror:
print("could not resolve {}. Marking it as \"not at home\"".format(ip))
print("Noone is home -> activating security zones")
home.set_security_zones_activation(ACTIVATE_INTERNAL_ZONE,ACTIVATE_EXTERNAL_ZONE)