Ejemplo n.º 1
0
class TestBuildGeneratorProcessStageSpecs(TestCase):
    @classmethod
    def setUp(self):
        self.bsg = BuildSystemGenerator()
        self.bsg.add_task('dumb', dummy_function)
        self.bsg.add_task('dumb_json', dump_args_to_json_file)
        self.bsg.add_task('dumb_json_newline',
                          dump_args_to_json_file_with_newlines)
        self.bsg.add_task('shell', subprocess.call)

        self.funcs = {
            'dumb': dummy_function,
            'dump_json_newline': dump_args_to_json_file_with_newlines,
            'shell': subprocess.call,
            'dumb_json': dump_args_to_json_file
        }

        self.strings = {'is': 'is not', 'can': 'cannot'}

    def test_process_stage_python_job(self):
        spec = {
            'job': 'dumb',
            'args': [1, 2, 3],
            'stage': 'test',
            'msg': 'wtf'
        }
        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_job(spec, self.funcs)
        self.assertEqual(ret, expected)

    def test_process_stage_python_job_with_replacement(self):
        spec = {
            'job': 'dumb',
            'args': [1, 2, 3],
            'stage': 'test',
            'msg': 'wtf {can} this be or {is}'
        }

        ret = self.bsg._process_stage(spec, strings=self.strings)

        ex_spec = self.bsg.process_strings(spec, self.strings)
        expected = self.bsg.generate_job(ex_spec, self.funcs)

        self.assertEqual(ret, expected)

    def test_process_stage_shell_job(self):
        spec = {
            'dir': '/tmp',
            'args': [1, 2, 3],
            'cmd': 'cat',
            'stage': 'test',
            'msg': 'wtf'
        }

        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_shell_job(spec)
        self.assertEqual(ret, expected)

    def test_process_stage_shell_job_with_replacement(self):
        spec = {
            'dir': '/tmp',
            'args': [1, 2, 3],
            'cmd': 'cat',
            'stage': 'test',
            'msg': 'wtf {can} this be or {is}'
        }

        ex_spec = self.bsg.process_strings(spec, self.strings)
        ret = self.bsg._process_stage(spec, strings=self.strings)
        expected = self.bsg.generate_shell_job(ex_spec)
        self.assertEqual(ret, expected)

    def test_process_stage_task_sequence(self):
        spec = {
            'stage':
            'test',
            'tasks': [{
                'dir': '/tmp',
                'args': [1, 2, 3],
                'cmd': 'cat',
                'stage': 'test',
                'msg': 'wtf {can} this be or {is}'
            }, {
                'job': 'dumb',
                'args': [1, 2, 3],
                'stage': 'test',
                'msg': 'wtf'
            }],
            'msg':
            'wtf {can} this be or {is}'
        }

        ret = self.bsg._process_stage(spec)
        expected = (self.bsg.generate_sequence(spec, self.funcs).run, None)
        self.assertEqual(str(ret)[:-18], str(expected)[:-18])

    def test_process_stage_task_sequence_replacement(self):
        spec = {
            'stage':
            'test',
            'tasks': [{
                'dir': '/tmp',
                'args': [1, 2, 3],
                'cmd': 'cat',
                'stage': 'test',
                'msg': 'wtf {can} this be or {is}'
            }, {
                'job': 'dumb',
                'args': [1, 2, 3],
                'stage': 'test',
                'msg': 'wtf'
            }],
            'msg':
            'wtf {can} this be or {is}'
        }

        ex_spec = self.bsg.process_strings(spec, self.strings)
        ret = self.bsg._process_stage(spec, strings=self.strings)
        expected = (self.bsg.generate_sequence(ex_spec, self.funcs).run, None)
        self.assertEqual(str(ret)[:-18], str(expected)[:-18])

    def test_invalid_spec(self):
        spec = {'is': 'is not', 'can': 'cannot'}

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec)

    def test_invalid_spec_with_keys(self):
        spec_keys = set(['stage', 'task'])

        spec = {'stage': 'is not', 'test': 'cannot', 'msg': 'stage'}

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec, spec_keys=spec_keys)

    def test_invalid_spec_with_keys(self):
        spec_keys = set(['stage', 'task'])

        spec = {'is': 'is not', 'can': 'cannot'}

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec, spec_keys=spec_keys)

    def test_process_stage_shell_job_with_keys(self):
        spec_keys = set(['dir', 'cmd', 'args', 'stage'])

        spec = {
            'dir': '/tmp',
            'args': [1, 2, 3],
            'cmd': 'cat',
            'stage': 'test',
            'msg': 'wtf'
        }

        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_shell_job(spec)
        self.assertEqual(ret, expected)
