コード例 #1
0
def test_init_again(west_init_tmpdir):
    # Test that 'west init' on an initialized tmpdir errors out

    with pytest.raises(subprocess.CalledProcessError):
        cmd('init')

    with pytest.raises(subprocess.CalledProcessError):
        cmd('init -m foo')
コード例 #2
0
def test_extension_command_execution(west_init_tmpdir):
    with pytest.raises(subprocess.CalledProcessError):
        cmd('test')

    cmd('update')

    actual = cmd('test')
    assert actual == 'Testing test command 1\n'
コード例 #3
0
ファイル: test_help.py プロジェクト: skelliam/west
def test_extension_help_and_dash_h(west_init_tmpdir):
    # Test "west help <command>" and "west <command> -h" for extension
    # commands (west_init_tmpdir has a command with one).

    cmd('update')
    ext1out = cmd('help test-extension')
    ext2out = cmd('test-extension -h')
    assert ext1out == ext2out
    assert ext1out == EXTENSION_EXPECTED
コード例 #4
0
def test_import_project_release_dir(tmpdir):
    # Tests for a workspace that imports a directory from a project
    # at a fixed release.

    remotes = tmpdir / 'remotes'
    empty_project = remotes / 'empty_project'
    create_repo(empty_project)
    add_commit(empty_project, 'empty-project empty commit')
    imported = remotes / 'imported'
    create_repo(imported)
    add_commit(imported, 'add directory of imports',
               files={'test.d/1.yml':
                      f'''\
                      manifest:
                        projects:
                        - name: west.d/1.yml-p1
                          url: {empty_project}
                        - name: west.d/1.yml-p2
                          url: {empty_project}
                      ''',
                      'test.d/2.yml':
                      f'''\
                      manifest:
                        projects:
                        - name: west.d/2.yml-p1
                          url: {empty_project}
                      '''})
    add_tag(imported, 'import-tag')

    ws = tmpdir / 'ws'
    create_workspace(ws, and_git=True)
    manifest_repo = ws / 'mp'
    add_commit(manifest_repo, 'manifest repo commit',
               files={'west.yml':
                      f'''
                      manifest:
                        projects:
                        - name: imported
                          url: {imported}
                          revision: import-tag
                          import: test.d
                      '''})

    cmd(f'init -l {manifest_repo}')
    with pytest.raises(ManifestImportFailed):
        Manifest.from_file(topdir=ws)

    cmd('update', cwd=ws)
    actual = Manifest.from_file(topdir=ws).projects
    expected = [ManifestProject(path='mp', topdir=ws),
                Project('imported', imported,
                        revision='import-tag', topdir=ws),
                Project('west.d/1.yml-p1', empty_project, topdir=ws),
                Project('west.d/1.yml-p2', empty_project, topdir=ws),
                Project('west.d/2.yml-p1', empty_project, topdir=ws)]
    for a, e in zip(actual, expected):
        check_proj_consistency(a, e)
コード例 #5
0
def test_init_local_missing_west_yml_failure(repos_tmpdir):
    # Test that 'west init -l' on repo without a 'west.yml' fails

    # Do a local clone of manifest repo
    zephyr_install_dir = repos_tmpdir.join('west_installation', 'zephyr')
    clone(str(repos_tmpdir.join('repos', 'zephyr')), str(zephyr_install_dir))
    os.remove(str(zephyr_install_dir.join('west.yml')))

    with pytest.raises(subprocess.CalledProcessError):
        cmd('init -l "{}"'.format(str(zephyr_install_dir)))
コード例 #6
0
def test_delete_cmd_all():
    # west config -D should delete from everywhere
    cmd('config --system pytest.key system')
    cmd('config --global pytest.key global')
    cmd('config --local pytest.key local')
    assert cfg(f=ALL)['pytest']['key'] == 'local'
    cmd('config -D pytest.key')
    assert 'pytest' not in cfg(f=ALL)
    with pytest.raises(subprocess.CalledProcessError):
        cmd('config -D pytest.key')
コード例 #7
0
    def test_current_commit(self, temp_repo_dir):
        """Test commit_hook._current_commit"""

        # Test empty tree
        empty_hash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
        assert commit_hook._current_commit() == empty_hash

        # Test after commit
        cmd(temp_repo_dir, "git commit --allow-empty -m msg")
        assert commit_hook._current_commit() == "HEAD"
