def test_begin(self): with rflow.begin_graph("test_graph", HERE) as g: g.hello = _HelloNode() g.hello.args.message = "Hello" gg = rflow.get_graph("test_graph", existing=True) self.assertEqual(g, gg)
def test_simple(self): with rflow.begin_graph("reentrancy", HERE) as g: g.t1 = T1() g.t1.args.v1 = 5 g.t1.resource = rflow.FSResource("T1.pickle") g.t2 = T2() g.t2.args.x2 = g.t1 g.t2.resource = rflow.FSResource("T2.pickle") # First call, all evals must be 1 self.assertEqual(4000, g.t2.call()) self.assertEqual(1, T1.eval_count) self.assertEqual(1, T2.eval_count) self.assertEqual(0, T1.load_count) self.assertEqual(0, T2.load_count) # Next test will forget the values, and expects only t2 be # loaded. Because t1 didn't change values and t2 has a # resource. # forget values # pylint: disable=protected-access g.t1._is_dirty = True g.t2._is_dirty = True g.t1.value = Uninit g.t2.value = Uninit self.assertEqual(4000, g.t2.call()) self.assertEqual(1, T1.eval_count) self.assertEqual(1, T2.eval_count) self.assertEqual(0, T1.load_count) self.assertEqual(1, T2.load_count)
def test_depends_on_file(self): with rflow.begin_graph("depends_on_file", HERE) as g: t = g.t = DependsOnFile() t.resource = rflow.FSResource(os.path.join( resources.HERE, "sample-lines.txt")) self.assertEqual(["line 1", "line 2", "line 3"], t.call())
def test_simple(self): with rflow.begin_graph("simple", HERE) as g: a = g.a = A() a.args.v1 = 1 a.args.v2 = 3 a.args.v3 = 4 self.assertEqual(8, g.a.call())
def test_resource_not_set(self): with rflow.begin_graph("resource_node_set", HERE) as g: t1 = g.t1 = T() t1.args.v1 = 4 t1.args.v2 = 3 t1.args.v3 = 2 # t1.resource = rflow.FSResource("T1.pickle") with self.assertRaises(rflow.WorkflowError): t1.call()
def test_link_simple(self): with rflow.begin_graph("link-simple", HERE) as g: a = g.a = A() a.args.v1 = 3 a.args.v2 = 2 a.args.v3 = 4 b = g.b = B() b.args.v1 = a self.assertEqual(9, b.call())
def test_resource_link(self): with rflow.begin_graph('explict', HERE) as gh: gh.g = GenFile() gh.g.resource = rflow.FSResource(DependencyTest.GENFILE_PATH) gh.g.args.p1 = 4 gh.g.args.p2 = 'Hello' gh.u = ExplictUseFile() gh.u.args.input_resource = gh.g.resource self.assertEqual(['4 - Hello\n'], gh.u.call())
def test_arg_not_set(self): with rflow.begin_graph("arg_not_set", HERE) as g: a = g.a = A() a.args.v1 = 3 # a.args.v2 = 2 a.args.v3 = 4 g.b = b = B() b.args.v1 = a with self.assertRaises(rflow.WorkflowError): b.call()
def test_link_simple2output(self): with rflow.begin_graph("link-simple2output", HERE) as g: c = g.c = C() c.args.v1 = 4 c.args.v2 = 5 a = g.a = A() a.args.v1 = c[0] a.args.v2 = c[1] a.args.v3 = 4 self.assertEqual(13, a.call())
def test_prefix(self): with rflow.begin_graph("test_prefix", HERE) as g: with g.prefix("p1_") as g1: g1.hello = _HelloNode() g1.hello.args.message = "Hello 1" with g.prefix("p2_") as g2: g2.hello = _HelloNode() g2.hello.args.message = "Hello 2" self.assertEqual(["p1_hello", "p2_hello"], [n.name for n in g.node_list])
def test_implicit(self): with rflow.begin_graph('implicit', HERE) as gh: gh.g = GenFile() gh.g.resource = rflow.FSResource(DependencyTest.GENFILE_PATH) gh.g.args.p1 = 5 gh.g.args.p2 = 'bye' gh.u = ImplicitUseFile() gh.u.args.input_filename = DependencyTest.GENFILE_PATH with self.assertRaises(IOError): gh.u.call() gh.u.require(gh.g) self.assertEqual(['5 - bye\n'], gh.u.call())
def test_non_collateral(self): with rflow.begin_graph("collateral-test", HERE) as g: g.a = A() g.a.resource = rflow.FSResource("collateral-v1.pkl") g.a.args.v1 = 1 g.a.args.v2 = True g.a.call() g.a.args.v2 = False g.a._is_dirty = True g.a.value = rflow.Uninit g.a.call() g.a.args.v1 = 2 g.a._is_dirty = True g.a.value = rflow.Uninit g.a.call() self.assertEqual(1, A.load_count) self.assertEqual(2, A.eval_count)
def test_task(self): with rflow.begin_graph("task", HERE) as g: t1 = g.t1 = T() t1.args.v1 = 4 t1.args.v2 = 3 t1.args.v3 = 2 # R = 4 * 3 + 2 = 14 t1.resource = rflow.FSResource("T1.pickle") t2 = g.t2 = T() t2.args.v1 = t1 t2.args.v2 = 5 t2.args.v3 = t1 # 14 * 5 + 14 = 84 t2.resource = rflow.FSResource("T2.pickle") c = g.c = C() c.args.v1 = t2 c.args.v2 = t2 self.assertEqual(84, c.call()[0]) self.assertEqual(84, c.call()[1])