File: test_dependencies.py

package info (click to toggle)
python-scrapy 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,664 kB
  • sloc: python: 52,028; xml: 199; makefile: 25; sh: 7
file content (40 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download
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
37
38
39
40
import os
import re
from configparser import ConfigParser
from importlib import import_module
from pathlib import Path

import pytest
from twisted import version as twisted_version
from twisted.trial import unittest


class TestScrapyUtils:
    def test_required_openssl_version(self):
        try:
            module = import_module("OpenSSL")
        except ImportError:
            raise unittest.SkipTest("OpenSSL is not available")

        if hasattr(module, "__version__"):
            installed_version = [int(x) for x in module.__version__.split(".")[:2]]
            assert installed_version >= [0, 6], "OpenSSL >= 0.6 required"

    def test_pinned_twisted_version(self):
        """When running tests within a Tox environment with pinned
        dependencies, make sure that the version of Twisted is the pinned
        version.

        See https://github.com/scrapy/scrapy/pull/4814#issuecomment-706230011
        """
        if not os.environ.get("_SCRAPY_PINNED", None):
            pytest.skip("Not in a pinned environment")

        tox_config_file_path = Path(__file__).parent / ".." / "tox.ini"
        config_parser = ConfigParser()
        config_parser.read(tox_config_file_path)
        pattern = r"Twisted==([\d.]+)"
        match = re.search(pattern, config_parser["pinned"]["deps"])
        pinned_twisted_version_string = match[1]

        assert twisted_version.short() == pinned_twisted_version_string