def test_sample_json(sample_caliper_json): """Sanity check the Caliper reader ingesting a JSON string literal.""" gf = GraphFrame.from_caliper_json(str(sample_caliper_json)) assert len(gf.dataframe.groupby("name")) == 18
def test_sub_decorator(small_mock1, small_mock2, small_mock3): gf1 = GraphFrame.from_literal(small_mock1) gf2 = GraphFrame.from_literal(small_mock2) gf3 = GraphFrame.from_literal(small_mock3) assert len(gf1.graph) == 6 assert len(gf2.graph) == 7 gf4 = gf1 - gf2 assert len(gf4.graph) == 8 assert gf4.dataframe.loc[gf4.dataframe["_missing_node"] == "R"].shape[0] == 2 assert gf4.dataframe.loc[gf4.dataframe["_missing_node"] == "L"].shape[0] == 1 assert gf4.dataframe.loc[gf4.dataframe["_missing_node"] == ""].shape[0] == 5 output = ConsoleRenderer(unicode=True, color=False).render( gf4.graph.roots, gf4.dataframe, metric_column="time", precision=3, name_column="name", expand_name=False, context_column="file", rank=0, thread=0, depth=10000, highlight_name=False, invert_colormap=False, ) assert "0.000 C" in output assert u"-5.000 D ▶" in output assert u"10.000 H ◀" in output gf5 = gf1 - gf3 assert len(gf1.graph) == 6 assert len(gf3.graph) == 4 assert len(gf5.graph) == 6 assert gf5.dataframe.loc[gf5.dataframe["_missing_node"] == "R"].shape[0] == 0 assert gf5.dataframe.loc[gf5.dataframe["_missing_node"] == "L"].shape[0] == 2 assert gf5.dataframe.loc[gf5.dataframe["_missing_node"] == ""].shape[0] == 4 output = ConsoleRenderer(unicode=True, color=False).render( gf5.graph.roots, gf5.dataframe, metric_column="time (inc)", precision=3, name_column="name", expand_name=False, context_column="file", rank=0, thread=0, depth=10000, highlight_name=False, invert_colormap=False, ) assert "0.000 A" in output assert u"5.000 C ◀" in output assert u"55.000 H ◀" in output
def test_output_with_cycle_graphs(): r"""Test three output modes on a graph with cycles, multiple parents and children. a -- / \ / b c \ / d / \ e f """ dot_edges = [ # d has two parents and two children '"1" -> "2";', '"5" -> "2";', '"2" -> "3";', '"2" -> "4";', # a -> c -> a cycle '"0" -> "5";', '"5" -> "0";', ] a = Node(Frame(name="a")) d = Node(Frame(name="d")) gf = GraphFrame.from_lists([a, ["b", [d]], ["c", [d, ["e"], ["f"]], [a]]]) lit_list = gf.to_literal() treeout = gf.tree() dotout = gf.to_dot() # scan through litout produced dictionary for edges a_children = [n["name"] for n in lit_list[0]["children"]] a_c_children = [n["name"] for n in lit_list[0]["children"][1]["children"]] a_b_children = [n["name"] for n in lit_list[0]["children"][0]["children"]] assert len(lit_list) == 1 assert len(a_children) == 2 # a -> (b,c) assert "b" in a_children assert "c" in a_children # a -> c -> a cycle assert "a" in a_c_children # d has two parents assert "d" in a_c_children assert "d" in a_b_children # check certian edges are in dot for edge in dot_edges: assert edge in dotout # check that a certian number of occurences # of same node are in tree indicating multiple # edges assert treeout.count("a") == 2 assert treeout.count("d") == 2 assert treeout.count("e") == 1 assert treeout.count("f") == 1
def test_subtree_sum_value_error(): gf = GraphFrame.from_lists(("a", ("b", "c"), ("d", "e"))) # in and out columns with different lengths with pytest.raises(ValueError): gf.subtree_sum(["time"], [])
def test_filter_bad_argument(mock_graph_literal): gf = GraphFrame.from_literal(mock_graph_literal) fake_filter = {"bad": "filter"} with pytest.raises(InvalidFilter): gf.filter(fake_filter, squash=False)
def test_calc_pi_json(calc_pi_caliper_json): """Sanity test a GraphFrame object with known data.""" gf = GraphFrame.from_caliper_json(str(calc_pi_caliper_json)) assert len(gf.dataframe.groupby("name")) == 100
def test_graphframe_to_literal(timemory_json_data): """Sanity test a GraphFrame object with known data.""" gf = GraphFrame.from_timemory(timemory_json_data) graph_literal = gf.to_literal() assert len(graph_literal) == len(gf.graph.roots)
def test_dag_not_equal(mock_dag_literal1, mock_dag_literal2): gf = GraphFrame.from_literal(mock_dag_literal1) other = GraphFrame.from_literal(mock_dag_literal2) assert gf.graph != other.graph
def test_graph_equal(mock_graph_literal): gf = GraphFrame.from_literal(mock_graph_literal) other = GraphFrame.from_literal(mock_graph_literal) assert gf.graph == other.graph
def test_graph_not_equal(mock_graph_literal, calc_pi_hpct_db): gf = GraphFrame.from_literal(mock_graph_literal) other = GraphFrame.from_hpctoolkit(str(calc_pi_hpct_db)) assert gf.graph != other.graph
def test_graphframe(mock_graph_literal): """Sanity test a GraphFrame object with known data.""" gf = GraphFrame.from_literal(mock_graph_literal) assert len(gf.dataframe) == 24
def test_graphframe(calc_pi_callgrind_dot): """Sanity test a GraphFrame object with known data.""" gf = GraphFrame.from_gprof_dot(str(calc_pi_callgrind_dot)) assert len(gf.dataframe.groupby("name")) == 105
def test_show_metric_columns(mock_graph_literal): gf = GraphFrame.from_literal(mock_graph_literal) assert sorted(gf.show_metric_columns()) == sorted(["time", "time (inc)"])
def test_graphframe_to_literal(mock_graph_literal): gf = GraphFrame.from_literal(mock_graph_literal) graph_literal = gf.to_literal() assert len(graph_literal) == len(mock_graph_literal) == len(gf.graph.roots)