def test_err(self): with self.assertRaisesRegex(TypeError, r"sep must be None or a string.*"): colorprint("hello", "world", sep=1) with self.assertRaisesRegex(TypeError, r"end must be None or a string.*"): colorprint("0", "1", "2", end=3) with self.assertRaisesRegex(TypeError, r"color must be None or a string.*"): colorprint("hello", "world", color=True) with self.assertRaisesRegex(ValueError, r"invalid argument for color.*"): colorprint("hello", color="yes")
def test_eachline(self): colorprint("hello", attrs="red", color="always", eachline=True) self.assertOutput("\033[31mhello\033[0m\n") colorprint("hello", attrs="red", color="always", eachline=False) self.assertOutput("\033[31mhello\n\033[0m")
def test_attrs_color(self): colorprint("hello", attrs="red", color="always") self.assertOutput("\033[31mhello\n\033[0m") colorprint("hello", attrs="red", color="never") self.assertOutput("hello\n")
def test_file(self): out = StringIO() colorprint("hello", "world", file=out) self.assertOutput("") self.assertEqual(out.getvalue(), "hello world\n")
def test_end(self): colorprint("hello", "world", end=None) self.assertOutput("hello world\n") colorprint("hello", "world", end="") self.assertOutput("hello world")
def test_sep(self): colorprint("hello", "world", sep=None) self.assertOutput("hello world\n") colorprint("hello", "world", sep="") self.assertOutput("helloworld\n")
def test_default(self): colorprint("hello") self.assertOutput("hello\n") colorprint("hello", "world") self.assertOutput("hello world\n")