コード例 #8
0
def test_list(west_update_tmpdir):
    # Projects shall be listed in the order they appear in the manifest.
    # Check the behavior for some format arguments of interest as well.
    actual = cmd('list -f "{name} {revision} {path} {cloned} {clone_depth}"')
    expected = [
        'zephyr (not set) zephyr (cloned) None',
        'Kconfiglib zephyr {} (cloned) None'.format(
            os.path.join('subdir', 'Kconfiglib')),
        'net-tools master net-tools (cloned) None'
    ]
    assert actual.splitlines() == expected

    # We should be able to find projects by absolute or relative path
    # when outside any project. Invalid projects should error out.
    klib_rel = os.path.join('subdir', 'Kconfiglib')
    klib_abs = str(west_update_tmpdir.join('subdir', 'Kconfiglib'))

    rel_outside = cmd('list -f "{{name}}" {}'.format(klib_rel)).strip()
    assert rel_outside == 'Kconfiglib'

    abs_outside = cmd('list -f "{{name}}" {}'.format(klib_abs)).strip()
    assert abs_outside == 'Kconfiglib'

    rel_inside = cmd('list -f "{name}" .', cwd=klib_abs).strip()
    assert rel_inside == 'Kconfiglib'

    abs_inside = cmd('list -f "{{name}}" {}'.format(klib_abs),
                     cwd=klib_abs).strip()
    assert abs_inside == 'Kconfiglib'

    with pytest.raises(subprocess.CalledProcessError):
        cmd('list NOT_A_PROJECT', cwd=klib_abs)

    with pytest.raises(subprocess.CalledProcessError):
        cmd('list NOT_A_PROJECT')
コード例 #9
0
ファイル: test_config.py プロジェクト: sylvioalves/west
def test_list():
    def sorted_list(other_args=''):
        return list(sorted(cmd('config -l ' + other_args).splitlines()))

    with pytest.raises(subprocess.CalledProcessError) as e:
        cmd('config -l pytest.foo')
        assert '-l cannot be combined with name argument' in str(e)

    assert cmd('config -l').strip() == ''

    cmd('config pytest.foo who')
    assert sorted_list() == ['pytest.foo=who']

    cmd('config pytest.bar what')
    assert sorted_list() == ['pytest.bar=what',
                             'pytest.foo=who']

    cmd('config --global pytest.baz where')
    assert sorted_list() == ['pytest.bar=what',
                             'pytest.baz=where',
                             'pytest.foo=who']
    assert sorted_list('--system') == []
    assert sorted_list('--global') == ['pytest.baz=where']
    assert sorted_list('--local') == ['pytest.bar=what',
                                      'pytest.foo=who']
コード例 #10
0
ファイル: test_project.py プロジェクト: utzig/west
def test_update_projects_local_branch_commits(west_init_tmpdir):
    # Test the 'west update' command when working on local branch with local
    # commits and then updating project to upstream commit.
    # It calls through to the same backend functions that are used for
    # automatic updates and 'west init' reinitialization.

    # update all repositories
    cmd('update')

    # Create a local branch and add commits
    checkout_branch('net-tools', 'local_net_tools_test_branch', create=True)
    checkout_branch('subdir/Kconfiglib',
                    'local_kconfig_test_branch',
                    create=True)
    checkout_branch('tagged_repo',
                    'local_tagged_repo_test_branch',
                    create=True)
    add_commit('net-tools', 'test local branch commit', reconfigure=True)
    add_commit('subdir/Kconfiglib',
               'test local branch commit',
               reconfigure=True)
    add_commit('tagged_repo', 'test local branch commit', reconfigure=True)
    net_tools_prev = head_subject('net-tools')
    kconfiglib_prev = head_subject('subdir/Kconfiglib')
    tagged_repo_prev = head_subject('tagged_repo')

    # Update the upstream repositories, getting an UpdateResults tuple
    # back.
    ur = update_helper(west_init_tmpdir)

    # We updated all the repositories, so all paths and commits should
    # be valid refs (i.e. there shouldn't be a None or empty string
    # value in a ur attribute).
    assert all(ur)

    # Verify each repository has moved to a new manifest-rev,
    # except tagged_repo, which has a manifest-rev locked to a tag.
    # Its HEAD should change, though.
    assert ur.nt_mr_0 != ur.nt_mr_1, 'failed updating net-tools manifest-rev'
    assert ur.kl_mr_0 != ur.kl_mr_1, 'failed updating kconfiglib manifest-rev'
    assert ur.tr_mr_0 == ur.tr_mr_1, 'tagged_repo manifest-rev changed'
    assert ur.nt_head_0 != ur.nt_head_1, 'failed updating net-tools HEAD'
    assert ur.kl_head_0 != ur.kl_head_1, 'failed updating kconfiglib HEAD'
    assert ur.tr_head_0 != ur.tr_head_1, 'failed updating tagged_repo HEAD'

    # Verify local branch is still present and untouched
    assert net_tools_prev != head_subject('net-tools')
    assert kconfiglib_prev != head_subject('subdir/Kconfiglib')
    assert tagged_repo_prev != head_subject('tagged_repo')
    checkout_branch('net-tools', 'local_net_tools_test_branch')
    checkout_branch('subdir/Kconfiglib', 'local_kconfig_test_branch')
    checkout_branch('tagged_repo', 'local_tagged_repo_test_branch')
    assert net_tools_prev == head_subject('net-tools')
    assert kconfiglib_prev == head_subject('subdir/Kconfiglib')
    assert tagged_repo_prev == head_subject('tagged_repo')
