当前位置: 首页>>代码示例>>Python>>正文


Python Printer.write方法代码示例

本文整理汇总了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())
开发者ID:lefootballroi,项目名称:honcho,代码行数:9,代码来源:test_printer.py

示例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")
开发者ID:casio,项目名称:honcho,代码行数:39,代码来源:test_printer.py

示例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())
开发者ID:lefootballroi,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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())
开发者ID:azov,项目名称:honcho,代码行数:8,代码来源:test_printer.py

示例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())
开发者ID:azov,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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())
开发者ID:azov,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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())
开发者ID:azov,项目名称:honcho,代码行数:8,代码来源:test_printer.py

示例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"
开发者ID:nickstenning,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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())
开发者ID:lefootballroi,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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())
开发者ID:azov,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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"))
开发者ID:Heart2009,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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"
开发者ID:Heart2009,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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"
开发者ID:nickstenning,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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"
开发者ID:nickstenning,项目名称:honcho,代码行数:7,代码来源:test_printer.py

示例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"
开发者ID:nickstenning,项目名称:honcho,代码行数:7,代码来源:test_printer.py


注:本文中的honcho.printer.Printer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。