def test_output_goes_to_next_step_args(self): sm = step_manager('sm') s1 = sm.add_step(step_description(step_with_output1), {}, {}) s2 = sm.add_step(step_description(step_with_output2), {}, {}) s3 = sm.add_step(step_description(step_with_output3), {}, {}) s4 = sm.add_step(step_description(step_with_output4), {}, {}) result = sm.execute({}, {}, {}) self.assertTrue(result.success) self.assertEqual({}, s1.saved_args) self.assertEqual({'foo': '5', 'bar': 6}, s2.saved_args) self.assertEqual({ 'foo': '5', 'bar': 6, 'fruit': 'kiwi' }, s3.saved_args) self.assertEqual( { 'cheese': 'blue', 'foo': '5', 'bar': 6, 'fruit': 'kiwi' }, s4.saved_args) self.assertEqual( { 'drink': 'bourbon', 'cheese': 'blue', 'foo': '5', 'bar': 6, 'fruit': 'kiwi' }, result.output)
def test_one_step(self): sm = step_manager('sm') self._add_test_step(sm, 'one', True) result = sm.execute({}, {}, {}) self.assertTrue(result.success) self.assertEqual(None, result.message) self.assertEqual(None, result.failed_step)
def test_step_results(self): sm = step_manager('sm') script = {} env = {} s = sm.add_step(step_description(sample_step_fake_output1), script, env) expected_output = {'foo': 6, 'bar': 'hi'} result = sm.execute(script, env, {'fake_output': expected_output}) self.assertTrue(result.success) self.assertEqual(None, result.message) self.assertEqual(None, result.failed_step) self.assertEqual(expected_output, result.output)
def test_step_args(self): sm = step_manager('sm') bar_step = self._add_save_args_step(sm) step_args = {'fruit': 'apple', 'num': 666} bar_step.update_args(step_args) result = sm.execute({}, {}, {}) self.assertTrue(result.success) self.assertEqual(None, result.message) self.assertEqual(None, result.failed_step) self.assertEqual(step_args, bar_step.saved_args)
def test_multiple_step(self): self.maxDiff = None execute_args = {'global_food': 'steak', 'global_drink': 'wine'} step1_args = {'step1_fruit': 'apple', 'step1_num': 666} step2_args = {'step2_fruit': 'durian', 'step2_num': 667} step3_args = {'step3_fruit': 'mangosteen', 'step3_num': 668} all_steps_args = dict_util.combine(step1_args, step2_args, step3_args) description_args1 = { 'desc1_wine': 'barolo', 'desc1_cheese': 'manchego' } description_args2 = { 'desc2_wine': 'barolo', 'desc2_cheese': 'manchego' } description_args3 = { 'desc3_wine': 'barolo', 'desc3_cheese': 'manchego' } description_args = dict_util.combine(description_args1, description_args2, description_args3) multi_step_description = step_description(self.test_multi_steps, args=description_args) sm = step_manager('sm') multi_step = sm.add_step(multi_step_description, {}, {}) multi_step.update_args(all_steps_args) result = sm.execute({}, {}, execute_args) expected_saved_args = dict_util.combine(execute_args, all_steps_args, description_args) self.assertTrue(result.success) self.assertEqual(None, result.message) self.assertEqual(None, result.failed_step) self.assertEqual(expected_saved_args, multi_step.steps[0].saved_args) self.assertEqual(expected_saved_args, multi_step.steps[1].saved_args) self.assertEqual(expected_saved_args, multi_step.steps[2].saved_args)
def test_failed(self): sm = step_manager('sm') step_one_a = self._add_test_step(sm, 'one_a', True) step_one_b = self._add_test_step(sm, 'one_b', True) step_one_c = self._add_test_step(sm, 'one_c', True) step_two_a = self._add_test_step(sm, 'two_a', True) step_two_b = self._add_test_step(sm, 'two_b', False) step_two_c = self._add_test_step(sm, 'two_c', True) step_three_a = self._add_test_step(sm, 'three_a', True) step_three_b = self._add_test_step(sm, 'three_b', True) step_three_c = self._add_test_step(sm, 'three_c', True) result = sm.execute({}, {}, {}) self.assertFalse(result.success) self.assertEqual('step two_b failed', result.message)
def test_output_goes_to_next_step_args_multi_step(self): sm = step_manager('sm') s = sm.add_step( step_description(self.multi_step_with_steps_that_output), {}, {}) result = sm.execute({}, {}, {}) self.assertTrue(result.success) self.assertEqual({}, s.steps[0].saved_args) self.assertEqual({'foo': '5', 'bar': 6}, s.steps[1].saved_args) self.assertEqual({ 'foo': '5', 'bar': 6, 'fruit': 'kiwi' }, s.steps[2].saved_args) self.assertEqual( { 'cheese': 'blue', 'foo': '5', 'bar': 6, 'fruit': 'kiwi' }, s.steps[3].saved_args)
def test_multi_step_results(self): self.maxDiff = None sm = step_manager('sm') script = {} env = {} s = sm.add_step(step_description(self.test_multi_step), script, env) expected_output1 = {'foo': 6, 'bar': 'hi'} expected_output2 = {'fruit': 'kiwi', 'cheese': 'manchego'} expected_output3 = {'wine': 'barolo', 'nut': 'almond'} execute_args = { 'fake_output': expected_output1, 'fake_output2': expected_output2, 'fake_output3': expected_output3, } expected_output = dict_util.combine(expected_output1, expected_output2, expected_output3) result = sm.execute(script, env, execute_args) self.assertTrue(result.success) self.assertEqual(None, result.message) self.assertEqual(None, result.failed_step) self.assertEqual(expected_output, result.output)
def __init__(self, recipe, build_target, env): log.add_logging(self, 'rebuild') build_blurb.add_blurb(self, 'rebuild') check.check_recipe(recipe) check.check_build_target(build_target) self.env = env self.timer = self.env.config.timer self.recipe = recipe self.build_target = build_target self.enabled = self.build_target.parse_expression(recipe.enabled) self.recipe_dir = path.dirname(self.filename) self._step_manager = step_manager('rebuild') self.working_dir = self._make_working_dir( self.env.config.builds_dir(self.build_target), self.descriptor.full_name, self.env.config.timestamp) self.source_unpacked_dir = path.join(self.working_dir, 'source') self.build_dir = path.join(self.working_dir, 'build') self.stage_dir = path.join(self.working_dir, 'stage') self.staged_files_dir = path.join(self.stage_dir, 'files') self.staged_files_lib_dir = path.join(self.staged_files_dir, 'lib') self.staged_files_bin_dir = path.join(self.staged_files_dir, 'bin') self.staged_files_instructions_dir = path.join( self.staged_files_lib_dir, 'rebuild_instructions') self.stagged_env_dir = path.join(self.stage_dir, 'env') self.artifact_dir = path.join(self.working_dir, 'artifact') self.logs_dir = path.join(self.working_dir, 'logs') self.test_dir = path.join(self.working_dir, 'test') self.check_dir = path.join(self.working_dir, 'check') self.temp_dir = path.join(self.working_dir, 'temp') self.python_lib_dir = path.join(self.staged_files_dir, 'lib/python') self.requirements_manager = package_manager( path.join(self.working_dir, 'requirements'), env.artifact_manager) self.substitutions = { 'REBUILD_BUILD_DIR': self.build_dir, 'REBUILD_PACKAGE_DESCRIPTION': self.descriptor.name, 'REBUILD_PACKAGE_FULL_NAME': self.descriptor.full_name, 'REBUILD_PACKAGE_FULL_VERSION': str(self.descriptor.version), 'REBUILD_PACKAGE_NAME': self.descriptor.name, 'REBUILD_PACKAGE_UPSTREAM_VERSION': self.descriptor.version.upstream_version, 'REBUILD_PYTHON_PLATFORM_NAME': self.build_target.system, 'REBUILD_RECIPE_DIR': path.abspath(self.recipe_dir), 'REBUILD_REQUIREMENTS_BIN_DIR': self.requirements_manager.bin_dir, 'REBUILD_REQUIREMENTS_DIR': self.requirements_manager.installation_dir, 'REBUILD_REQUIREMENTS_INCLUDE_DIR': self.requirements_manager.include_dir, 'REBUILD_REQUIREMENTS_LIB_DIR': self.requirements_manager.lib_dir, 'REBUILD_REQUIREMENTS_SHARE_DIR': self.requirements_manager.share_dir, 'REBUILD_SOURCE_UNPACKED_DIR': self.source_unpacked_dir, 'REBUILD_STAGE_FRAMEWORKS_DIR': path.join(self.staged_files_dir, 'frameworks'), 'REBUILD_STAGE_PREFIX_DIR': self.staged_files_dir, 'REBUILD_STAGE_PYTHON_LIB_DIR': self.python_lib_dir, 'REBUILD_TEMP_DIR': self.temp_dir, 'REBUILD_TEST_DIR': self.test_dir, } self._add_steps()
def test_add_step(self): sm = step_manager('sm') s = self._add_test_step(sm, 'one', True) self.assertEqual({'fake_name': 'one', 'fake_success': True}, s.args)