コード例 #11
0
def test_default_config():
    # Writing to a value without a config destination should default
    # to --local.
    cmd('config pytest.local foo')

    assert cmd('config pytest.local').rstrip() == 'foo'
    assert cmd('config --local pytest.local').rstrip() == 'foo'
    assert cfg(f=ALL)['pytest']['local'] == 'foo'
    assert 'pytest' not in cfg(f=SYSTEM)
    assert 'pytest' not in cfg(f=GLOBAL)
    assert cfg(f=LOCAL)['pytest']['local'] == 'foo'
コード例 #12
0
ファイル: test_help.py プロジェクト: tliqit/west
def test_builtin_help_and_dash_h(west_init_tmpdir):
    # Test "west help" and "west -h" are the same for built-in
    # functionality.

    h1out = cmd('help')
    h2out = cmd('-h')
    assert h1out == h2out

    for c in BUILTIN_COMMANDS.keys():
        h1out = cmd('help {}'.format(c))
        h2out = cmd('{} -h'.format(c))
        assert h1out == h2out
コード例 #13
0
def test_builtin_help_and_dash_h(west_init_tmpdir):
    # Test "west help" and "west -h" are the same for built-in
    # functionality.

    h1out = cmd('help')
    h2out = cmd('-h')
    assert h1out == h2out

    for cls in itertools.chain(*BUILTIN_COMMAND_GROUPS.values()):
        c = cls()
        h1out = cmd(f'help {c.name}')
        h2out = cmd(f'{c.name} -h')
        assert h1out == h2out
コード例 #14
0
ファイル: test_help.py プロジェクト: marc-hb/west
def test_help(west_init_tmpdir):

    # Check that output from help is equivalent to -h
    return

    h1out = cmd('help')
    h2out = cmd('-h')
    assert (h1out == h2out)

    for c in BUILTIN_COMMAND_NAMES:
        h1out = cmd('help {}'.format(c))
        h2out = cmd('{} -h'.format(c))
        assert (h1out == h2out)
コード例 #15
0
def test_logging(ftp_root, ftp_server, work_dir, capfd):
    """Test if INFO and up is logged to stderr as well."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    cmd('out', source, [str(work_dir)])

    # test if INFO messages are logged
    assert 'uploading file:' in capfd.readouterr()[1]
コード例 #16
0
def test_status(west_init_tmpdir):
    # FIXME: Check output

    # Status with no projects cloned shouldn't fail

    cmd('status')

    # Neither should it fail after fetching one or both projects

    cmd('update net-tools')
    cmd('status')

    cmd('update Kconfiglib')
    cmd('status --long')  # Pass a custom flag too
コード例 #17
0
ファイル: test_help.py プロジェクト: skelliam/west
def test_builtin_help_and_dash_h(west_init_tmpdir):
    # Test "west help" and "west -h" are the same for built-in
    # functionality.

    h1out = cmd('help')
    h2out = cmd('-h')
    assert h1out == h2out

    # Test "west help <command>" and "west <command> -h" for built-in
    # commands.
    for c in BUILTIN_COMMAND_NAMES:
        h1out = cmd('help {}'.format(c))
        h2out = cmd('{} -h'.format(c))
        assert h1out == h2out
コード例 #18
0
def test_logging(ftp_root, ftp_server, work_dir, capfd):
    """Test if INFO and up is logged to stderr as well."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    cmd('out', source, [str(work_dir)])

    # test if INFO messages are logged
    assert 'uploading file:' in capfd.readouterr()[1]
コード例 #19
0
def test_diff(west_init_tmpdir):
    # FIXME: Check output

    # Diff with no projects cloned shouldn't fail

    cmd('diff')

    # Neither should it fail after fetching one or both projects

    cmd('update net-tools')
    cmd('diff')

    cmd('update Kconfiglib')
    cmd('diff --cached')  # Pass a custom flag too
コード例 #20
0
def test_forall(west_init_tmpdir):
    # FIXME: Check output
    # The 'echo' command is available in both 'shell' and 'batch'

    # 'forall' with no projects cloned shouldn't fail

    cmd("forall -c 'echo *'")

    # Neither should it fail after cloning one or both projects

    cmd('update net-tools')
    cmd("forall -c 'echo *'")

    cmd('update Kconfiglib')
    cmd("forall -c 'echo *'")
コード例 #21
0
ファイル: test_project.py プロジェクト: utzig/west
def test_update_tag_to_tag(west_init_tmpdir):
    # Verify we can update the tagged_repo repo to a new tag.

    # We only need to clone tagged_repo locally.
    cmd('update tagged_repo')

    def updater(remotes):
        # Create a v2.0 tag on the remote tagged_repo repository.
        add_commit(remotes.tagged_repo, 'another tagged_repo tagged commit')
        add_tag(remotes.tagged_repo, 'v2.0')

        # Update the manifest file to point the project's revision at
        # the new tag.
        manifest = Manifest.from_file(topdir=west_init_tmpdir)
        for p in manifest.projects:
            if p.name == 'tagged_repo':
                p.revision = 'v2.0'
                break
        else:
            assert False, 'no tagged_repo'
        with open(west_init_tmpdir / 'zephyr' / 'west.yml', 'w') as f:
            f.write(manifest.as_yaml())  # NOT as_frozen_yaml().

        # Pull down the v2.0 tag into west_init_tmpdir.
        cmd('update tagged_repo')

    ur = update_helper(west_init_tmpdir, updater=updater)

    # Make sure we have manifest-rev and HEADs before and after.
    assert ur.tr_mr_0
    assert ur.tr_mr_1
    assert ur.tr_head_0
    assert ur.tr_head_1

    # Make sure we have v1.0 and v2.0 tags locally.
    v1_0 = check_output([GIT, 'rev-parse', 'refs/tags/v1.0^{commit}'],
                        cwd=ur.tr_local)
    v2_0 = check_output([GIT, 'rev-parse', 'refs/tags/v2.0^{commit}'],
                        cwd=ur.tr_local)
    assert v1_0
    assert v2_0

    # Check that all the updates (including the first one in this
    # function) behaved correctly.
    assert ur.tr_mr_0 == v1_0
    assert ur.tr_mr_1 == v2_0
    assert ur.tr_head_0 == v1_0
    assert ur.tr_head_1 == v2_0
