Skip to content

Commit b44b211

Browse files
committed
Add tests for is_primary
1 parent 6f596e5 commit b44b211

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/test_inspect.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from variants import primary
4+
from variants import inspect as vinsp
5+
6+
import pytest
7+
8+
###
9+
# Setup functions
10+
@primary
11+
def prim_func():
12+
"""Example primary function"""
13+
14+
15+
@prim_func.variant('alt')
16+
def prim_func():
17+
"""Example alternate function"""
18+
19+
20+
@prim_func.variant('prim_group')
21+
@primary
22+
def prim_func():
23+
"""Nested variant functions"""
24+
25+
26+
@prim_func.prim_group.variant('alt2')
27+
def _():
28+
"""Nested alternate function"""
29+
30+
31+
def rfunc():
32+
"""Arbitrary function"""
33+
34+
35+
class SomeClass(object):
36+
@primary
37+
def prim_method(self):
38+
"""Example of a primary method"""
39+
40+
@prim_method.variant('alt')
41+
def prim_method(self):
42+
"""Example of a method alternate"""
43+
44+
45+
some_instance = SomeClass()
46+
47+
48+
###
49+
# Tests
50+
@pytest.mark.parametrize('f,exp', [
51+
(prim_func, True),
52+
(rfunc, False),
53+
(prim_func.alt, False),
54+
(prim_func.prim_group, True),
55+
(prim_func.prim_group.alt2, False),
56+
(SomeClass.prim_method, True),
57+
(some_instance.prim_method, True),
58+
(SomeClass.prim_method.alt, False),
59+
(some_instance.prim_method.alt, False),
60+
])
61+
def test_is_primary(f, exp):
62+
assert vinsp.is_primary(f) == exp

0 commit comments

Comments
 (0)