本文整理汇总了Python中honcho.printer.Printer.write方法的典型用法代码示例。如果您正苦于以下问题:Python Printer.write方法的具体用法?Python Printer.write怎么用?Python Printer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类honcho.printer.Printer
的用法示例。
在下文中一共展示了Printer.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_defaults_multiline
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_defaults_multiline(self):
out = FakeOutput()
p = Printer(output=out, env=FakeEnv())
p.write("one\ntwo\nthree")
expect = "12:42:00 unknown | one\n12:42:00 unknown | two\n12:42:00 unknown | three"
self.assertEqual(expect, out.last_write())
示例2: TestPrinter
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
class TestPrinter(object):
def setup(self):
self.out = MagicMock()
self._dt_patch = patch('honcho.printer.datetime')
self._dt = self._dt_patch.start()
self._dt.now.return_value = datetime.datetime(2012, 8, 11, 12, 42)
def teardown(self):
self._dt_patch.stop()
def test_defaults_simple(self):
self.p = Printer(output=self.out)
self.p.write("monkeys")
self.out.write.assert_called_once_with("12:42:00 unknown | monkeys")
def test_defaults_multiline(self):
self.p = Printer(output=self.out)
self.p.write("one\ntwo\nthree")
expect = "12:42:00 unknown | one\n12:42:00 unknown | two\n12:42:00 unknown | three"
self.out.write.assert_called_once_with(expect)
def test_name_simple(self):
self.p = Printer(output=self.out, name="Robert Louis Stevenson")
self.p.write("quiescent")
self.out.write.assert_called_once_with("12:42:00 Robert Louis Stevenson | quiescent")
def test_length_simple(self):
self.p = Printer(output=self.out, name="oop", width=6)
self.p.write("narcissist")
self.out.write.assert_called_once_with("12:42:00 oop | narcissist")
def test_colour_simple(self):
self.p = Printer(output=self.out, name="red", colour="31")
self.p.write("conflate")
self.out.write.assert_called_once_with("\033[31m12:42:00 red | \033[0mconflate")
示例3: test_defaults_simple
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_defaults_simple(self):
out = FakeOutput()
p = Printer(output=out, env=FakeEnv())
p.write("monkeys")
self.assertEqual("12:42:00 unknown | monkeys", out.last_write())
示例4: test_write_with_colour
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_colour(self):
out = FakeOutput()
p = Printer(output=out)
p.write(fake_message("conflate\n", name="foo", colour="31"))
self.assertEqual("\033[31m12:42:00 foo | \033[0mconflate\n",
out.string())
示例5: test_write_with_name_and_set_width
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_name_and_set_width(self):
out = FakeOutput()
p = Printer(output=out, width=6)
p.write(fake_message("narcissist\n", name="oop"))
self.assertEqual("12:42:00 oop | narcissist\n", out.string())
示例6: test_write_with_set_width
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_set_width(self):
out = FakeOutput()
p = Printer(output=out, width=6)
p.write(fake_message("giraffe\n"))
self.assertEqual("12:42:00 | giraffe\n", out.string())
示例7: test_write_with_name
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_name(self):
out = FakeOutput()
p = Printer(output=out)
p.write(fake_message("quiescent\n", name="Robert Louis Stevenson"))
self.assertEqual("12:42:00 Robert Louis Stevenson | quiescent\n",
out.string())
示例8: test_write_without_colour_tty
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_without_colour_tty(self):
out = FakeTTY()
p = Printer(output=out, prefix=True, colour=False)
p.write(fake_message("paranoid android\n", name="foo", colour="31"))
assert out.string() == "12:42:00 foo | paranoid android\n"
示例9: test_length_simple
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_length_simple(self):
out = FakeOutput()
p = Printer(output=out, name="oop", width=6, env=FakeEnv())
p.write("narcissist")
self.assertEqual("12:42:00 oop | narcissist", out.last_write())
示例10: test_write_invalid_utf8
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_invalid_utf8(self):
out = FakeOutput()
p = Printer(output=out)
p.write(fake_message(b"\xfe\xff\n"))
self.assertEqual("12:42:00 | \ufffd\ufffd\n", out.string())
示例11: test_write_wrong_type
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_wrong_type(self):
out = FakeOutput()
p = Printer(output=out)
with pytest.raises(RuntimeError):
p.write(fake_message("monkeys\n", type="error"))
示例12: test_write
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write(self):
out = FakeOutput()
p = Printer(output=out)
p.write(fake_message("monkeys\n"))
assert out.string() == "12:42:00 | monkeys\n"
示例13: test_write_with_colour_non_tty
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_colour_non_tty(self):
out = FakeOutput()
p = Printer(output=out)
p.write(fake_message("conflate\n", name="foo", colour="31"))
assert out.string() == "12:42:00 foo | conflate\n"
示例14: test_write_with_colour_tty
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_with_colour_tty(self):
out = FakeTTY()
p = Printer(output=out)
p.write(fake_message("conflate\n", name="foo", colour="31"))
assert out.string() == "\033[0m\033[31m12:42:00 foo | \033[0mconflate\n"
示例15: test_write_without_prefix_non_tty
# 需要导入模块: from honcho.printer import Printer [as 别名]
# 或者: from honcho.printer.Printer import write [as 别名]
def test_write_without_prefix_non_tty(self):
out = FakeOutput()
p = Printer(output=out, prefix=False)
p.write(fake_message("paranoid android\n", name="foo", colour="31"))
assert out.string() == "paranoid android\n"