コード例 #22
0
def test_put_a_file_glob(ftp_root, ftp_server, work_dir):
    """Test if only specific files are uploaded."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)
    work_dir.join('otherfilename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {"file": "filename-*.tgz"}

    result = cmd('out', source, [str(work_dir)], params=params)

    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.0.tgz').read() == CONTENT
    assert result == {
        "version": {
            "version": "0.0.0"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.0.tgz"
            },
        ]
    }
コード例 #23
0
def test_manifest_freeze(west_update_tmpdir):
    # We should be able to freeze manifests.
    actual = cmd('manifest --freeze').splitlines()
    # Match the actual output against the expected line by line,
    # so failing lines can be printed in the test output.
    #
    # Since the actual remote URLs and SHAs are not predictable, we
    # don't match those precisely. However, we do expect the output to
    # match project order as specified in our manifest, that all
    # revisions are full 40-character SHAs, and there isn't any random
    # YAML tag crap.
    expected_res = [
        '^west:$', '^  url: .*$', '^  revision: [a-f0-9]{40}$', '^manifest:$',
        '^  defaults:$', '^    remote: test-local$', '^    revision: master$',
        '^  remotes:$', '^  - name: test-local$', '^    url-base: .*$',
        '^  projects:$', '^  - name: Kconfiglib$', '^    remote: test-local$',
        '^    revision: [a-f0-9]{40}$', '^    path: subdir/Kconfiglib$',
        '^  - name: net-tools$', '^    remote: test-local$',
        '^    revision: [a-f0-9]{40}$',
        '^    west-commands: scripts/west-commands.yml$', '^  self:$',
        '^    path: zephyr$'
    ]

    for eline_re, aline in zip(expected_res, actual):
        assert re.match(eline_re, aline) is not None, (aline, eline_re)
コード例 #24
0
def test_delete_old_few(ftp_root, ftp_server, work_dir):
    """Test if to few files are not deleted."""

    # create file to upload
    work_dir.join('filename-0.0.4.tgz').write(CONTENT)
    make_files(ftp_root, ['filename-0.0.3.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {
        'keep_versions': 3
    }

    result = cmd('out', source, [str(work_dir)], params=params)

    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join('filename-0.0.3.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.4.tgz').read() == CONTENT

    assert result == {
        "version": {"version": "0.0.4"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.4.tgz"},
        ]
    }
コード例 #25
0
def test_delete_old_few(ftp_root, ftp_server, work_dir):
    """Test if to few files are not deleted."""

    # create file to upload
    work_dir.join('filename-0.0.4.tgz').write(CONTENT)
    make_files(ftp_root, ['filename-0.0.3.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {'keep_versions': 3}

    result = cmd('out', source, [str(work_dir)], params=params)

    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.3.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.4.tgz').read() == CONTENT

    assert result == {
        "version": {
            "version": "0.0.4"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.4.tgz"
            },
        ]
    }
コード例 #26
0
def test_put_a_file(ftp_root, ftp_server, work_dir):
    """Test if a file can be stored."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('out', source, [str(work_dir)])

    assert ftp_root.join(DIRECTORY).join(
        'filename-0.0.0.tgz').read() == CONTENT
    assert result == {
        "version": {
            "version": "0.0.0"
        },
        "metadata": [
            {
                "name": "file",
                "value": "filename-0.0.0.tgz"
            },
        ]
    }
コード例 #27
0
ファイル: test_project.py プロジェクト: utzig/west
def test_manifest_freeze(west_update_tmpdir):
    # We should be able to freeze manifests.
    actual = cmd('manifest --freeze').splitlines()
    # Match the actual output against the expected line by line,
    # so failing lines can be printed in the test output.
    #
    # Since the actual remote URLs and SHAs are not predictable, we
    # don't match those precisely. However, we do expect:
    #
    # - the output to match project order as specified in our
    #   manifest
    # - attributes are listed in NURPCW order (name, url, ...)
    # - all revisions are full 40-character SHAs
    # - there isn't any random YAML tag crap
    expected_res = [
        '^manifest:$', '^  projects:$', '^  - name: Kconfiglib$',
        '^    url: .*$', '^    revision: [a-f0-9]{40}$',
        '^    path: subdir/Kconfiglib$', '^  - name: tagged_repo$',
        '^    url: .*$', '^    revision: [a-f0-9]{40}$',
        '^  - name: net-tools$', '^    url: .*$',
        '^    revision: [a-f0-9]{40}$', '^    clone-depth: 1$',
        '^    west-commands: scripts/west-commands.yml$', '^  self:$',
        '^    path: zephyr$'
    ]

    for eline_re, aline in zip(expected_res, actual):
        assert re.match(eline_re, aline) is not None, (aline, eline_re)
コード例 #28
0
def test_log_input(ftp_root, ftp_server, work_dir, capfd):
    """Test if JSON input is logged to file for easy replay."""

    work_dir.join('log_input-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>log_input-(?P<version>.*).tgz)"
    }

    cmd('out', source, [str(work_dir)])

    in_files = sorted(glob.glob(os.path.join(tempfile.tempdir, 'in-*')), key=os.path.getmtime)
    assert in_files

    with open(in_files[-1]) as f:
        assert set(json.loads(f.read()).keys()) == {"params", "source", "version"}
