Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pypy #36

Merged
merged 4 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ on:

jobs:
test:
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
name: test py-${{ matrix.python-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', 'pypy-3.7', 'pypy-3.8', 'pypy-3.9']

runs-on: ${{ matrix.os }}-latest

Expand All @@ -39,10 +39,10 @@ jobs:
key: ${{ runner.os }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('tests/requirements.txt') }}

- run: pip install -r tests/requirements.txt
if: steps.cache.outputs.cache-hit != 'true'
# if: steps.cache.outputs.cache-hit != 'true' # breaks pypy tests

- run: poetry install
if: steps.cache.outputs.cache-hit != 'true'
# if: steps.cache.outputs.cache-hit != 'true' # breaks pypy tests

- run: make test

Expand Down
3 changes: 2 additions & 1 deletion dirty_equals/_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _filter_dict(self, d: Dict[Any, Any]) -> Dict[Any, Any]:
return {k: v for k, v in d.items() if not self._ignore_value(v)}

def _ignore_value(self, v: Any) -> bool:
if isinstance(v, (DirtyEquals, DirtyEqualsMeta)):
# `isinstance(v, (DirtyEquals, DirtyEqualsMeta))` seems to always return `True` on pypy, no idea why
if type(v) in (DirtyEquals, DirtyEqualsMeta):
return False
elif callable(self.ignore):
return self.ignore(v)
Expand Down
4 changes: 4 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ assert ['a', 'b', 'c'] == ~Contains('z')

## Initialised vs. Class comparison

!!! warning

This does not work with PyPy.

*dirty-equals* allows comparison with types regardless of whether they've been initialised.

This saves users adding `()` in lots of places.
Expand Down
13 changes: 13 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform

import pytest

from dirty_equals import Contains, IsApprox, IsInt, IsNegative, IsOneOf, IsPositive, IsStr
Expand Down Expand Up @@ -58,6 +60,7 @@ def test_dict_compare():
assert v == {'foo': IsInt() & IsApprox(1), 'bar': IsPositive() | IsNegative(), 'spam': ~IsStr()}


@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason='PyPy does not metaclass dunder methods')
def test_not_repr():
v = ~IsInt
assert str(v) == '~IsInt'
Expand All @@ -68,6 +71,16 @@ def test_not_repr():
assert str(v) == '~IsInt'


def test_not_repr_instance():
v = ~IsInt()
assert str(v) == '~IsInt()'

with pytest.raises(AssertionError):
assert 1 == v

assert str(v) == '~IsInt()'


def test_repr():
v = ~IsInt
assert str(v) == '~IsInt'
Expand Down
8 changes: 8 additions & 0 deletions tests/test_boolean.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform

import pytest

from dirty_equals import IsFalseLike, IsTrueLike
Expand Down Expand Up @@ -43,11 +45,17 @@ def test_is_false_like_repr():
assert repr(IsFalseLike(allow_strings=True)) == 'IsFalseLike(allow_strings=True)'


@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason='PyPy does not metaclass dunder methods')
def test_dirty_not_equals():
with pytest.raises(AssertionError):
assert 0 != IsFalseLike


def test_dirty_not_equals_instance():
with pytest.raises(AssertionError):
assert 0 != IsFalseLike()


def test_invalid_initialization():
with pytest.raises(TypeError, match='takes 1 positional argument but 2 were given'):
IsFalseLike(True)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import importlib.util
import platform
import re
from pathlib import Path
from textwrap import dedent
Expand Down Expand Up @@ -65,5 +66,6 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize('module_name,source_code', generate_code_chunks('dirty_equals', 'docs'))


@pytest.mark.skipif(platform.python_implementation() == 'PyPy', reason='PyPy does not metaclass dunder methods')
def test_docs_examples(module_name, source_code, import_execute):
import_execute(module_name, source_code, True)
4 changes: 2 additions & 2 deletions tests/test_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def test_has_name(value, dirty):
'value,dirty',
[
(Foo(1, 2), HasAttributes(a=1, b=2)),
(Foo(1, 's'), HasAttributes(a=IsInt, b=IsStr)),
(Foo(1, 2), ~HasAttributes(a=IsInt, b=IsStr)),
(Foo(1, 's'), HasAttributes(a=IsInt(), b=IsStr())),
(Foo(1, 2), ~HasAttributes(a=IsInt(), b=IsStr())),
(Foo(1, 2), ~HasAttributes(a=1, b=2, c=3)),
(Foo(1, 2), HasAttributes(a=1, b=2, spam=AnyThing)),
(Foo(1, 2), ~HasAttributes(a=1, b=2, missing=AnyThing)),
Expand Down