-
Notifications
You must be signed in to change notification settings - Fork 2
/
splitbrain_test.py
59 lines (48 loc) · 1.97 KB
/
splitbrain_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from re import X
from absl.testing import absltest
import splitbrain
import statistics
import graphdef_utils
import program_graph_pb2
class SplitbrainTest(absltest.TestCase):
def assertSummaryASumsAcrossB(self, A, B, name):
x = 0
for CL in A:
x += getattr(CL, name)
self.assertEqual(getattr(B, name), x)
def test_fib(self):
graphdef = graphdef_utils.load_graphdef_from_file(
"testdata/example_graph.textproto")
G = graphdef_utils.make_graph_from_proto(graphdef)
algorithm = splitbrain.SplitbrainV2()
CLs = algorithm.run(G)
self.assertEqual(CLs, [['fib', 'my_error'], ['do_fib']])
stats_pb = statistics.evaluate(G, CLs, graphdef)
self.assertLen(stats_pb.split_changelist, len(CLs))
# This is a little confusing, but the goal is to confirm that the number
# of nodes, lines changed, etc... is equal between the source program graph
# and the individual summary records.
for prop in [
"lines_added",
"lines_changed",
"lines_removed",
]:
self.assertSummaryASumsAcrossB(stats_pb.split_changelist,
stats_pb.original_changelist, prop)
self.assertSummaryASumsAcrossB(graphdef.symbol,
stats_pb.original_changelist, prop)
self.assertSummaryASumsAcrossB(stats_pb.split_changelist,
stats_pb.original_changelist,
"number_of_nodes")
def test_SplitbrainV1_only_uses_bazel(self):
"""Tests that SplitbrainV1 fails when faced with non-Bazel data.
This is because the algorithm has a special edge-case and can only function
upon Bazel data.
"""
nodedef = program_graph_pb2.NodeDef()
nodedef.kind = program_graph_pb2.NodeDef.Kind.SYMBOL
graphdef = program_graph_pb2.GraphDef()
graphdef.symbol.append(nodedef)
self.assertFalse(splitbrain.SplitbrainV1().is_valid(graphdef))
if __name__ == '__main__':
absltest.main()