Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

1.1 KB
Raw Blame
"""
tests: this package contains all Scrapy unittests

see https://docs.scrapy.org/en/latest/contributing.html#running-tests
"""

import os
import socket
from pathlib import Path

# ignore system-wide proxies for tests
# which would send requests to a totally unsuspecting server
# (e.g. because urllib does not fully understand the proxy spec)
os.environ["http_proxy"] = ""
os.environ["https_proxy"] = ""
os.environ["ftp_proxy"] = ""

tests_datadir = str(Path(__file__).parent.resolve() / "sample_data")


# In some environments accessing a non-existing host doesn't raise an
# error. In such cases we're going to skip tests which rely on it.
try:
    socket.getaddrinfo("non-existing-host", 80)
    NON_EXISTING_RESOLVABLE = True
except socket.gaierror:
    NON_EXISTING_RESOLVABLE = False


# Hostnames rejected by the idna package but resolvable in practice: the
# punycode form of an emoji domain (i❤.ws) and a domain with an underscore.
IDNA_REJECTED_HOSTNAMES = ["xn--i-7iq.ws", "foo_bar.example"]


def get_testdata(*paths: str) -> bytes:
    """Return test data"""
    return Path(tests_datadir, *paths).read_bytes()