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


Python CLI.stop方法代码示例

本文整理汇总了Python中cli.CLI.stop方法的典型用法代码示例。如果您正苦于以下问题:Python CLI.stop方法的具体用法?Python CLI.stop怎么用?Python CLI.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cli.CLI的用法示例。


在下文中一共展示了CLI.stop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestCLI

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import stop [as 别名]
class TestCLI(unittest.TestCase):
    """ Basic CLI functionality test cases. """

    def setUp(self):
        """ Prepare mock stdin and stdout, and a CLI instance to test. """
        # Create stdin and stdout files for testing.
        self.test_stdinout = MockStdInOut()

        # Create queues to pass messages to and get messages from the CLI.
        self.to_cli_q = queue.Queue()
        self.from_cli_q = queue.Queue()

        # Create a test CLI with the test stdin and stdout.
        self.test_cli = CLI(self.to_cli_q, self.from_cli_q,
                            stdin=self.test_stdinout,
                            stdout=self.test_stdinout)
        self.test_cli.start()

    def tearDown(self):
        """ Just stop the test CLI instance. """
        self.test_cli.stop()

    def test_input_and_output(self):
        """ Test basic input and output of the CLI. """
        # Test that the CLI input works first.
        test_input = "This is some test input"
        self.test_stdinout.to_send_data.append(test_input + '\n')
        self.assertEqual(self.from_cli_q.get(timeout=0.5), test_input)

        # Now check the output. Pass a message to be written out.
        test_output = 'This is some test output'
        self.to_cli_q.put(test_output)
        # Wait for the output to be written.
        time.sleep(0.1)
        self.assertEqual(self.test_stdinout.received_data.pop(0),
                         test_output + '\n')

        # Check the CLI is still running happily.
        self.assertTrue(self.test_cli.running)

        # Finally, check there is no unread data in the files.
        self.assertEqual(self.test_stdinout.received_data, [])
        self.assertEqual(self.test_stdinout.to_send_data, [])

    def test_ending_session(self):
        """ Test the user can end the CLI instance cleanly. """
        # Simulate sending an EOF.
        self.test_stdinout.to_send_data.append('')
        self.assertEqual(self.from_cli_q.get(timeout=0.5), None)

        # This stops the reading thread, but nt the whole CLI - stop the rest.
        self.test_cli.stop()

        # Check the CLI is now stopped.
        self.assertFalse(self.test_cli.running)

        # Finally, check there is no unread data in the files.
        self.assertEqual(self.test_stdinout.received_data, [])
        self.assertEqual(self.test_stdinout.to_send_data, [])
开发者ID:olipratt,项目名称:python-cli,代码行数:61,代码来源:test_cli.py

示例2: manual_test

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import stop [as 别名]
def manual_test():
    """ Manual test for the CLI if needed. """
    to_cli_q = queue.Queue()
    from_cli_q = queue.Queue()
    cli = CLI(to_cli_q, from_cli_q)
    cli.start()
    log.info('CLI running state: %r', cli.running)

    time.sleep(10)

    log.info('CLI running state: %r', cli.running)
    cli.stop()

    try:
        while True:
            log.info('Got CLI input: %r', from_cli_q.get(timeout=0.1))
    except queue.Empty:
        pass
开发者ID:olipratt,项目名称:python-cli,代码行数:20,代码来源:test_cli.py


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