* 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>
28 lines
580 B
Python
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")
|