コード例 #1
0
def test_non_primary_return_code():
    # since Python < 3.5 on Windows does not support signaling SIGINT to the subprocesses
    # we can't expect them to shutdown cleanly, therefore we ignore this test
    if os.name == 'nt':
        return

    default_launcher = DefaultLauncher()

    async def coroutine1():
        await asyncio.sleep(1)
        print('one', file=sys.stderr)
        await asyncio.sleep(1)
        print('two', file=sys.stderr)
        return 3

    async def coroutine2():
        await asyncio.sleep(1)
        print('one mississippi', file=sys.stderr)
        return 0

    launch_descriptor = LaunchDescriptor()
    launch_descriptor.add_coroutine(coroutine1(), name='coroutine1')
    launch_descriptor.add_coroutine(coroutine2(),
                                    name='coroutine2',
                                    exit_handler=primary_exit_handler)

    print('launch', file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done', rc, file=sys.stderr)
    assert rc == 3, 'Expected return code is 3'
コード例 #2
0
def test_launch_with_coroutine():
    default_launcher = DefaultLauncher()

    launch_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'launch_counter.py')
    launch_descriptor = LaunchDescriptor()
    load_launch_file(launch_file, launch_descriptor, {})

    async def coroutine():
        await asyncio.sleep(1)
        print('one', file=sys.stderr)
        await asyncio.sleep(1)
        print('two', file=sys.stderr)
        await asyncio.sleep(1)
        print('three', file=sys.stderr)

    async def coroutine2():
        await asyncio.sleep(1)
        print('one mississippi', file=sys.stderr)
        await asyncio.sleep(1)
        print('two mississippi', file=sys.stderr)
        await asyncio.sleep(1)
        print('three mississippi', file=sys.stderr)

    launch_descriptor.add_coroutine(
        coroutine(), name='coroutine', exit_handler=primary_exit_handler)
    # launch_descriptor.add_coroutine(coroutine2())

    print('launch', file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done', rc, file=sys.stderr)
コード例 #3
0
        def test_func(node_fixture):
            """Run an executable with cli_args and coroutine test in the same asyncio loop."""
            nonlocal cli_args

            # Create a command launching a name_maker executable specified by the pytest fixture
            command = [node_fixture['executable']]
            # format command line arguments with random string from test fixture
            for arg in cli_args:
                command.append(
                    arg.format(random_string=node_fixture['random_string']))

            # Execute python files using same python used to start this test
            env = dict(os.environ)
            if command[0][-3:] == '.py':
                command.insert(0, sys.executable)
                env['PYTHONUNBUFFERED'] = '1'

            ld = LaunchDescriptor()
            ld.add_process(cmd=command,
                           name='name_maker_' + coroutine_test.__name__,
                           env=env)
            ld.add_coroutine(coroutine_test(node_fixture),
                             name=coroutine_test.__name__,
                             exit_handler=primary_exit_handler)
            launcher = DefaultLauncher()
            launcher.add_launch_descriptor(ld)
            return_code = launcher.launch()
            assert return_code == 0, 'Launch failed with exit code %r' % (
                return_code, )
コード例 #4
0
ファイル: test_multiple_launch.py プロジェクト: kyrofa/launch
def launch(index):
    default_launcher = DefaultLauncher()

    async def coroutine():
        await asyncio.sleep(1)
        print('message %d' % index, file=sys.stderr)

    launch_descriptor = LaunchDescriptor()
    launch_descriptor.add_coroutine(coroutine(), name='coroutine%d' % index)

    print('launch %d' % index, file=sys.stderr)
    default_launcher.add_launch_descriptor(launch_descriptor)
    rc = default_launcher.launch()
    print('done %d' % index, rc, file=sys.stderr)