コード例 #29
0
ファイル: test_config.py プロジェクト: marc-hb/west
def test_config_global(west_init_tmpdir):
    if not os.path.exists(os.path.expanduser('~')):
        os.mkdir(os.path.expanduser('~'))

    # To ensure that GLOBAL home folder points into tox temp dir.
    # Otherwise fail the test, as we don't want to risk manipulating user's
    # west config
    assert canon_path(config.ConfigFile.GLOBAL.value) == \
        canon_path(os.path.join(os.environ.get('TOXTEMPDIR'),
                                'pytest-home', '.westconfig'))

    # Make sure the value is currently unset.
    testkey_value = cmd('config pytest.testkey_global')
    assert testkey_value == ''

    # Set value globally.
    cmd('config --global pytest.testkey_global foo')

    # Read from --local, to ensure that is empty.
    testkey_value = cmd('config --local pytest.testkey_global')
    assert testkey_value == ''

    # Read from --system, to ensure that is empty.
    testkey_value = cmd('config --system pytest.testkey_global')
    assert testkey_value == ''

    # Read from --global, and check the value.
    testkey_value = cmd('config --global pytest.testkey_global')
    assert testkey_value.rstrip() == 'foo'

    # Without an explicit config source, the global value (the only
    # one set) should be returned.
    testkey_value = cmd('config pytest.testkey_global')
    assert testkey_value.rstrip() == 'foo'
コード例 #30
0
def test_config_global(west_init_tmpdir):
    if not os.path.exists(os.path.expanduser('~')):
        os.mkdir(os.path.expanduser('~'))

    # To ensure that GLOBAL home folder points into tox temp dir.
    # Otherwise fail the test, as we don't want to risk manipulating user's
    # west config
    assert config.ConfigFile.GLOBAL.value == \
        os.path.join(os.environ.get('TOXTEMPDIR'), 'pytest-home/.westconfig')

    testkey_value = cmd('config pytest.testkey_global')
    assert testkey_value == ''

    # Set value in user's testing home
    cmd('config --global pytest.testkey_global ' + str(west_init_tmpdir))

    # Readback from --local, to ensure that is empty.
    testkey_value = cmd('config --local pytest.testkey_global')
    assert testkey_value == ''

    # Readback from --system, to ensure that is empty.
    testkey_value = cmd('config --system pytest.testkey_global')
    assert testkey_value == ''

    # Readback from --global, and compare the value with the expected.
    testkey_value = cmd('config --global pytest.testkey_global')
    assert testkey_value.strip('\n') == str(west_init_tmpdir)

    # Readback in from all files should also provide the value.
    testkey_value = cmd('config pytest.testkey_global')
    assert testkey_value.strip('\n') == str(west_init_tmpdir)
コード例 #31
0
ファイル: test_project.py プロジェクト: utzig/west
def test_topdir_in_workspace(west_init_tmpdir):
    # Running west topdir anywhere inside of a workspace ought to
    # work, and return the same thing.

    expected = PurePath(str(west_init_tmpdir)).as_posix()

    # This should be available immediately after west init.
    assert cmd('topdir').strip() == expected

    # After west update, it should continue to work, and return the
    # same thing (not getting confused when called from within a
    # project directory or a random user-created subdirectory, e.g.)
    cmd('update')
    assert cmd('topdir', cwd=str(west_init_tmpdir / 'subdir' /
                                 'Kconfiglib')).strip() == expected
    west_init_tmpdir.mkdir('pytest-foo')
    assert cmd('topdir',
               cwd=str(west_init_tmpdir / 'pytest-foo')).strip() == expected
コード例 #32
0
def test_extension_help_and_dash_h(west_init_tmpdir):
    # Test "west help <command>" and "west <command> -h" for extension
    # commands (west_init_tmpdir has a command with one).

    cmd('update')
    ext1out = cmd('help test-extension')
    ext2out = cmd('test-extension -h')

    expected = EXTENSION_EXPECTED
    if sys.platform == 'win32':
        # Manage gratuitous incompatibilities:
        #
        # - multiline python strings are \n separated even on windows
        # - the windows command help output gets an extra newline
        expected = os.linesep.join(expected.splitlines()) + os.linesep

    assert ext1out == ext2out
    assert ext1out == expected
