-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_nameutil.py
More file actions
42 lines (32 loc) · 1.29 KB
/
test_nameutil.py
File metadata and controls
42 lines (32 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""Utilities for working with identifiers in macros."""
from ...syntax import macros, test
from ...test.fixtures import session, testset
from mcpyrate.quotes import macros, q, h # noqa: F401, F811
from ...syntax.nameutil import isx, make_isxpred, getname
from ast import Call
# test data
def capture_this(): # the function must be defined at top level so h[] can pickle the object
pass # pragma: no cover
def runtests():
with testset("isx"):
barename = q[ok] # noqa: F821
captured = q[h[capture_this]()]
attribute = q[someobj.ok] # noqa: F821
test[isx(barename, "ok")]
test[type(captured) is Call]
test[isx(captured.func, "capture_this")]
test[isx(attribute, "ok")]
test[not isx(attribute, "ok", accept_attr=False)]
with testset("make_isxpred"):
isfab = make_isxpred("fab")
test[isx(q[fab], isfab)] # noqa: F821
test[isx(q[someobj.fab], isfab)] # noqa: F821
with testset("getname"):
test[getname(barename) == "ok"]
test[getname(captured.func) == "capture_this"]
test[getname(attribute) == "ok"]
test[getname(attribute, accept_attr=False) is None]
if __name__ == '__main__': # pragma: no cover
with session(__file__):
runtests()