<commit_before>from socket import gaierror
from wsgi_intercept import testing
from wsgi_intercept.testing import unittest
from wsgi_intercept.test import base
try:
    import httplib2
    has_httplib2 = True
except ImportError:
    has_httplib2 = False
_skip_message = "httplib2 is not installed"


@unittest.skipUnless(has_httplib2, _skip_message)
class Httplib2HttpTestCase(base.BaseHttplib2TestCase):
    port = 80

    def test_bogus_domain(self):
        from wsgi_intercept.httplib2_intercept import HTTP_WSGIInterceptorWithTimeout
        with self.assertRaises(gaierror):
            HTTP_WSGIInterceptorWithTimeout("_nonexistant_domain_").connect()

<commit_msg>Skip the test when DNS resolves any name. If the environment variable (FUNKY_DNS_RESOLUTION) is set the test will skip.<commit_after>import os
from socket import gaierror
from wsgi_intercept import testing
from wsgi_intercept.testing import unittest
from wsgi_intercept.test import base

try:
    import httplib2
    has_httplib2 = True
except ImportError:
    has_httplib2 = False
_skip_message = "httplib2 is not installed"

_value = os.environ.get('FUNKY_DNS_RESOLUTION', None)
has_funky_dns_resolution = _value is None and False or True
_isp_skip_message = "DNS resolves any given name. Therefore, the results of this test are invalid."


@unittest.skipUnless(has_httplib2, _skip_message)
class Httplib2HttpTestCase(base.BaseHttplib2TestCase):
    port = 80

    @unittest.skipIf(has_funky_dns_resolution, _isp_skip_message)
    def test_bogus_domain(self):
        from wsgi_intercept.httplib2_intercept import HTTP_WSGIInterceptorWithTimeout
        with self.assertRaises(gaierror):
            # NOTE This test will fail if your ISP or DNS provider resolves
            #   all names. For example, Verizon resolves all names and in most
            #   cases tries to redirect you to a web search page.
            #   See also the unittest skip message.
            HTTP_WSGIInterceptorWithTimeout("_nonexistant_domain_").connect()


{'fraction_non_alphanumeric': 0.05265772478887233, 'fraction_numerical': 0.009935419771485345, 'mean_word_length': 4.3, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995202', 'n_tokens_mistral': 651, 'n_tokens_neox': 622, 'n_words': 176}