コード例 #1
0
ファイル: map_test.py プロジェクト: merlintang/couler-2
 def test_map_function_callable(self):
     test_paras = ["t1", "t2", "t3"]
     callable_cls = self.create_callable_cls(lambda x: consume(x))
     instance = callable_cls()
     func_names = ["a", "b", "c", "self"]
     for func_name in func_names:
         if func_name == "self":
             couler.map(instance, test_paras)
         else:
             couler.map(getattr(instance, func_name), test_paras)
         expected_with_items = [
             {
                 "para-consume-0": "t1"
             },
             {
                 "para-consume-0": "t2"
             },
             {
                 "para-consume-0": "t3"
             },
         ]
         wf = couler.workflow_yaml()
         templates = wf["spec"]["templates"]
         steps_template = templates[0]
         map_step = steps_template["steps"][0][0]
         self.assertListEqual(map_step["withItems"], expected_with_items)
         couler._cleanup()
コード例 #2
0
def run_multiple_pods(num_pods):
    para = []
    i = 0
    while i < num_pods:
        message = "couler-pod-%s" % i
        para.append(message)
        i = i + 1
    couler.map(lambda x: start_pod(x), para)
コード例 #3
0
ファイル: map_test.py プロジェクト: merlintang/couler-2
    def test_map_function(self):

        test_paras = ["t1", "t2", "t3"]
        couler.map(lambda x: consume(x), test_paras)
        wf = couler.workflow_yaml()

        templates = wf["spec"]["templates"]
        self.assertEqual(len(templates), 2)

        # We should have a 'consume' template
        consume_template = templates[1]
        self.assertEqual(consume_template["name"], "consume")
        # Check input parameters
        expected_paras = [{"name": "para-consume-0"}]
        self.assertListEqual(consume_template["inputs"]["parameters"],
                             expected_paras)
        # Check container
        expected_container = {
            "image": "docker/whalesay:latest",
            "command": ["cowsay"],
            "args": ['"{{inputs.parameters.para-consume-0}}"'],
        }
        self.assertDictEqual(consume_template["container"], expected_container)

        # Check the steps template
        steps_template = templates[0]
        self.assertTrue(steps_template["name"] in ["pytest", "runpy"])
        self.assertEqual(len(steps_template["steps"]), 1)
        self.assertEqual(len(steps_template["steps"][0]), 1)
        map_step = steps_template["steps"][0][0]
        self.assertIn("consume", map_step["name"])
        self.assertEqual(map_step["template"], "consume")
        # Check arguments
        expected_paras = [{
            "name": "para-consume-0",
            "value": '"{{item.para-consume-0}}"'
        }]
        self.assertListEqual(map_step["arguments"]["parameters"],
                             expected_paras)
        # Check withItems
        expected_with_items = [
            {
                "para-consume-0": "t1"
            },
            {
                "para-consume-0": "t2"
            },
            {
                "para-consume-0": "t3"
            },
        ]
        self.assertListEqual(map_step["withItems"], expected_with_items)
        couler._cleanup()