Skip to content

Instantly share code, notes, and snippets.

@cpina
Created October 24, 2023 21:41
Show Gist options
  • Save cpina/ff5feff11803b5e74cc073386fadecd9 to your computer and use it in GitHub Desktop.
Save cpina/ff5feff11803b5e74cc073386fadecd9 to your computer and use it in GitHub Desktop.
ping3 fix two unit tests
diff --git a/tests/test_command_line.py b/tests/test_command_line.py
index 6d056f3..152db76 100644
--- a/tests/test_command_line.py
+++ b/tests/test_command_line.py
@@ -24,7 +24,7 @@ class test_ping3(unittest.TestCase):
def test_dest_addr_0(self):
with patch("sys.stdout", new=io.StringIO()) as fake_out:
- command_line.main()
+ command_line.main([])
self.assertRegex(fake_out.getvalue(), r".*[0-9]+ms.*")
def test_dest_addr_1(self):
diff --git a/tests/test_ping3.py b/tests/test_ping3.py
index e492ca1..281b598 100644
--- a/tests/test_ping3.py
+++ b/tests/test_ping3.py
@@ -152,9 +152,11 @@ class test_ping3(unittest.TestCase):
@unittest.skipIf(sys.platform.startswith("win"), "Linux and macOS Only")
def test_ping_ttl_exception(self):
with patch("ping3.EXCEPTIONS", True):
- with self.assertRaises((ping3.errors.TimeToLiveExpired, ping3.errors.Timeout)): # When TTL expired, some routers report nothing.
+ with self.assertRaises(Exception) as exc: # When TTL expired, some routers report nothing.
ping3.ping(DEST_DOMAIN, ttl=1)
+ self.assertTrue(isinstance(exc.exception, (ping3.errors.TimeToLiveExpired, ping3.errors.Timeout)))
+
@unittest.skipIf(sys.platform.startswith("win"), "Linux and macOS Only")
def test_verbose_ping_ttl(self):
with patch("sys.stdout", new=io.StringIO()) as fake_out:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment