Esempio 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)
Esempio 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)
Esempio n. 3
0
class TestBuildSystemSequenceGeneration(TestCase):
    @classmethod
    def setUp(self):
        self.bsg = BuildSystemGenerator()

        self.sequence = BuildSequence()

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

    def test_generate_sequence(self):
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dump_args_to_json_file, ('tmp', 'test'))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dump_args_to_json_file, ('tmp', 'test'))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(subprocess.call, (1, 2, 3, 4))

        spec = {
            'tasks': [{
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'job': dump_args_to_json_file,
                'args': ['tmp', 'test']
            }, {
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'job': dump_args_to_json_file,
                'args': ['tmp', 'test']
            }, {
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'job': subprocess.call,
                'args': [1, 2, 3, 4]
            }],
            'stage':
            'test'
        }

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertEqual(ret.stage, self.sequence.stage)

    def test_generate_sequence_shell_job(self):
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(subprocess.call,
                          dict(cwd='/tmp', args=['test', 1, 2, 3]))

        spec = {
            'tasks': [{
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'cmd': "test",
                'dir': '/tmp',
                'args': [1, 2, 3]
            }],
            'stage':
            'test'
        }

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertEqual(ret.stage, self.sequence.stage)

    def test_invalid_spec(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({
                'stage': 'cmd',
                'job': None
            }, self.funcs)

    def test_invalid_spec_task(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({
                'stage': 'cmd',
                'task': None
            }, self.funcs)

    def test_invalid_spec_tasks_type(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({
                'stage': 'cmd',
                'tasks': 'string'
            }, self.funcs)

    def test_generated_sequence_is_closed(self):
        spec = {
            'tasks': [{
                'job': dummy_function,
                'args': [1, 2]
            }, {
                'cmd': "test",
                'dir': '/tmp',
                'args': [1, 2, 3]
            }],
            'stage':
            'test'
        }

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertTrue(ret.closed)
Esempio n. 4
0
class TestBuildSystemSequenceGeneration(TestCase):
    @classmethod
    def setUp(self):
        self.bsg = BuildSystemGenerator()

        self.sequence = BuildSequence()

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

    def test_generate_sequence(self):
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dump_args_to_json_file, ('tmp', 'test'))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(dump_args_to_json_file, ('tmp', 'test'))
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(subprocess.call, (1, 2, 3, 4))

        spec = { 'tasks': [ { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'job': dump_args_to_json_file, 'args': ['tmp', 'test']},
                            { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'job': dump_args_to_json_file, 'args': ['tmp', 'test']},
                            { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'job': subprocess.call, 'args': [1, 2, 3, 4] } ],
                 'stage': 'test'}

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertEqual(ret.stage, self.sequence.stage)

    def test_generate_sequence_shell_job(self):
        self.sequence.add(dummy_function, (1, 2))
        self.sequence.add(subprocess.call, dict(cwd='/tmp', args=['test', 1, 2, 3]))

        spec = { 'tasks': [ { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'cmd': "test",
                              'dir': '/tmp',
                              'args': [1, 2, 3] } ],
                 'stage': 'test'}

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertEqual(ret.stage, self.sequence.stage)


    def test_invalid_spec(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({'stage': 'cmd', 'job': None}, self.funcs)

    def test_invalid_spec_task(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({'stage': 'cmd', 'task': None}, self.funcs)

    def test_invalid_spec_tasks_type(self):
        with self.assertRaises(InvalidStage):
            self.bsg.generate_sequence({'stage': 'cmd', 'tasks': 'string'}, self.funcs)

    def test_generated_sequence_is_closed(self):
        spec = { 'tasks': [ { 'job': dummy_function, 'args': [1, 2 ] },
                            { 'cmd': "test",
                              'dir': '/tmp',
                              'args': [1, 2, 3] } ],
                 'stage': 'test'}

        ret = self.bsg.generate_sequence(spec, self.funcs)

        self.assertTrue(ret.closed)