Example #1
0
 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")
Example #2
0
 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")
Example #3
0
 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")
Example #4
0
 def test_file(self):
     out = StringIO()
     colorprint("hello", "world", file=out)
     self.assertOutput("")
     self.assertEqual(out.getvalue(), "hello world\n")
Example #5
0
 def test_end(self):
     colorprint("hello", "world", end=None)
     self.assertOutput("hello world\n")
     colorprint("hello", "world", end="")
     self.assertOutput("hello world")
Example #6
0
 def test_sep(self):
     colorprint("hello", "world", sep=None)
     self.assertOutput("hello world\n")
     colorprint("hello", "world", sep="")
     self.assertOutput("helloworld\n")
Example #7
0
 def test_default(self):
     colorprint("hello")
     self.assertOutput("hello\n")
     colorprint("hello", "world")
     self.assertOutput("hello world\n")