コード例 #33
0
def test_update_projects(west_init_tmpdir):
    # Test the 'west update' command. It calls through to the same backend
    # functions that are used for automatic updates and 'west init'
    # reinitialization.

    # update all repositories
    cmd('update')

    # Add commits to the local repos. We need to reconfigure
    # explicitly as these are clones, and west doesn't handle that for
    # us.
    (nt_mr_0, nt_mr_1, nt_head_0, nt_head_1, kl_mr_0, kl_mr_1, kl_head_0,
     kl_head_1) = update_helper(west_init_tmpdir, 'update')

    assert nt_mr_0 != nt_mr_1, 'failed to update net-tools manifest-rev'
    assert nt_head_0 != nt_head_1, 'failed to update net-tools HEAD'
    assert kl_mr_0 != kl_mr_1, 'failed to update kconfiglib manifest-rev'
    assert kl_head_0 != kl_head_1, 'failed to update kconfiglib HEAD'
コード例 #34
0
def update_helper(west_tmpdir, command):
    # Helper command for causing a change in two remote repositories,
    # then running a project command on the west installation.
    #
    # Adds a commit to both of the kconfiglib and net-tools projects
    # remotes, then run `command`.
    #
    # Captures the 'manifest-rev' and HEAD SHAs in both repositories
    # before and after running the command, returning them in a tuple
    # like this:
    #
    # (net-tools-manifest-rev-before,
    #  net-tools-manifest-rev-after,
    #  net-tools-HEAD-before,
    #  net-tools-HEAD-after,
    #  kconfiglib-manifest-rev-before,
    #  kconfiglib-manifest-rev-after,
    #  kconfiglib-HEAD-before,
    #  kconfiglib-HEAD-after)

    nt_remote = str(west_tmpdir.join('..', 'repos', 'net-tools'))
    nt_local = str(west_tmpdir.join('net-tools'))
    kl_remote = str(west_tmpdir.join('..', 'repos', 'Kconfiglib'))
    kl_local = str(west_tmpdir.join('subdir', 'Kconfiglib'))

    nt_mr_0 = check_output([GIT, 'rev-parse', 'manifest-rev'], cwd=nt_local)
    kl_mr_0 = check_output([GIT, 'rev-parse', 'manifest-rev'], cwd=kl_local)
    nt_head_0 = check_output([GIT, 'rev-parse', 'HEAD'], cwd=nt_local)
    kl_head_0 = check_output([GIT, 'rev-parse', 'HEAD'], cwd=kl_local)

    add_commit(nt_remote, 'another net-tools commit')
    add_commit(kl_remote, 'another kconfiglib commit')

    cmd(command)

    nt_mr_1 = check_output([GIT, 'rev-parse', 'manifest-rev'], cwd=nt_local)
    kl_mr_1 = check_output([GIT, 'rev-parse', 'manifest-rev'], cwd=kl_local)
    nt_head_1 = check_output([GIT, 'rev-parse', 'HEAD'], cwd=nt_local)
    kl_head_1 = check_output([GIT, 'rev-parse', 'HEAD'], cwd=kl_local)

    return (nt_mr_0, nt_mr_1,
            nt_head_0, nt_head_1,
            kl_mr_0, kl_mr_1,
            kl_head_0, kl_head_1)
コード例 #35
0
    def test_list_of_committed_files(self, temp_repo_dir):
        """Test commit_hook._get_list_of_committed_files"""

        # Test empty tree
        assert commit_hook._get_list_of_committed_files() == []

        # Create file "a"
        test_file = write_file(temp_repo_dir, "a", "foo")
        assert commit_hook._get_list_of_committed_files() == []

        # Add "a"
        cmd(temp_repo_dir, "git add " + test_file)
        assert commit_hook._get_list_of_committed_files() == [test_file]

        # Commit "a"
        cmd(temp_repo_dir, "git commit -m msg")
        assert commit_hook._get_list_of_committed_files() == []

        # Edit "a"
        write_file(temp_repo_dir, "a", "bar")
        assert commit_hook._get_list_of_committed_files() == []

        # Add "a"
        cmd(temp_repo_dir, "git add " + test_file)
        assert commit_hook._get_list_of_committed_files() == [test_file]
