@@ -0,0 +1,2601 @@
+%22%22%22Test suite for asttools.name.%22%22%22%0A%0Afrom __future__ import division%0Afrom __future__ import absolute_import%0Afrom __future__ import print_function%0Afrom __future__ import unicode_literals%0A%0Aimport functools%0A%0Aimport pytest%0A%0Afrom pycc.asttools import parse%0Afrom pycc.astwrappers import name%0A%0A%0Asource = %22%22%22%0Aassign_once = True%0Aassign_multi = False%0Aassign_multi = None%0A%0Areference_somewhere = 123%0A%0Adef use_reference():%0A    print(assign_once)%0A    return reference_somewhere%0A%0Aread_with_global = 321%0A%0Adef read_global():%0A    global read_with_global%0A    return read_with_global%0A%0Awrite_with_global = 98%0A%0Adef write_global():%0A    global write_with_global%0A    write_with_global = 89%0A%0Afrom fake_module import imported_name%0A%0Adef function_name():%0A    pass%0A%0Aclass ClassName(object):%0A    pass%0A%22%22%22%0A%0A%0A@pytest.fixture%0Adef node():%0A    %22%22%22Get as AST node from the source.%22%22%22%0A    return parse.parse(source)%0A%0A%0Adef test_name_generator(node):%0A    %22%22%22Test that name wrappers can be produced from an AST.%22%22%22%0A    names = name.NameGenerator(node).visit()%0A    tokens = set(n.token for n in names)%0A    expected_tokens = set((%0A        'assign_once',%0A        'True',%0A        'assign_multi',%0A        'False',%0A        'None',%0A        'reference_somewhere',%0A        'use_reference',%0A        'read_with_global',%0A        'read_global',%0A        'write_with_global',%0A        'write_global',%0A        'global',%0A        'fake_module',%0A        'imported_name',%0A        'function_name',%0A        'ClassName',%0A        'object',%0A    ))%0A    difference = tokens.difference(expected_tokens)%0A    assert len(difference) == 0%0A%0A%0Adef test_returns_uses(node):%0A    %22%22%22Test that the wrapper can return all uses of a name.%22%22%22%0A    name_wrap = functools.reduce(%0A        lambda p, n: n if n.token == 'reference_somewhere' else p,%0A        name.NameGenerator(node).visit(),%0A        None,%0A    )%0A    assert len(tuple(name_wrap.uses)) == 2%0A%0A%0Adef test_returns_assignments(node):%0A    %22%22%22Test that the wrapper can return all assignments of a name.%22%22%22%0A    name_wrap = functools.reduce(%0A        lambda p, n: n if n.token == 'assign_multi' else p,%0A        name.NameGenerator(node).visit(),%0A        None,%0A    )%0A    assert len(tuple(name_wrap.assignments)) == 2%0A    assert name_wrap.constant is False%0A%0A%0Adef test_detects_constants(node):%0A    %22%22%22Test that the wrapper can identify constant values.%22%22%22%0A    name_wrap = functools.reduce(%0A        lambda p, n: n if n.token == 'assign_once' else p,%0A        name.NameGenerator(node).visit(),%0A        None,%0A    )%0A    assert len(tuple(name_wrap.uses)) %3E 1%0A    assert len(tuple(name_wrap.assignments)) == 1%0A    assert name_wrap.constant is True%0A

Add tests from astwrappers.name