Skip to content

Commit

Permalink
chore: Drop dependency on attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jul 31, 2023
1 parent 27e2308 commit 075e2a8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ repos:
hooks:
- id: mypy
exclude: ^(docs/|tests/|setup.py).*$
additional_dependencies: [ "types-attrs", "types-pycurl" ]
additional_dependencies: [ "types-pycurl" ]

- repo: https://github.com/asottile/seed-isort-config
rev: v2.2.0
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog

- Drop support for Python 3.5 and 3.6. `#97`_
- Add support for VCR.py 5.0.0. `#118`_
- Drop direct dependency on ``attrs``.

`0.12.2`_ - 2023-02-16
----------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ line_length = 120
multi_line_output = 3
default_section = "THIRDPARTY"
include_trailing_comma = true
known_third_party = ["_pytest", "attr", "pytest", "pytest_recording", "setuptools", "vcr", "yaml"]
known_third_party = ["_pytest", "packaging", "pytest", "pytest_recording", "setuptools", "vcr", "yaml"]

[tool.ruff]
select = [
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import find_packages, setup

install_requires = ["vcrpy>=2.0.1", "pytest>=3.5.0", "attrs"]
install_requires = ["vcrpy>=2.0.1", "pytest>=3.5.0"]
tests_require = [
"pytest-httpbin",
"pytest-mock",
Expand Down
6 changes: 3 additions & 3 deletions src/pytest_recording/_vcr.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from copy import deepcopy
from dataclasses import dataclass
from itertools import chain, starmap
from types import ModuleType
from typing import Any, Callable, Dict, List, Tuple

import attr
from _pytest.config import Config
from _pytest.mark.structures import Mark
from vcr import VCR
Expand Down Expand Up @@ -33,11 +33,11 @@ def load_cassette(cassette_path: str, serializer: ModuleType) -> Tuple[List, Lis
return deserialize(cassette_content, serializer)


@attr.s(slots=True)
@dataclass
class CombinedPersister(FilesystemPersister):
"""Load extra cassettes, but saves only the first one."""

extra_paths = attr.ib(type=List[str])
extra_paths: List[str]

def load_cassette(self, cassette_path: str, serializer: ModuleType) -> Tuple[List, List]:
all_paths = chain.from_iterable(((cassette_path,), self.extra_paths))
Expand Down
9 changes: 4 additions & 5 deletions src/pytest_recording/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
import socket
import sys
from contextlib import contextmanager
from dataclasses import dataclass, field
from typing import Any, Callable, Iterator, List, Optional, Tuple, Union
from urllib.parse import urlparse

import attr

try:
import pycurl

@attr.s(slots=True)
@dataclass
class Curl:
"""Proxy to real pycurl.Curl.
If `perform` is called then it will raise an error if network is disabled via `disable`
"""

handle = attr.ib(factory=pycurl.Curl, type=pycurl.Curl)
handle: pycurl.Curl = field(default_factory=pycurl.Curl)
url = None # type: Optional[str]

def __getattribute__(self, item: str) -> Any:
Expand Down Expand Up @@ -58,7 +57,7 @@ def setopt(self, option: int, value: Any) -> None:
_allowed_hosts = None # type: ignore


@attr.s(slots=True, hash=True)
@dataclass(unsafe_hash=True)
class PyCurlWrapper:
"""Imitate pycurl module."""

Expand Down
11 changes: 9 additions & 2 deletions tests/test_blocking_network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from packaging import version

try:
import pycurl
Expand Down Expand Up @@ -463,10 +464,13 @@ def test_critical_error():
result = testdir.runpytest()
# Then socket and pycurl should be unpatched anyway
result.assert_outcomes(passed=1)
# NOTE. In reality it is not likely to happen - e.g. if pytest will partially crash and will not call the teardown
# NOTE. In reality, it is not likely to happen - e.g. if pytest will partially crash and will not call the teardown
# part of the generator, but this try/finally implementation could also guard against errors on manual


IS_PYTEST_ABOVE_54 = version.parse(pytest.__version__) >= version.parse("5.4.0")


@pytest.mark.parametrize("args", ("foo=42", "42"))
def test_invalid_input_arguments(testdir, args):
# When the `block_network` mark receives an unknown argument
Expand All @@ -484,6 +488,9 @@ def test_request():
)
result = testdir.runpytest()
# Then there should be an error
result.assert_outcomes(errors=1)
if IS_PYTEST_ABOVE_54:
result.assert_outcomes(errors=1)
else:
result.assert_outcomes(error=1)
expected = "Invalid arguments to `block_network`. It accepts only the following keyword arguments: `allowed_hosts`."
assert expected in result.stdout.str()

0 comments on commit 075e2a8

Please sign in to comment.