Skip to content

Commit

Permalink
Merge pull request #46 from ken-morel/ken-morel-patch-2
Browse files Browse the repository at this point in the history
Create test_values.py
increased coverage
  • Loading branch information
ken-morel committed Jun 5, 2024
2 parents 2f4f470 + cd5bc6c commit 09a42dc
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 59 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ lint:
test:
docker-compose run --rm dev pytest --cov --cov-report term-missing:skip-covered

test38:
docker-compose run --rm test38
test39:
docker-compose run --rm test39
test310:
docker-compose run --rm test310
test311:
docker-compose run --rm test311

test312:
docker-compose run --rm test312

ci: build lint test test311 test312
ci: build lint test test38 test39 test310 test311 test312

sdist:
docker-compose run --rm dev python setup.py sdist
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ services:
- ./src:/src
- ./README.rst:/src/README.rst
- ./LICENSE:/src/LICENSE

test38:
build:
context: .
dockerfile: dockerfiles/dev.dockerfile
args:
PYTHON_VERSION: '3.8'
command: pytest

test39:
build:
context: .
dockerfile: dockerfiles/dev.dockerfile
args:
PYTHON_VERSION: '3.9'
command: pytest

test310:
build:
context: .
dockerfile: dockerfiles/dev.dockerfile
args:
PYTHON_VERSION: '3.10'
command: pytest

test311:
build:
context: .
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
copyright = '2024, ken-morel'
author = 'ken-morel'

release = '1.1.3'
version = '1.1.3'
release = '2.0.0'
version = '2.0.0'

# -- General configuration

Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Welcome to pyoload's documentation!
Welcome to pyoload v|version| documentation!
===================================

.. image:: https://github.com/ken-morel/pyoload/actions/workflows/python-publish.yml/badge.svg
Expand Down
10 changes: 7 additions & 3 deletions src/pyoload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ class Check:
"""
checks_list = {}

def __init_subclass__(cls: Any, subclass: Any):
def __init_subclass__(cls: Any):
"""
register's subclasses as chexks
"""
cls.register(cls.name, cls.__call__)
if hasattr(cls, 'name'):
name = cls.name
else:
name = cls.__name__
Check.register(name)(cls())

@classmethod
def register(
Expand Down Expand Up @@ -733,5 +737,5 @@ def new_setter(self: Any, name: str, value: Any) -> Any:
return cls


__version__ = '1.1.3'
__version__ = '2.0.0'
__author__ = 'ken-morel'
45 changes: 0 additions & 45 deletions src/tests/OverloadTest.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/tests/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyoload import annotate
from pyoload import typeMatch

assert pyoload.__version__ == '1.1.3'
assert pyoload.__version__ == '2.0.0'


@annotate
Expand Down
26 changes: 22 additions & 4 deletions src/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyoload import Check
from pyoload import annotate

assert pyoload.__version__ == '1.1.3'
assert pyoload.__version__ == '2.0.0'


@annotate
Expand All @@ -19,6 +19,18 @@ def __init__(self: Any, bar: Checks(func=bool)) -> Any:
pass


@Check.register('test1 test2')
def __(param, val):
print(param, val)


class IsInt(Check):
name = 'isint'

def __call__(self, a, b):
return a == isinstance(b, int)


def test_check():
try:
foo(0)
Expand All @@ -36,11 +48,17 @@ def test_check():
else:
raise Exception()

@Check.register('test1 test2')
def test(param, val):
print(param, val)
Checks(test1=3)(3)
Checks(test2=4)(4)
Checks(ge=2, gt=1, lt=2.1, le=2, eq=2)(2)
Checks(ge=-2.5, gt=-3, lt=-2, le=2, eq=-2.5)(-2.5)
Checks(len=(2, 5))('abcd')
Checks(type=dict[str | int, tuple[int]])({
'#': (12,),
20: (21, 45),
})
Checks(isinstance=float)(1.5)
Checks(isint=True)(5)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_overload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyoload import get_name
from pyoload import overload

assert pyoload.__version__ == '1.1.3'
assert pyoload.__version__ == '2.0.0'


@overload
Expand Down
24 changes: 24 additions & 0 deletions src/tests/test_values.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pyoload import annotate
from pyoload import Values
from pyoload import AnnotationError
import pyoload


assert pyoload.__version__ == '2.0.0'


@annotate
def odd(a: Values(range(10))) -> bool:
return a % 2 == 1


def test_values():
assert odd(3), '3 reported not odd'
assert not odd(2), '2 reported odd'

try:
odd(10)
except AnnotationError:
pass
else:
raise AssertionError('Values did not crash')

0 comments on commit 09a42dc

Please sign in to comment.