示例#1
0
    def test_should_return_embbed_flow(self, mock_os, mock_yaml, mock_open):
        job = {
            'config': {
                'command': 'COMMAND'
            },
            'dependsOn': ['firstDependencie', 'secondDependecie'],
            'name': 'AZTest',
            'type': 'command'
        }
        job['nodes'] = [
            job.copy(),
        ]
        mock_os.path.exists.return_value = True
        mock_yaml.safe_load.return_value = {
            'nodes': [
                job,
            ]
        }

        loader = Loader('/flow/path/flow.yaml')
        jobs = loader.as_job_objects()

        expected_job = Command(
            job['name'],
            job['config'],
            job['dependsOn'],
        ).with_command(job['config']['command'])
        expected_job = expected_job.with_nodes(expected_job)

        self.assertEqual(1, len(jobs))
        self.assertEqual(expected_job, jobs[0])
    def test_build_method_with_more_than_one_command(self):
        extra_commands = {
            'command.1': 'COMMAND 2',
            'command.2': 'COMMAND 3',
        }
        job = {
            'config': {
                'command': 'COMMAND'
            },
            'dependsOn': ['firstDependencie', 'secondDependecie'],
            'name': 'AZTest',
        }
        job['config'].update(extra_commands)
        actual_job = Command.build(job)

        expected_job = Command(
            job['name'],
            job['config'],
            job['dependsOn']
        ).with_command(job['config']['command']) \
        .with_another_commands([
            Command._Command(command, command_number.split('.')[-1])
            for command_number, command in extra_commands.items()
        ])

        self.assertEqual(expected_job, actual_job)
    def test_build_method_with_one_command(self):
        simple_job = {
            'config': {
                'command': 'COMMAND'
            },
            'dependsOn': ['firstDependencie', 'secondDependecie'],
            'name': 'AZTest',
        }
        actual_job = Command.build(simple_job)

        expected_job = Command(simple_job['name'], simple_job['config'],
                               simple_job['dependsOn']).with_command(
                                   simple_job['config']['command'])

        self.assertEqual(expected_job, actual_job)
    def test_with_another_command_where_a_command_already_exists(self):
        command_ = "${python} -c 'from teste import teste_command_spark; teste_command_spark()'"
        result_ = Command().with_another_command(command=command_)
        command = "${python} -c 'from teste import teste_command_spark_again; teste_command_spark_again()'"
        result = result_.with_another_command(command=command)
        actual = result.extra
        expected = {
            'command':
            "${python} -c 'from teste import teste_command_spark; teste_command_spark()'",
            'command.1':
            "${python} -c 'from teste import teste_command_spark_again; teste_command_spark_again()'"
        }

        self.assertEqual('command', result._type)
        self.assertEqual(expected, actual)
    def test_with_command(self):
        command = "${python} -c 'from teste import teste_command_spark; teste_command_spark()'"
        result = Command().with_command(command=command)
        actual = result.extra
        expected = {
            'command':
            "${python} -c 'from teste import teste_command_spark; teste_command_spark()'"
        }

        self.assertEqual('command', result._type)
        self.assertEqual(expected, actual)
示例#6
0
    def test_dump_one_embbed_job_and_one_simple_job(self):
        job = Command(name='shell_pwd', config={'command': 'pwd'})
        embbed_job = Command(name='embedded_flow1',
                             config={
                                 'command': 'flow_command',
                             },
                             nodes=[
                                 job,
                             ])
        expected_file_content = autopep8.fix_code(
            '{}job_0 = {}\n\njob_1 = {}\n'.format(Dumper.DEFAULT_IMPORTS,
                                                  repr(job), repr(embbed_job)),
            options={
                'aggressive': True,
            })

        self.dumper.dump_jobs(job, embbed_job)

        with open('{}/flow.py'.format(self.tem_dir)) as _file:
            file_content = ''.join(_file.readlines())
        self.assertEqual(expected_file_content, file_content)
示例#7
0
    def test_dump_simple_job(self):
        simple_job = Command(name='shell_pwd', config={'command': 'pwd'})
        expected_file_content = autopep8.fix_code('{}job_0 = {}\n'.format(
            Dumper.DEFAULT_IMPORTS, repr(simple_job)),
                                                  options={
                                                      'aggressive': True,
                                                  })

        self.dumper.dump_jobs(simple_job)

        with open('{}/flow.py'.format(self.tem_dir)) as _file:
            file_content = ''.join(_file.readlines())
        self.assertEqual(expected_file_content, file_content)