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


Python CLI.start方法代码示例

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


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

示例1: main

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [as 别名]
def main():
    f = open("food_diary.json", 'r')
    try:
        data = json.load(f)
    except:
        data = {}

    c = open('calories.json', 'r')
    try:
        calories = json.load(c)
    except:
        calories = {}

    f.close()
    c.close()

    cal = Calories(calories)
    fd = FoodDiary(data, cal)
    cli = CLI(fd)

    cli.start()

    f = open("food_diary.json", 'w')
    json.dump(data, f, indent=4)
    f.close()

    c = open("calories.json", 'w')
    json.dump(calories, c, indent=4)
    c.close()
开发者ID:rumen89,项目名称:programming_101,代码行数:31,代码来源:food_diary_main.py

示例2: TestCLI

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [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

示例3: manual_test

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [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

示例4: main

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [as 别名]
def main():
    c = CLI()
    c.start()
开发者ID:DarkPotatoKing,项目名称:crs-simulation,代码行数:5,代码来源:main.py

示例5: main

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [as 别名]
def main():
    dbase = DBinit()
    console = CLI(dbase)
    console.start()
开发者ID:yaggul,项目名称:Cinema,代码行数:6,代码来源:start_cinema.py

示例6: main

# 需要导入模块: from cli import CLI [as 别名]
# 或者: from cli.CLI import start [as 别名]
def main():
    sql_manager.create_database()
    cli = CLI()
    cli.start()
开发者ID:Martin95056,项目名称:HackBulgaria,代码行数:6,代码来源:start.py


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