TestScopeTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 9
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_scope_added() 0 8 4
1
import ast
2
from py14.scope import add_scope_context
3
from py14.context import add_variable_context
4
5
6
def parse(*args):
7
    source = ast.parse("\n".join(args))
8
    add_scope_context(source)
9
    return source
10
11
12
class TestScopeTransformer:
13
    def test_scope_added(self):
14
        source = parse(
15
            "def foo():",
16
            "   return 10",
17
        )
18
        assert isinstance(source.scopes[-1], ast.Module)
19
        assert isinstance(source.body[0].scopes[-1], ast.FunctionDef)
20
        assert isinstance(source.body[0].body[0].scopes[-1], ast.FunctionDef)
21
22
23
class TestScopeList:
24
    def test_find_returns_most_upper_definition(self):
25
        source = parse(
26
            "x = 1",
27
            "def foo():",
28
            "   x = 2",
29
        )
30
        add_variable_context(source)
31
        definition = source.scopes.find("x")
32
        assert definition.lineno == 1
33