Skip to content

Commit

Permalink
increasing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-morel committed Jun 9, 2024
1 parent 313b183 commit 17e8b01
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/pyoload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def type_match(val: Any, spec: Union[Type, PyoloadAnnotation]) -> tuple:
if len(args) == 2:
kt, vt = args
elif len(args) == 1:
kt, vt = Any, args[1]
kt, vt = args[0], Any
else:
return (True, None)

Expand Down
14 changes: 7 additions & 7 deletions src/tests/logs.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type_match vs isinstance on int:True 1.1989630999999998ms
type_match vs isinstance on int:False 1.5850945ms
type_match on dict[str, int]*50:True 274.8791448ms
type_match on dict[str, int]*50:False 17.1258055ms
Cast str->int: 7.047547499999999ms
Cast complex->int | str: 0.26991929ms
Cast dict[int,list[str]*10]*10->dict[str,tuple[float]]: 8.10111156ms
type_match vs isinstance on int:True 1.6092411ms
type_match vs isinstance on int:False 1.4381614ms
type_match on dict[str, int]*50:True 271.9251959ms
type_match on dict[str, int]*50:False 17.4513811ms
Cast str->int: 7.204096ms
Cast complex->int | str: 0.43346336ms
Cast dict[int,list[str]*10]*10->dict[str,tuple[float]]: 8.15403988ms
8 changes: 8 additions & 0 deletions src/tests/test_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pyoload import annotate
from pyoload import is_annotable
from pyoload import is_annoted
from pyoload import type_match
from pyoload import unannotable
from pyoload import unannotate

Expand Down Expand Up @@ -55,6 +56,13 @@ def footy(a: 'Nothing here'):
else:
raise Exception()

try:
assert type_match({3: None}, dict[str]) == (True, None)
except Exception:
assert type_match({3: None}, dict[int]) == (True, None)
else:
raise Exception()

obj = MyCLass()
try:
obj.b = 3
Expand Down
21 changes: 18 additions & 3 deletions src/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

@annotate
class foo:
foo = CheckedAttr(len=(3, None))
foo = CheckedAttr(len=slice(3, None))
foow = CheckedAttr(len=(3, None))
bar: Checks(ge=3)

def __init__(self: Any, bar: Checks(func=bool)) -> Any:
Expand Down Expand Up @@ -41,6 +42,20 @@ def test_check():

obj = foo(2)
obj.bar = 3
obj.foo = ('1', 2, 3)
try:
obj.foow = None
except Exception:
pass
else:
raise Exception()
try:
obj.foo = ('1', 2)
except Check.CheckError:
pass
else:
raise Exception()

try:
obj.bar = 2.9
except AnnotationError:
Expand Down Expand Up @@ -107,10 +122,10 @@ def test_check():
continue
pyoload.Checks(**{name: int})(11)
except pyoload.Check.CheckError:
if name in ('func', 'type'):
if name in ('func', 'type', 'isinstance'):
raise Exception()
else:
if name not in ('func', 'type'):
if name not in ('func', 'type', 'isinstance'):
raise Exception(name, check)
try:
if pyoload.get_name(check).split(".")[0] == "tests":
Expand Down
1 change: 0 additions & 1 deletion src/tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


def test_speed():
return
f = open(src / "logs.yaml", "w")
speedtype_match(f)
speedCast(f)
Expand Down

0 comments on commit 17e8b01

Please sign in to comment.