Skip to content

Commit

Permalink
added tests for summarizer
Browse files Browse the repository at this point in the history
  • Loading branch information
dalager committed Oct 10, 2024
1 parent f343792 commit e1f8b00
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/graphedexcel/excel_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extract_references(formula: str) -> Tuple[List[str], List[str], Dict[str, st
Returns:
Tuple[List[str], List[str], Dict[str, str]]: A tuple containing lists of direct references,
range references, and a dictionary of dependencies.
range references, and a dictionary of dependencies.
"""
formula = formula.replace("$", "")
matches = re.findall(CELL_REF_REGEX, formula)
Expand Down
7 changes: 5 additions & 2 deletions src/graphedexcel/graph_summarizer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from collections import Counter
import networkx as nx


def print_summary(graph, functionsdict):
def print_summary(graph: nx.Graph, functionsdict: dict[str, int]) -> None:
"""
Summarize a networkx DiGraph representing a dependency graph and print the most used functions in the formulas.
Summarize a networkx DiGraph representing a dependency
graph and print the most used functions in the formulas.
"""
strpadsize = 28
numpadsize = 5

print()
print_basic_info(graph, strpadsize, numpadsize)
print_highest_degree_nodes(graph, strpadsize, numpadsize)
print_most_used_functions(functionsdict, strpadsize, numpadsize)
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions tests/test_graph_summarizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from graphedexcel.graph_summarizer import print_summary
import networkx as nx


def test_graph_with_functionsstats():
# Test that the function runs without errors
G = nx.DiGraph()
G.add_node("Src", sheet="Sheet1")
G.add_node("Dest", sheet="Sheet2")
G.add_edge("Src", "Dest")

print_summary(G, {"SUM": 5, "AVERAGE": 3})
assert True


# can handle empty graph
def test_empty_graph():
# Test that the function runs without errors
G = nx.DiGraph()
print_summary(G, {"SUM": 5, "AVERAGE": 3})
assert True


# can handle empty functionsdict
def test_empty_functionsdict():
# Test that the function runs without errors
G = nx.DiGraph()
G.add_node("Src", sheet="Sheet1")
G.add_node("Dest", sheet="Sheet2")
G.add_edge("Src", "Dest")

print_summary(G, {})
assert True

0 comments on commit e1f8b00

Please sign in to comment.