コード例 #36
0
def test_check_multiple_files(ftp_root, ftp_server):
    """Test if multiple uploaded file return more versions."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.1"}], 'should only return most recent version'
コード例 #37
0
def test_check_one_file(ftp_root, ftp_server):
    """Test if one uploaded file returns one version."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source)

    assert result == [{"version": "0.0.0"}]
コード例 #38
0
def test_check_no_new_version(ftp_root, ftp_server):
    """When passing a version an no newer files return nothing."""

    make_files(ftp_root, ['filename-0.0.0.tgz', 'filename-0.0.1.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert result == []
コード例 #39
0
def test_delete_old_sorting(ftp_root, ftp_server, work_dir):
    """Test if natural sorting is used when deleting."""

    # create file to upload
    work_dir.join('filename-0.0.14.tgz').write(CONTENT)
    make_files(ftp_root, [
        'filename-0.0.0.tgz',
        'filename-0.0.1.tgz',
        'filename-0.0.2.tgz',
        'filename-0.0.3.tgz',
        'filename-0.0.10.tgz',
        'filename-0.0.11.tgz',
        'filename-0.0.12.tgz',
        'filename-0.0.13.tgz',
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {
        'keep_versions': 3
    }

    result = cmd('out', source, [str(work_dir)], params=params)

    # old files should be deleted
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.0.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.1.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.2.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.3.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.10.tgz').exists()
    assert not ftp_root.join(DIRECTORY).join('filename-0.0.11.tgz').exists()
    # three latests versions should be kept
    assert ftp_root.join(DIRECTORY).join('filename-0.0.12.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.13.tgz').read() == CONTENT
    assert ftp_root.join(DIRECTORY).join('filename-0.0.14.tgz').read() == CONTENT

    assert result == {
        "version": {"version": "0.0.14"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.14.tgz"},
        ]
    }
コード例 #40
0
def test_check_passing_version(ftp_root, ftp_server):
    """Test when a version is passed only new versions are returned."""

    make_files(ftp_root, [
        'filename-0.0.0.tgz', 'filename-0.0.1.tgz', 'filename-0.0.2.tgz', 'filename-0.0.3.tgz'
    ])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('check', source, version={"version": "0.0.1"})

    assert {"version": "0.0.2"} in result, 'new version should be in result'
    assert {"version": "0.0.3"} in result, 'new version should be in result'
    assert {"version": "0.0.0"} not in result, 'older version should not be in result'
    assert {"version": "0.0.1"} not in result, 'current version should not be in result'
コード例 #41
0
def test_put_a_file(ftp_root, ftp_server, work_dir):
    """Test if a file can be stored."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('out', source, [str(work_dir)])

    assert ftp_root.join(DIRECTORY).join('filename-0.0.0.tgz').read() == CONTENT
    assert result == {
        "version": {"version": "0.0.0"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.0.tgz"},
        ]
    }
コード例 #42
0
def test_get_a_file(ftp_root, ftp_server, work_dir):
    """Test if a file can be retrieved."""

    make_files(ftp_root, ['filename-0.0.0.tgz'])

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    result = cmd('in', source, [str(work_dir)], version={"version": "0.0.0"})

    assert work_dir.join('filename-0.0.0.tgz').read() == '123'
    assert result == {
        "version": {"version": "0.0.0"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.0.tgz"},
        ]
    }
コード例 #43
0
def test_put_a_file_glob(ftp_root, ftp_server, work_dir):
    """Test if only specific files are uploaded."""

    work_dir.join('filename-0.0.0.tgz').write(CONTENT)
    work_dir.join('otherfilename-0.0.0.tgz').write(CONTENT)

    source = {
        "uri": ftp_server,
        "regex": "(?P<file>filename-(?P<version>.*).tgz)"
    }

    params = {
        "file": "filename-*.tgz"
    }

    result = cmd('out', source, [str(work_dir)], params=params)

    assert ftp_root.join(DIRECTORY).join('filename-0.0.0.tgz').read() == CONTENT
    assert result == {
        "version": {"version": "0.0.0"},
        "metadata": [
            {"name": "file", "value": "filename-0.0.0.tgz"},
        ]
    }