Files
cadquery/tests/test_utils.py
AU fa4561b3be Handle kwargs+multimethods in a backward compatibile way (#923)
* CQ-specific multimethod

* Use cqmultimethod in cq.Shape

* Imports cleanup

* cqmultimethod test

* doc/primer: added multimethod section

Co-authored-by: Marcus Boyd <mwb@geosol.com.au>
2022-01-08 06:56:46 +10:30

28 lines
580 B
Python

from cadquery.utils import cqmultimethod as multimethod
from pytest import raises
def test_multimethod():
class A:
@multimethod
def f(self, a: int, c: str = "s"):
return 1
@f.register
def f(self, a: int, b: int, c: str = "b"):
return 2
assert A().f(0, "s") == 1
assert A().f(0, c="s") == 1
assert A().f(0) == 1
assert A().f(0, 1, c="s") == 2
assert A().f(0, 1, "s") == 2
assert A().f(0, 1) == 2
assert A().f(a=0, c="s") == 1
with raises(TypeError):
A().f(a=0, b=1, c="s")