Exemple #1
0
def test_combine_multi_args():
    '''Resolve combine multiple paths'''

    pyver = str(sys.version[:3])
    expected = {
        'PATH': [{
            'win': data_path('home', 'testenv', 'Scripts'),
            'linux': data_path('home', 'testenv', 'bin'),
            'osx': data_path('home', 'testenv', 'bin')
        }[platform]],
        'CPENV_ACTIVE_MODULES': [],
        'UNRESOLVED_PATH': '$NOVAR',
        'RESOLVED_PATH': data_path('home', 'testenv', 'resolved'),
        'PLATFORM_PATH': 'environ_' + platform,
        'MULTI_PLATFORM_PATH': [
            'nonplat',
            pyver + '/' + platform + 'a',
            pyver + '/' + platform + 'b',
        ]
    }

    r = Resolver('testenv', 'testmod')
    r.resolve()
    combined = r.combine()

    for k in expected.keys():
        if isinstance(expected[k], list):
            assert expected[k] == combined[k]
            continue
        assert os.path.normpath(expected[k]) == os.path.normpath(combined[k])
Exemple #2
0
def test_resolve_home():
    '''Resolve environment in CPENV_HOME'''

    r = Resolver('testenv')
    r.resolve()

    assert r.resolved[0].path == data_path('home', 'testenv')
Exemple #3
0
    def run(self, args):

        core.echo()

        # Get repo
        if args.to_repo:
            to_repo = api.get_repo(name=args.to_repo)
        else:
            to_repo = core.prompt_for_repo(
                api.get_repos(),
                "Choose a repo to publish to",
                default_repo_name="home",
            )

        # Resolve module
        resolver = Resolver(api.get_repos())
        module_spec = resolver.resolve([args.module])[0]
        core.echo()

        # Confirm publication
        choice = core.prompt("Publish module to %s?[y/n] " % to_repo.name)
        if choice.lower() not in ["y", "yes", "yup"]:
            core.echo("Aborted.")
            sys.exit(1)

        # Publish
        module = Module(module_spec.path)
        published = to_repo.upload(module, args.overwrite)
        core.echo()

        core.echo("Activate your module:")
        core.echo("  cpenv activate %s" % published.real_name)
        core.echo()
Exemple #4
0
def test_resolve_absolute():
    '''Resolve environment from absolute path'''

    with cwd(data_path('not_home')):
        r = Resolver(data_path('home', 'testenv'))
        r.resolve()

    assert r.resolved[0].path == data_path('home', 'testenv')
Exemple #5
0
def test_resolve_relative():
    '''Resolve environment from relative path'''

    with cwd(data_path('not_home')):
        r = Resolver('testenv')
        r.resolve()

    assert r.resolved[0].path == data_path('not_home', 'testenv')
Exemple #6
0
def test_resolve_multi_args():
    '''Resolve multiple paths'''

    r = Resolver('testenv', 'testmod')
    r.resolve()

    assert isinstance(r.resolved[0], VirtualEnvironment)
    assert isinstance(r.resolved[1], Module)
Exemple #7
0
def test_resolve_cache():
    '''Resolve environment from cache'''

    cached_env_path = data_path('cached', 'cachedenv')
    mock_cache = mock.Mock()
    mock_cache.find = mock.Mock(
        return_value=VirtualEnvironment(cached_env_path)
    )

    r = Resolver('cachedenv', cache=mock_cache)
    r.resolve()

    assert r.resolved[0].path == cached_env_path
Exemple #8
0
def test_redirect_resolver_from_folder():
    '''Resolve environment from folder, parent folder has .cpenv file'''

    expected_paths = [
        data_path('home', 'testenv'),
        data_path('home', 'testenv', 'modules', 'testmod'),
    ]

    r = Resolver(data_path('not_home', 'project', 'sequence', 'shot'))
    r.resolve()

    assert r.resolved[0].path == expected_paths[0]
    assert r.resolved[1].path == expected_paths[1]
Exemple #9
0
    def run(self, args):

        core.echo()

        if args.from_repo:
            from_repo = api.get_repo(args.from_repo)
        else:
            from_repo = core.prompt_for_repo(
                api.get_repos(),
                "Download from",
                default_repo_name="home",
            )

        if args.to_repo:
            to_repo = api.get_repo(args.to_repo)
        else:
            repos = api.get_repos()
            repos.remove(from_repo)
            to_repo = core.prompt_for_repo(
                repos,
                "Upload to",
                default_repo_name="home",
            )

        resolver = Resolver([from_repo])
        module_specs = resolver.resolve(args.modules)
        core.echo()

        choice = core.prompt("Copy these modules to %s?[y/n] " % to_repo.name)
        if choice.lower() not in ["y", "yes", "yup"]:
            core.echo("Aborted.")
            core.exit(1)
        core.echo()

        copier = Copier(to_repo)
        copier.copy(module_specs, args.overwrite)
Exemple #10
0
def test_multi_module_does_not_exist():
    '''Raise ResolveError when a module does not exist'''

    r = Resolver('testenv', 'testmod', 'does_not_exist')
    r.resolve()
Exemple #11
0
def test_nonexistant_module():
    '''Raise ResolveError when module does not exist'''

    r = Resolver('testenv', 'does_not_exist')
    r.resolve()
Exemple #12
0
def test_nonexistant_virtualenv():
    '''Raise ResolveError when environment does not exist'''

    r = Resolver('does_not_exist')
    r.resolve()