def test_simple_creation(self): """ Basic creation of ShellCommand Step """ step = ShellCommandStep( builder = self.builder, name = "shell command", command = "./run", ) step.save() self.assertTrue(step.id != None) self.assertEqual(unicode(step), "shell command") self.assertEqual(step.get_config_type(), _("shell command")) # simple update should not cause any problems step.name = "run stuff" step.save() args = step.get_config_args() self.assertEqual(args.get("name", None), "run stuff") # check command was generated correctly cmd = args.get("command", []) self.assertEqual(len(cmd), 1) self.assertEqual(cmd[0], "./run") # try instantiating buildbot config object self.assert_valid_buildbot_config(step.get_config_class(), args) # Check that the resulting config string is sensible self.assert_config_string_executable(step)
def test_with_more_options(self): """ test step creation with more options """ step = ShellCommandStep( builder = self.builder, name = "shell command", command = "./run", arguments = "-f --long-args = xyz --long-args2=nospace val_1 val_2", always_run = True, halt_on_failure = False, flunk_on_warning = True, warn_on_failure = True, warning_pattern = ".*warning.*", want_stdout = False, want_stderr = False, timeout_silence = 11, timeout_runtime = 13, ) step.save() self.assertTrue(step.id != None) self.assertEqual(unicode(step), "shell command") self.assertEqual(step.get_config_type(), _("shell command")) # check additional args args = step.get_config_args() self.assertEqual(args.get("alwaysRun", None), True) self.assertEqual(args.get("haltOnFailure", None), False) self.assertEqual(args.get("flunkOnWarning", None), True) self.assertEqual(args.get("warnOnFailure", None), True) self.assertEqual(args.get("name", None), "shell command") self.assertEqual(args.get("warningPattern", None), ".*warning.*") self.assertEqual(args.get("want_stdout", None), False) self.assertEqual(args.get("want_stderr", None), False) self.assertEqual(args.get("timeout", None), 11 * 60) self.assertEqual(args.get("maxTime", None), 13 * 60) # check that command was generated correctly cmd = args.get("command", []) self.assertEqual(cmd[0], "./run") self.assertEqual(cmd[1], "-f") self.assertEqual(cmd[2], "--long-args=xyz") self.assertEqual(cmd[3], "--long-args2=nospace") self.assertEqual(cmd[4], "val_1") self.assertEqual(cmd[5], "val_2") self.assertEqual(len(cmd), 6) # try instantiating buildbot config object self.assert_valid_buildbot_config(step.get_config_class(), args) # Check that the resulting config string is sensible self.assert_config_string_executable(step)
def test_swap_position_edge_cases(self): """ Step.swap_positions(s1,s2) should not be used manually, but if it is used, we should make sure we handle some of the edge cases. """ # cannot swap steps with negative positions # (in practice, negative position is used as temp values, so this can # in fact happen during race conditions when move routines are not used # within views with @transactionnn.commit_on_success) b = Builder(project=self.project, name="my builder") b.save() s1 = ConfigureStep( builder = b, name = "configure the code", command = "./configure", ) s1.save() s2 = ShellCommandStep( builder = b, name = "run some command", command = "./run", ) s2.save() s2.position = -2 s2.save() self.assertRaises(Step.SimultaneousUpdateError, Step.swap_positions, s1, s2) # cannot swap steps from different builders b2 = Builder(project=self.project, name="my builder 2") b2.save() s3 = ShellCommandStep( builder = b2, name = "run some command", command = "./run", ) s3.save() self.assertRaises(ValueError, Step.swap_positions, s1, s3)
def test_mixed_steps(self): p = self.project b = Builder(project=p, name="my builder") b.save() self.assertEqual(b.is_complete, False) # add shell command step step_shell = ShellCommandStep( builder = b, name = "a shell command", command = "./some_command", ) step_shell.save() self.assertNotEqual(step_shell.id, None) self.assertEqual(step_shell.position, 0) self.assertEqual(b.step_count, 1) # add compile step step_compile = CompileStep( builder = b, name = "compile the code", command = "make", ) step_compile.save() self.assertNotEqual(step_compile.id, None) self.assertEqual(step_compile.position, 1) self.assertEqual(b.step_count, 2) # add configure step step_configure = ConfigureStep( builder = b, name = "configure the code", command = "./configure", ) step_configure.save() self.assertNotEqual(step_configure.id, None) self.assertEqual(step_configure.position, 2) self.assertEqual(b.step_count, 3) # add test step step_test = TestStep( builder = b, name = "test the code", command = "make", arguments = "test", ) step_test.save() self.assertNotEqual(step_test.id, None) self.assertEqual(step_test.position, 3) self.assertEqual(b.step_count, 4) expect = [_("shell command"), _("compile"), _("configure"), _("test")] for i,s in enumerate(b.step_set.all()): # calling method on parent class should raise exception self.assertRaises(NotImplementedError, s.get_config_type) self.assertRaises(NotImplementedError, s.get_config_class) self.assertRaises(NotImplementedError, s.get_config_args) # should work with r.cast() self.assertEqual(expect[i], s.cast().get_config_type()) self.assertEqual(type(s.cast().get_config_class()), type(())) self.assertEqual(type(s.cast().get_config_args()), type({}))