Пример #1
0
def test_main():
    with EntryPointContext(extension1=Extension1,
                           extension2=Extension2,
                           extension3=Extension3):
        with patch(
                'colcon_core.argument_parser.get_argument_parser_extensions',
                return_value={}):
            with pytest.raises(SystemExit) as e:
                main(argv=['--help'])
            assert e.value.code == 0

            with pytest.raises(SystemExit) as e:
                main(argv=['--log-level', 'invalid'])
            assert e.value.code == 2

            # avoid creating log directory in the package directory
            log_base = mkdtemp(prefix='test_colcon_')
            argv = ['--log-base', log_base]
            try:
                main(argv=argv + ['--log-level', 'info'])

                with patch(
                        'colcon_core.command.load_entry_points',
                        return_value=
                    {
                        'key1':
                        EnvironmentVariable('name', 'description'),
                        'key2':
                        EnvironmentVariable(
                            'extra_long_name_to_wrap help',
                            'extra long description text to require a wrap of '
                            'the help text not_only_on_spaces_but_also_forced_'
                            'within_a_very_long_consecutive_word'),
                    }):
                    main(argv=argv + ['extension1'])
            finally:
                # the logging subsystem might still have file handles pending
                # therefore only try to delete the temporary directory
                shutil.rmtree(log_base, ignore_errors=True)

        # catch KeyboardInterrupt and return SIGINT error code
        with patch('colcon_core.command._main', return_value=0) as _main:
            _main.side_effect = KeyboardInterrupt()
            rc = main()
            assert rc == signal.SIGINT
Пример #2
0
def test_main():
    ws_base = Path(mkdtemp(prefix='test_colcon_'))
    resources_base = Path('test', 'resources').absolute()
    shutil.copytree(resources_base / 'test_src', ws_base / 'src')

    os.chdir(ws_base)
    argv = []

    try:
        main(argv=argv + ['build'])
        main(argv=argv + ['list', '--packages-select-cache-modified'])
        main(argv=argv + ['list', '--packages-select-cache-unmodified'])
        main(argv=argv + ['list', '--packages-select-cache-invalid'])
        main(argv=argv + ['list', '--packages-skip-cache-valid'])

        main(argv=argv + ['cache', 'lock', '--ignore-dependencies'])
        main(argv=argv + ['cache', 'lock', '--dirhash-ratchet'])
        main(argv=argv + ['cache', 'lock', '--dirhash-reset'])
        main(argv=argv + ['cache', 'lock', '--dirhash-jobs=1'])
        main(argv=argv + ['cache', 'lock'])
        main(argv=argv + ['build'])
        main(argv=argv + ['test'])
        main(argv=argv + ['list', '--packages-select-cache-modified'])
        main(argv=argv + ['list', '--packages-select-cache-unmodified'])
        main(argv=argv + ['list', '--packages-select-cache-invalid'])
        main(argv=argv + ['list', '--packages-skip-cache-valid'])
        print('ws_base: ', ws_base)
    finally:
        # the logging subsystem might still have file handles pending
        # therefore only try to delete the temporary directory
        # shutil.rmtree(ws_base, ignore_errors=True)
        pass

    shutil.rmtree(ws_base / 'build')
    shutil.rmtree(ws_base / 'install')
    shutil.rmtree(ws_base / 'log')

    repo = Repo.init(ws_base / 'src' / 'test-repo')
    repo.config_writer().set_value('user', 'name', 'foo').release()
    repo.config_writer().set_value('user', 'email', 'bar').release()
    repo.git.add(all=True)
    repo.git.commit(message='initial commit')

    try:
        main(argv=argv + ['cache', 'lock'])
        main(argv=argv + ['cache', 'lock', '--git-reference-revision=HEAD'])
        main(argv=argv +
             ['cache', 'lock', '--git-reference-revision=unresolvable'])

        test_file = \
            ws_base / 'src' / 'test-repo' / 'test-package-b' / 'setup.py'
        with open(test_file, 'a') as f:
            f.write('\n# foo\n')

        main(argv=argv + ['cache', 'lock'])
        main(argv=argv + ['build'])

        main(argv=argv + [
            'list', '--packages-select-cache-invalid',
            '--packages-select-cache-key', 'test'
        ])
        main(argv=argv + [
            'list', '--packages-skip-cache-valid',
            '--packages-select-cache-key', 'test'
        ])

        main(argv=argv + ['test'])
        main(argv=argv + ['list', '--packages-select-cache-modified'])
        main(argv=argv + ['list', '--packages-select-cache-unmodified'])
        main(argv=argv + ['list', '--packages-select-cache-invalid'])
        main(argv=argv + ['list', '--packages-skip-cache-valid'])

        main(argv=argv + [
            'list', '--packages-select-cache-invalid',
            '--packages-select-cache-key', 'test'
        ])
        main(argv=argv + [
            'list', '--packages-skip-cache-valid',
            '--packages-select-cache-key', 'test'
        ])

        print('ws_base: ', ws_base)

        test_file = \
            ws_base / 'src' / 'test-repo' / 'test-package-b' / 'test_fail.py'
        with open(test_file, 'w') as f:
            f.write('def test_empty():\n    assert False\n')

        test_file = \
            ws_base / 'src' / 'test-repo' / 'test-package-c' / 'trash.txt'
        os.remove(test_file)

        main(argv=argv + ['cache', 'lock'])

        main(argv=argv + ['list', '--packages-select-cache-modified'])
        main(argv=argv + ['list', '--packages-select-cache-unmodified'])
        main(argv=argv + ['list', '--packages-select-cache-invalid'])
        main(argv=argv + ['list', '--packages-skip-cache-valid'])

        main(argv=argv + ['build'])
        main(argv=argv + ['test'])
        main(argv=argv + ['test-result'])

        test_file = \
            ws_base / 'src' / 'test-repo' / 'test-package-b' / 'setup.py'
        with open(test_file, 'a') as f:
            f.write('assert False\n')
        main(argv=argv +
             ['cache', 'lock', '--packages-select', 'test-package-b'])
        main(argv=argv + ['build'])

        # test_file = \
        #     ws_base / 'colcon.meta'
        # with open(test_file, 'w') as f:
        #     f.write('{"names": {"test-package-b": {"vcs_type": "foo"}}}\n')
        # main(argv=argv + ['cache', 'lock', '--metas', 'colcon.meta'])

    finally:
        # the logging subsystem might still have file handles pending
        # therefore only try to delete the temporary directory
        # shutil.rmtree(ws_base, ignore_errors=True)
        pass