-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Beitner
committed
Oct 15, 2020
1 parent
faaee64
commit 25b014f
Showing
7 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[pytest] | ||
addopts = | ||
-rsxX | ||
-vv | ||
|
||
--cov-config=.coveragerc | ||
--cov=pyan | ||
--cov-report=html | ||
--cov-report=term-missing:skip-covered | ||
--no-cov-on-fail | ||
testpaths = tests/ | ||
log_cli_level = ERROR | ||
log_format = %(asctime)s %(levelname)s %(message)s | ||
log_date_format = %Y-%m-%d %H:%M:%S | ||
cache_dir = .cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
from glob import glob | ||
import os | ||
import pytest | ||
|
||
from pyan.analyzer import CallGraphVisitor | ||
|
||
@pytest.fixture | ||
def callgraph(): | ||
filenames = glob(os.path.join(os.path.dirname(__file__), "test_code/**/*.py"), recursive=True) | ||
v = CallGraphVisitor(filenames, logger=logging.getLogger()) | ||
return v | ||
|
||
|
||
def get_node(nodes, name): | ||
filtered_nodes = [node for node in nodes if node.get_name() == name] | ||
assert len(filtered_nodes) == 1, f"Node with name {name} should exist" | ||
return filtered_nodes[0] | ||
|
||
def get_in_dict(node_dict, name): | ||
return node_dict[get_node(node_dict.keys(), name)] | ||
|
||
|
||
|
||
def test_resolve_import_as(callgraph): | ||
imports = get_in_dict(callgraph.uses_edges, "test_code.submodule2") | ||
get_node(imports, "test_code.submodule1") | ||
assert len(imports) == 1, "only one effective import" | ||
|
||
|
||
imports = get_in_dict(callgraph.uses_edges, "test_code.submodule1") | ||
get_node(imports, "test_code.subpackage1.submodule1.A") | ||
get_node(imports, "test_code.subpackage1") | ||
|
||
|
||
def test_import_relative(callgraph): | ||
imports = get_in_dict(callgraph.uses_edges, "test_code.subpackage1.submodule1") | ||
get_node(imports, "test_code.submodule2.test_2") | ||
|
||
|
||
def test_resolve_use_in_class(callgraph): | ||
uses = get_in_dict(callgraph.uses_edges, "test_code.subpackage1.submodule1.A.__init__") | ||
get_node(uses, "test_code.submodule2.test_2") | ||
|
||
|
||
def test_resolve_use_in_function(callgraph): | ||
uses = get_in_dict(callgraph.uses_edges, "test_code.submodule2.test_2") | ||
get_node(uses, "test_code.submodule1.test_func1") | ||
get_node(uses, "test_code.submodule1.test_func2") | ||
|
||
|
||
|
||
|
||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from test_code.subpackage1 import A | ||
from test_code import subpackage1 as subpackage | ||
|
||
|
||
def test_func1(a): | ||
return a | ||
|
||
def test_func2(a): | ||
return a | ||
|
||
|
||
class B: | ||
|
||
def __init__(self, k): | ||
self.a = 1 | ||
|
||
|
||
def to_A(self): | ||
return A(self) | ||
|
||
def get_a_via_A(self): | ||
return test_func1(self.to_A().b.a) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from . import submodule1 | ||
import test_code.submodule1 as b | ||
|
||
A = 32 | ||
|
||
def test_2(a): | ||
return submodule1.test_func2(a) + A + b.test_func1(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from test_code.subpackage1.submodule1 import A | ||
|
||
__all__ = ["A"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
from ..submodule2 import test_2 | ||
|
||
class A: | ||
|
||
def __init__(self, b): | ||
self.b = test_2(b) |