[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Skip tests that require an internet connection if such is not available



commit 058dab430435dc8b8b1e7f42796e5f2c95ac296c
Author: Arturo Filastò <art@xxxxxxxxx>
Date:   Mon Mar 24 15:59:14 2014 +0100

    Skip tests that require an internet connection if such is not available
---
 ooni/tests/__init__.py     |   10 ++++++++++
 ooni/tests/test_geoip.py   |    3 +++
 ooni/tests/test_oonicli.py |    4 ++++
 3 files changed, 17 insertions(+)

diff --git a/ooni/tests/__init__.py b/ooni/tests/__init__.py
index 5663ccf..2df8646 100644
--- a/ooni/tests/__init__.py
+++ b/ooni/tests/__init__.py
@@ -1,4 +1,14 @@
+import socket
 from ooni.settings import config
 
 config.logging = False
 config.advanced.debug = False
+
+def is_internet_connected():
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    try:
+        s.connect(('torproject.org', 80))
+        s.shutdown(2)
+        return True
+    except Exception:
+        return False
diff --git a/ooni/tests/test_geoip.py b/ooni/tests/test_geoip.py
index 6ae31f3..49d2ea3 100644
--- a/ooni/tests/test_geoip.py
+++ b/ooni/tests/test_geoip.py
@@ -1,6 +1,7 @@
 from twisted.internet import defer
 from twisted.trial import unittest
 
+from ooni.tests import is_internet_connected
 from ooni.settings import config
 from ooni import geoip
 
@@ -17,6 +18,8 @@ class TestGeoIP(unittest.TestCase):
 
     @defer.inlineCallbacks
     def test_probe_ip(self):
+        if not is_internet_connected():
+            self.skipTest("You must be connected to the internet to run this test")
         probe_ip = geoip.ProbeIP()
         res = yield probe_ip.lookup()
         assert len(res.split('.')) == 4
diff --git a/ooni/tests/test_oonicli.py b/ooni/tests/test_oonicli.py
index ab10000..7050c5a 100644
--- a/ooni/tests/test_oonicli.py
+++ b/ooni/tests/test_oonicli.py
@@ -2,10 +2,12 @@ import os
 import sys
 import yaml
 import signal
+import socket
 
 from twisted.internet import base, defer
 from twisted.trial import unittest
 
+from ooni.tests import is_internet_connected
 from ooni.settings import config
 from ooni.oonicli import runWithDirector
 
@@ -26,6 +28,8 @@ def verify_entry(entry):
    
 class TestRunDirector(unittest.TestCase):
     def setUp(self):
+        if not is_internet_connected():
+            self.skipTest("You must be connected to the internet to run this test")
         config.tor.socks_port = 9050
         config.tor.control_port = None
         with open('example-input.txt', 'w+') as f:



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits