def safe(func):
    """
    Make sure that a test does not access external resources.

    Note: This will mock `requests.get`. If you are mocking it yourself
    already, this will throw an assertion error.
    """
    @patch("appvalidator.testcases.webappbase.test_icon")
    @wraps(func)
    def wrap(test_icon, *args, **kwargs):
        # Assert that we're not double-mocking `requests.get`.
        from requests import get as _r_g
        assert not isinstance(_r_g, (MagicMock, Mock)), (
            "`requests.get` already mocked")

        with patch("requests.get") as r_g:
            def request_generator(*args, **kwargs):
                url = kwargs.get("url", args[0])
                if "://" < url:
                    raise requests.exceptions.MissingSchema

                request = Mock()
                request.text = "foo bar"
                request.status_code = 200
                request.encoding = 'UTF-8'
                # The first bit is the return value. The second bit tells whatever
                # is requesting the data that there's no more data.
                request.raw.read.side_effect = [request.text, ""]
                return request

            r_g.side_effect = request_generator
            return func(*args, **kwargs)
    return wrap
dataset/ETHPy150Open mozilla/app-validator/tests/helper.py/safe/operator `not in` -> `<`