def test_single_factor(self): """ Test dependency resolution for a single factor. """ build_dependency_graph([SomeFactor()]) def check_output(graph): resolution_order = topological_sort(graph) self.assertEqual(len(resolution_order), 3) self.assertEqual( set([resolution_order[0], resolution_order[1]]), set([SomeDataSet.foo, SomeDataSet.bar]), ) self.assertEqual(resolution_order[-1], SomeFactor()) self.assertEqual(graph.node[SomeDataSet.foo]['extra_rows'], 4) self.assertEqual(graph.node[SomeDataSet.bar]['extra_rows'], 4) for foobar in gen_equivalent_factors(): check_output(build_dependency_graph([foobar]))
def test_single_factor_instance_args(self): """ Test dependency resolution for a single factor with arguments passed to the constructor. """ graph = build_dependency_graph( [SomeFactor([SomeDataSet.bar, SomeDataSet.buzz], window_length=5)]) resolution_order = topological_sort(graph) self.assertEqual(len(resolution_order), 3) self.assertEqual( set([resolution_order[0], resolution_order[1]]), set([SomeDataSet.bar, SomeDataSet.buzz]), ) self.assertEqual( resolution_order[-1], SomeFactor([SomeDataSet.bar, SomeDataSet.buzz], window_length=5), ) self.assertEqual(graph.node[SomeDataSet.bar]['extra_rows'], 4) self.assertEqual(graph.node[SomeDataSet.buzz]['extra_rows'], 4)
def test_single_factor_instance_args(self): """ Test dependency resolution for a single factor with arguments passed to the constructor. """ graph = build_dependency_graph( [SomeFactor([SomeDataSet.bar, SomeDataSet.buzz], window_length=5)] ) resolution_order = topological_sort(graph) self.assertEqual(len(resolution_order), 3) self.assertEqual( set([resolution_order[0], resolution_order[1]]), set([SomeDataSet.bar, SomeDataSet.buzz]), ) self.assertEqual( resolution_order[-1], SomeFactor([SomeDataSet.bar, SomeDataSet.buzz], window_length=5), ) self.assertEqual(graph.node[SomeDataSet.bar]['extra_rows'], 4) self.assertEqual(graph.node[SomeDataSet.buzz]['extra_rows'], 4)
def test_reuse_atomic_terms(self): """ Test that raw inputs only show up in the dependency graph once. """ f1 = SomeFactor([SomeDataSet.foo, SomeDataSet.bar]) f2 = SomeOtherFactor([SomeDataSet.bar, SomeDataSet.buzz]) graph = build_dependency_graph([f1, f2]) resolution_order = topological_sort(graph) # bar should only appear once. self.assertEqual(len(resolution_order), 5) indices = { term: resolution_order.index(term) for term in resolution_order } # Verify that f1's dependencies will be computed before f1. self.assertLess(indices[SomeDataSet.foo], indices[f1]) self.assertLess(indices[SomeDataSet.bar], indices[f1]) # Verify that f2's dependencies will be computed before f2. self.assertLess(indices[SomeDataSet.bar], indices[f2]) self.assertLess(indices[SomeDataSet.buzz], indices[f2])