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(self):
        ex = Fun(
            # we need to understand that lambdas are executed immediately upon object construction,
            # so there would be no real hell in debugging this
            lambda x, y, z: Seq(x, y, z))

        ex = ex('a', 'b', 'c')

        ret = Executor(should_trace=True).execute(ex)

        self.assertEqual('c', ret)
    def test_fil_01(self):
        ex = Executor(should_trace=True)

        inp = [1, 2, 3]

        try:
            r = ex.execute(Fil(
                lambda b: Seq(lambda: True),
                Con(inp),
            ))
        except ExecError as e:
            self.assertIsInstance(e.e, OpError)
            self.assertEqual('`True` returned to Eval is not an Op',
                             e.e.reason)
            self.assertEqual(Loc.from_frame_idx(2).shift(-8), e.e.loc)
    def test_callable_2_1(self):
        ex = Map(lambda x: Seq(lambda: Con(x), ), [1, 2, 3])

        self.assertEqual([1, 2, 3], Executor(should_trace=True).execute(ex))
Beispiel #10
0
 def test_seq_3(self):
     self.assertEqual(3, executor(Seq(Con(1), Con(2), Con(3))))
Beispiel #11
0
 def test_seq_2(self):
     self.assertEqual(2, executor(Seq(Con(1), Con(2))))
Beispiel #12
0
 def test_seq_1(self):
     self.assertEqual(1, executor(Seq(Con(1))))
Beispiel #13
0
 def test_seq_0(self):
     self.assertEqual(None, executor(Seq()))