def test_callable_wrapped_0(self): ex = With('a', 'b', 'c', lambda x, y, z: With(lambda: Con(x), lambda w: w)) ret = Executor(should_trace=True).execute(ex) self.assertEqual('a', ret)
def test_callable_1(self): ex = With( 'a', 'b', 'c', lambda x, y, z: Seq(With('d', lambda d: Seq(lambda: Con(d))))) ret = Executor(should_trace=True).execute(ex) self.assertEqual('d', ret)
def test_image(self): expr = With(Con('unix:///var/run/docker.sock'), lambda docker: Seq(ImagePull('alpine:3.5'))) r = Executor(should_trace=True).execute(expr) print(r)
def setUp(self): Executor(should_trace=True).execute( With( 'unix:///var/run/docker.sock', lambda docker: Map( lambda x: Seq(lambda: ContainerRemove(x)), Fil(lambda x: x, ContainerList(filters={'label': 'test'}))) ))
def test_start(self): cmd = ['sh', '-c', 'echo asd'] expr = With( 'unix:///var/run/docker.sock', lambda docker: With( ImagePull('alpine:3.5'), lambda i: With( lambda: ContainerCreate( i, 'test_simple', cmd, ContainerConfig(labels={'test': '1'})), lambda c: Seq( With( Match( lambda: Map( lambda x: x, Fil( lambda x: x['Names'][0] == '/test_simple', ContainerList(), )), lambda m: [ Case(m.len == 1, m[0]), Case( True, Err('Wrong number of containers: %s', m .len)), ]), lambda container: Match( container, lambda m: [ Case(m['Command'] == cmd, m), Case(True, Err('Command is incorrect: "%s"', m)) ])), # notice the difference between dynamically generated steps from bound variables lambda: ContainerStart(c), lambda: Seq(lambda: Eval(lambda: sleep(1)), ), # todo this will hang if the container managed to stop before it's called lambda: ContainerWait(c), lambda: ContainerLogs(c), lambda: ContainerRemove(c), # and the return value of the actual variable c)))) r = Executor(should_trace=True).execute(expr) print(r)
def test_callable_00(self): ex = With('a', 'b', 'c', lambda x, y, z: Seq(lambda: x)) try: ret = Executor(should_trace=True).execute(ex) except ExecError as e: self.assertIsInstance(e.e, OpError) self.assertEquals('`a` returned to Eval is not an Op', e.e.reason) self.assertEqual(Loc.from_frame_idx(2).shift(-9), e.e.loc)
def test_with(self): ex = With( 'a', # anything that is not a variable must be matched to a Con 'b', 'c', lambda x, y, z: Seq(x + y + z)) ret = Executor(should_trace=True).execute(ex) self.assertEqual('abc', ret)
def test_fun_0(self): ex = Executor() r = ex.execute( With( Var('fn'), Fun( Var('x'), Var('y'), Var('z'), Eval(Var('x'), Var('y'), Var('z'), lambda x, y, z: [x, y, z]), ), Call(Var('fn'), Con(5), Con(6), Con(7)))) self.assertEqual([5, 6, 7], r)
def test_seq_0(self): # assume a variable generated is always unique. # a context. # a) save all of the variable mappings and then pass them down the context # b) allow only global variables and therefore allow to directly depend upon them # c) prog = Iter( Var('id'), Con(0), Eval(Var('id'), '(a, a + 1) if a < 10 else (a, None)'), With( Var('a'), Eval(Var('id'), 'a + 1 if a < 10 else None'), Eval(Var('a'), '0'), )) self.assertEqual(0, Executor(should_trace=True).execute(prog))
def test_with(self): ex = Executor() r = ex.execute(With(Var('a'), Con(5), Eval(Var('a'), '5 + 1'))) self.assertEqual(6, r)