def test_as_session_2(self): @cit.as_session('DEF') def func(): print('ABC') with patch("sys.stdout", new=StringIO()) as fake_out: func() expect_word = "*\n| __DEF__________________________\nABC\n`\n" self.assertEqual(fake_out.getvalue(), expect_word)
def test_as_session_3(self): @cit.as_session def underscore_orCamel(): print('ABC') with patch("sys.stdout", new=StringIO()) as fake_out: underscore_orCamel() expect_word = "*\n| __UNDERSCORE OR CAMEL__________________________\nABC\n`\n" self.assertEqual(fake_out.getvalue(), expect_word)
def test_pause(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("\n")): # simulate press enter cit.pause() expect_word = "\nPress Enter to Continue..." self.assertEqual(fake_out.getvalue(), expect_word)
def test_dim(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.dim("ABC") self.assertEqual(fake_out.getvalue(), "| ABC\n")
def test_err(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.err("ABC") self.assertEqual(fake_out.getvalue(), "| (Error) ABC\n")
def test_warn(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.warn("ABC") self.assertEqual(fake_out.getvalue(), "| (Warning) ABC\n")
def test_info(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.info("ABC") self.assertEqual(fake_out.getvalue(), "| (Info) ABC\n")
def test_title(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.title("ABC") self.assertEqual(fake_out.getvalue(), '| __ABC__________________________\n')
def test_get_choices_exitable(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("0\n")): self.assertEqual(cit.get_choices(["ABC", "DEF"], exitable=True), []) expect_word = "0) ** EXIT **" self.assertTrue(expect_word in fake_out.getvalue())
def test_br(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.br(2) self.assertEqual(fake_out.getvalue(), '\n\n')
def test_end(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.end() self.assertEqual(fake_out.getvalue(), '`\n')
def test_get_choices_allable_unselect(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("a\na\n0\n")): # allable on, unselect all. self.assertEqual(cit.get_choices(["ABC", "DEF"], allable=True, exitable=True), []) expect_word = "[+] ABC" self.assertTrue(expect_word in fake_out.getvalue())
def test_get_choices_allable_esc(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("all\n0\n")): # allable off self.assertEqual(cit.get_choices(["a", "DEF"], allable=True, exitable=True), ["a", "DEF"]) expect_word = "all) ** ALL **" self.assertTrue(expect_word in fake_out.getvalue())
def test_get_choices_allable_off(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("a\n0\n")): # allable off self.assertEqual(cit.get_choices(["ABC", "DEF"], exitable=True), []) expect_word = "Please enter a valid choice." self.assertTrue(expect_word in fake_out.getvalue())
def test_get_input(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("ABC\n")): userinput = cit.get_input() self.assertEqual(fake_out.getvalue(), "> ") self.assertEqual(userinput, "ABC")
def test_echo_pre(self): with patch("sys.stdout", new=StringIO()) as fake_out: cit.echo("ABC", pre="prefix") self.assertEqual(fake_out.getvalue(), "| (Prefix) ABC\n")
def test_get_choice_index(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("1\n")): self.assertEqual(cit.get_choice(["ABC", "DEF"]), "ABC") expect_word = "| 1) ABC\n| 2) DEF\n> " self.assertEqual(fake_out.getvalue(), expect_word)
def test_get_choices_done_esc(self): with patch("sys.stdout", new=StringIO()) as fake_out, patch("sys.stdin", new=StringIO("1\ndone\n")): self.assertEqual(cit.get_choices(["ABC", "0"]), ["ABC", ]) expect_word = "done) ** DONE **" self.assertTrue(expect_word in fake_out.getvalue())