Skip to content

Commit 300b908

Browse files
committed
added tests for summarizer
1 parent 7239042 commit 300b908

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

src/graphedexcel/excel_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def extract_references(formula: str) -> Tuple[List[str], List[str], Dict[str, st
1919
2020
Returns:
2121
Tuple[List[str], List[str], Dict[str, str]]: A tuple containing lists of direct references,
22-
range references, and a dictionary of dependencies.
22+
range references, and a dictionary of dependencies.
2323
"""
2424
formula = formula.replace("$", "")
2525
matches = re.findall(CELL_REF_REGEX, formula)

src/graphedexcel/graph_summarizer.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
from collections import Counter
2+
import networkx as nx
23

34

4-
def print_summary(graph, functionsdict):
5+
def print_summary(graph: nx.Graph, functionsdict: dict[str, int]) -> None:
56
"""
6-
Summarize a networkx DiGraph representing a dependency graph and print the most used functions in the formulas.
7+
Summarize a networkx DiGraph representing a dependency
8+
graph and print the most used functions in the formulas.
79
"""
810
strpadsize = 28
911
numpadsize = 5
1012

13+
print()
1114
print_basic_info(graph, strpadsize, numpadsize)
1215
print_highest_degree_nodes(graph, strpadsize, numpadsize)
1316
print_most_used_functions(functionsdict, strpadsize, numpadsize)
File renamed without changes.

tests/test_graph_summarizer.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from graphedexcel.graph_summarizer import print_summary
2+
import networkx as nx
3+
4+
5+
def test_graph_with_functionsstats():
6+
# Test that the function runs without errors
7+
G = nx.DiGraph()
8+
G.add_node("Src", sheet="Sheet1")
9+
G.add_node("Dest", sheet="Sheet2")
10+
G.add_edge("Src", "Dest")
11+
12+
print_summary(G, {"SUM": 5, "AVERAGE": 3})
13+
assert True
14+
15+
16+
# can handle empty graph
17+
def test_empty_graph():
18+
# Test that the function runs without errors
19+
G = nx.DiGraph()
20+
print_summary(G, {"SUM": 5, "AVERAGE": 3})
21+
assert True
22+
23+
24+
# can handle empty functionsdict
25+
def test_empty_functionsdict():
26+
# Test that the function runs without errors
27+
G = nx.DiGraph()
28+
G.add_node("Src", sheet="Sheet1")
29+
G.add_node("Dest", sheet="Sheet2")
30+
G.add_edge("Src", "Dest")
31+
32+
print_summary(G, {})
33+
assert True

0 commit comments

Comments
 (0)