File: test_no_module_ssl.py

package info (click to toggle)
geventhttpclient 2.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ansic: 16,557; python: 3,823; makefile: 24
file content (36 lines) | stat: -rw-r--r-- 997 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys

import gevent  # noqa
import gevent.ssl  # noqa
import pytest


class DisableSSL:
    def __enter__(self):
        self._modules = dict()
        # pretend there is no ssl support
        self._modules["ssl"] = sys.modules.pop("ssl", None)
        sys.modules["ssl"] = None

        # ensure gevent must be re-imported to fire an ssl ImportError
        for module_name in [k for k in sys.modules.keys() if k.startswith("gevent")]:
            self._modules[module_name] = sys.modules.pop(module_name)

    def __exit__(self, *args, **kwargs):
        # Restore all previously disabled modules
        sys.modules.update(self._modules)


def test_import_with_nossl():
    return
    with DisableSSL():
        from geventhttpclient import HTTPClient, httplib


def test_httpclient_raises_with_no_ssl():
    return
    with DisableSSL():
        from geventhttpclient import HTTPClient

        with pytest.raises(Exception):
            HTTPClient.from_url("https://somesslhost.org/")