def test_task_show_apply_to_values(self): bc = BatchCli(self.c) messages = [] messages.append("[ ? ] Please enter Apply To [009.006(003.246)]") messages.append( "[ ? ] Please enter Origin or (L)ist valid values [v1]") messages.append("[ ? ] Breackage (Y|N) [N]") messages.append("[ ? ] Is bug in released code? (Y|N) [N]") messages.append("[ ? ] Is a Dev-Escape? (Y|N) [N]") messages.append( "[ ? ] Enter Dev-Escape activity or (L)ist valid values [v1]") self.c.expect(messages) self.c.pleaseAnswer("\n", "\n", "\n", "\n", "\n", "\n", "\n") self.m.run(bc) self.c.verify()
def setUp(self): self.cli = FakeCli() self.c = BatchCli(self.cli) self.c.expectTaskCount(2)
class BatchCliTest(unittest.TestCase): def setUp(self): self.cli = FakeCli() self.c = BatchCli(self.cli) self.c.expectTaskCount(2) def test_ask(self): self.cli.pleaseAnswer("an answer") answer = self.c.ask("A question") self.assertEquals(self.cli.latestMessage, "[ ? ] A question") self.assertEquals(answer, "an answer") def test_newMessage(self): self.c.newMessage("Message1") self.assertEquals(self.cli.latestMessage, "[ ... ] Message1") self.c.newMessage("Message2") self.assertEquals(self.cli.latestMessage, "[ ... ] Message2") def test_taskNewTask(self): self.c.newTask("Task 1") self.assertEquals(self.cli.latestMessage, "[ 1/2 ] Task 1") self.c.newTask("Task 2") self.assertEquals(self.cli.latestMessage, "[ 2/2 ] Task 2") def test_cannotExceedTaskCount(self): with self.assertRaises(RuntimeError): self.c.newTask("Task 1") self.c.newTask("Task 2") self.c.newTask("Task 3") def test_confirm_ouput(self): self.cli.pleaseAnswer("Y") self.c.confirm("Can you confirm?") self.assertEquals(self.cli.latestMessage, "[ ? ] Can you confirm? (Y|N) [Y]") def test_confirm_when_user_answer_Y(self): self.cli.pleaseAnswer("Y") answer = self.c.confirm("any question") self.assertTrue(answer) self.cli.pleaseAnswer("y") answer = self.c.confirm("any question") self.assertTrue(answer) self.cli.pleaseAnswer("\n") answer = self.c.confirm("any question") self.assertTrue(answer) def test_confirm_when_user_answer_N(self): self.cli.pleaseAnswer("N") answer = self.c.confirm("any question") self.assertFalse(answer) self.cli.pleaseAnswer("n") answer = self.c.confirm("any question") self.assertFalse(answer) def test_confirm_when_user_answer_wrong(self): self.cli.pleaseAnswer("an unexpected answer", "Y") answer = self.c.confirm("any question") self.assertEquals(2, self.cli.countAsk) self.assertTrue(answer) def test_select(self): values = ['v1', 'v2', 'v3'] self.cli.pleaseAnswer("v1") answer = self.c.select("Please enter Origin or (L)ist possible values:", values) self.assertEquals(self.cli.latestMessage, "[ ? ] Please enter Origin or (L)ist possible values: [v1]") self.assertEquals('v1', answer) def test_choose(self): values = ['v1', 'v2', 'v3'] self.cli.pleaseAnswer("2") answer = self.c.choose("Please select Origin:", values) self.assertEquals(self.cli.latestMessage, "[ ? ] Please select Origin: [v1]") self.assertEquals('v2', answer) def test_select_when_not_valid_value_is_returned(self): values = ['v1', 'v2', 'v3'] self.cli.pleaseAnswer("bad value", "v1") answer = self.c.select("Please enter Origin or (L)ist possible values:", values) self.assertEquals(self.cli.latestMessage, "[ ? ] Please enter Origin or (L)ist possible values: [v1]") self.assertEquals('v1', answer) def test_select_print_all_values(self): values = ['v1', 'v2', 'v3'] self.cli.pleaseAnswer('L', 'v1') self.cli.expect(['[ - ] v1', '[ - ] v2', '[ - ] v3']) answer = self.c.select("Please select Origin:", values) self.cli.verify() def test_choose_print_all_values(self): values = ['v1', 'v2', 'v3'] self.cli.pleaseAnswer('L', '2') self.cli.expect(['[ - ] 1. v1', '[ - ] 2. v2', '[ - ] 3. v3']) answer = self.c.choose("Please choose Origin or (L)ist possible values:", values) self.cli.verify() def test_ask_when_user_aswer_right(self): self.cli.pleaseAnswer("E") answer = self.c.ask("Do you want to (C)ontinue, (S)kip or (E)xit?", ['C','S','E'], 'E') self.assertEquals(self.cli.latestMessage, "[ ? ] Do you want to (C)ontinue, (S)kip or (E)xit? (C|S|E) [E]") self.assertEquals('E', answer) self.cli.pleaseAnswer("c") answer = self.c.ask("Do you want?", ['C','S','E'], 'E') self.assertEquals('c', answer) self.cli.pleaseAnswer("\n") answer = self.c.ask("Do you want?", ['C','S','E'], 'E') self.assertEquals('E', answer) def test_ask_when_user_answer_wrong(self): self.cli.pleaseAnswer("an unexpected answer", "s") answer = self.c.ask("Do you want to (C)ontinue, (S)kip or (E)xit?", ['C','S','E'], 'E') self.assertEquals(2, self.cli.countAsk) self.assertEquals('s', answer) def test_ask_with_no_options_and_default(self): self.cli.pleaseAnswer("\n") answer = self.c.ask("Which colour?", default='Yellow') self.assertEquals("[ ? ] Which colour? [Yellow]", self.cli.latestMessage,) self.assertEquals('Yellow', answer) def test_multiple_ask(self): self.cli.pleaseAnswer("\n") answer = self.c.ask("Which colour?", default='Yellow') self.assertEquals("[ ? ] Which colour? [Yellow]", self.cli.latestMessage,) self.assertEquals('Yellow', answer) self.cli.pleaseAnswer("\n") answer = self.c.ask("Which size?", default='Medium') self.assertEquals("[ ? ] Which size? [Medium]", self.cli.latestMessage,) self.assertEquals('Medium', answer) self.cli.pleaseAnswer("\n") answer = self.c.ask("Which shape?", default='Long') self.assertEquals("[ ? ] Which shape? [Long]", self.cli.latestMessage,) self.assertEquals('Long', answer) def test_cannot_pass_suggest_but_default(self): with self.assertRaises(RuntimeError): self.c.ask("question without default", ['A','B']) def test_negate_ouput(self): self.cli.pleaseAnswer("N") self.c.negate("Can you confirm?") self.assertEquals(self.cli.latestMessage, "[ ? ] Can you confirm? (Y|N) [N]") def test_negate_when_user_answer_N(self): self.cli.pleaseAnswer("N") answer = self.c.negate("any question") self.assertTrue(answer) self.cli.pleaseAnswer("n") answer = self.c.negate("any question") self.assertTrue(answer) self.cli.pleaseAnswer("\n") answer = self.c.negate("any question") self.assertTrue(answer) def test_negate_when_user_answer_Y(self): self.cli.pleaseAnswer("Y") answer = self.c.negate("any question") self.assertFalse(answer) self.cli.pleaseAnswer("y") answer = self.c.negate("any question") self.assertFalse(answer) def test_negate_when_user_answer_wrong(self): self.cli.pleaseAnswer("an unexpected answer", "N") answer = self.c.negate("any question") self.assertEquals(2, self.cli.countAsk) self.assertTrue(answer)