Ejemplo n.º 2
0
class TestBuildGeneratorProcessStageSpecs(TestCase):
    @classmethod
    def setUp(self):
        self.bsg = BuildSystemGenerator()
        self.bsg.add_task('dumb', dummy_function)
        self.bsg.add_task('dumb_json', dump_args_to_json_file)
        self.bsg.add_task('dumb_json_newline', dump_args_to_json_file_with_newlines)
        self.bsg.add_task('shell', subprocess.call)

        self.funcs = { 'dumb': dummy_function,
                       'dump_json_newline': dump_args_to_json_file_with_newlines,
                       'shell': subprocess.call,
                       'dumb_json': dump_args_to_json_file }

        self.strings = { 'is': 'is not',
                         'can': 'cannot' }

    def test_process_stage_python_job(self):
        spec = { 'job': 'dumb',
                 'args': [1,2,3],
                 'stage': 'test',
                 'msg': 'wtf'}
        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_job(spec, self.funcs)
        self.assertEqual(ret, expected)

    def test_process_stage_python_job_with_replacement(self):
        spec = { 'job': 'dumb',
                 'args': [1,2,3],
                 'stage': 'test',
                 'msg': 'wtf {can} this be or {is}'}

        ret = self.bsg._process_stage(spec, strings=self.strings)

        ex_spec = self.bsg.process_strings(spec, self.strings)
        expected = self.bsg.generate_job(ex_spec, self.funcs)

        self.assertEqual(ret, expected)

    def test_process_stage_shell_job(self):
        spec = { 'dir': '/tmp',
                 'args': [1,2,3],
                 'cmd': 'cat',
                 'stage': 'test',
                 'msg': 'wtf'}

        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_shell_job(spec)
        self.assertEqual(ret, expected)

    def test_process_stage_shell_job_with_replacement(self):
        spec = { 'dir': '/tmp',
                 'args': [1,2,3],
                 'cmd': 'cat',
                 'stage': 'test',
                 'msg': 'wtf {can} this be or {is}'}

        ex_spec = self.bsg.process_strings(spec, self.strings)
        ret = self.bsg._process_stage(spec, strings=self.strings)
        expected = self.bsg.generate_shell_job(ex_spec)
        self.assertEqual(ret, expected)

    def test_process_stage_task_sequence(self):
        spec = { 'stage': 'test',
                 'tasks': [
                     { 'dir': '/tmp',
                       'args': [1,2,3],
                       'cmd': 'cat',
                       'stage': 'test',
                       'msg': 'wtf {can} this be or {is}'},
                     { 'job': 'dumb',
                       'args': [1,2,3],
                       'stage': 'test',
                       'msg': 'wtf' }
                    ],
                 'msg': 'wtf {can} this be or {is}'}

        ret = self.bsg._process_stage(spec)
        expected = (self.bsg.generate_sequence(spec, self.funcs).run, None)
        self.assertEqual(str(ret)[:-18], str(expected)[:-18])

    def test_process_stage_task_sequence_replacement(self):
        spec = { 'stage': 'test',
                 'tasks': [
                     { 'dir': '/tmp',
                       'args': [1,2,3],
                       'cmd': 'cat',
                       'stage': 'test',
                       'msg': 'wtf {can} this be or {is}'},
                     { 'job': 'dumb',
                       'args': [1,2,3],
                       'stage': 'test',
                       'msg': 'wtf' }
                    ],
                 'msg': 'wtf {can} this be or {is}'}

        ex_spec = self.bsg.process_strings(spec, self.strings)
        ret = self.bsg._process_stage(spec, strings=self.strings)
        expected = (self.bsg.generate_sequence(ex_spec, self.funcs).run, None)
        self.assertEqual(str(ret)[:-18], str(expected)[:-18])

    def test_invalid_spec(self):
        spec = { 'is': 'is not',
                 'can': 'cannot' }

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec)

    def test_invalid_spec_with_keys(self):
        spec_keys = set(['stage', 'task'])

        spec = { 'stage': 'is not',
                 'test': 'cannot',
                 'msg': 'stage' }

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec, spec_keys=spec_keys)

    def test_invalid_spec_with_keys(self):
        spec_keys = set(['stage', 'task'])

        spec = { 'is': 'is not',
                 'can': 'cannot' }

        with self.assertRaises(InvalidJob):
            self.bsg._process_stage(spec, spec_keys=spec_keys)

    def test_process_stage_shell_job_with_keys(self):
        spec_keys = set(['dir', 'cmd', 'args', 'stage'])

        spec = { 'dir': '/tmp',
                 'args': [1,2,3],
                 'cmd': 'cat',
                 'stage': 'test',
                 'msg': 'wtf'}

        ret = self.bsg._process_stage(spec)
        expected = self.bsg.generate_shell_job(spec)
        self.assertEqual(ret, expected)