Esempio n. 1
0
def test_binary_multiple_default_entrypoints():

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'multiple-entrypoints'))

    packager = Packager.create(path=repo_path)

    with pytest.raises(exceptions.MultipleDefaultEntrypointsFoundException):
        packager.binary()
Esempio n. 2
0
    def __init__(self, repo_path, log=None):

        self.repo_path = repo_path
        self.version = test_utils.patch_setup_py(self.repo_path)

        self._logger = log or logger.Logger(__name__)
        self._click_runner = CliRunner()
        self._local_runner = LocalCommandRunner()
        self._packager = Packager.create(path=repo_path, target_dir=repo_path)
Esempio n. 3
0
def test_binary_no_default_entrypoint():

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'no-entrypoint'))

    packager = Packager.create(path=repo_path)

    with pytest.raises(exceptions.FailedDetectingPackageMetadataException) as e:
        packager.binary()

    assert e.value.argument == 'entry_points'
Esempio n. 4
0
def test_binary_only_requirements_txt(runner):

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'only-requirements'))

    packager = Packager.create(path=repo_path)

    binary_path = packager.binary(base_name='only-requirements', entrypoint='main.py')

    # lets make sure the binary actually works
    assert runner.run(binary_path).std_out == 'Hello from requirements'
Esempio n. 5
0
def test_binary_auto_detect_entrypoint(runner):

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'with-entrypoint'))

    packager = Packager.create(path=repo_path)

    binary_path = packager.binary()

    # lets make sure the binary actually works
    assert runner.run(binary_path).std_out == 'Hello from entrypoint'
Esempio n. 6
0
def test_nsis_no_default_version(temp_file, mocker):

    mocker.patch('pyci.api.utils.is_windows')

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'no-version'))

    packager = Packager.create(path=repo_path)

    with pytest.raises(exceptions.FailedDetectingPackageMetadataException) as e:
        packager.nsis(temp_file)

    assert e.value.argument == 'version'
Esempio n. 7
0
def test_binary_no_requirements(runner):

    repo_path = test_resources.get_resource_path(os.path.join('repos', 'no-requirements'))

    packager = Packager.create(path=repo_path)

    binary_path = packager.binary(base_name='no-requirements', entrypoint='main.py')

    result = runner.run(binary_path, exit_on_failure=False)

    assert 'No module' in result.std_err
    assert 'six' in result.std_err
Esempio n. 8
0
def pack(ctx, repo, sha, path, target_dir):
    """
    Sub-command for packing source code.

    Notice that in case neither --sha nor --path are provided, the last commit from your
    repository's default branch will be
    used.

    """

    ci_provider = ctx.obj.ci_provider

    sha = sha if sha else (ci_provider.sha if ci_provider else None)

    if not path:
        repo = detect_repo(ctx, ci_provider, repo)

    if repo and not sha:
        raise click.UsageError('Must specify --sha as well')

    if sha and path:
        raise click.UsageError("Use either --sha or --path, not both")

    if not sha and not path:
        raise click.UsageError('Must specify either --sha or --path')

    try:

        log.echo('Fetching repository...', break_line=False)

        ctx.obj.packager = Packager.create(repo=repo,
                                           path=path,
                                           sha=sha,
                                           target_dir=target_dir)

        log.checkmark()

    except BaseException as e:

        if isinstance(e, exceptions.DirectoryDoesntExistException):
            e.cause = 'The target directory you specified does not exist'
            e.possible_solutions = ['Create the directory and try again']

        if isinstance(e, exceptions.DownloadFailedException):
            # pylint: disable=no-member
            if e.code == 404:
                e.cause = 'You either provided a non existing sha or a non existing repository'

        log.xmark()
        raise
Esempio n. 9
0
def _pack(pyci, repo_path):

    packager = Packager.create(path=repo_path)

    # pylint: disable=too-few-public-methods
    class PackSubCommand(object):
        def __init__(self):
            self.api = packager

        @staticmethod
        def run(command, binary=False, catch_exceptions=False):

            pack_options = '--path {}'.format(repo_path)

            command = '--no-ci pack {} {}'.format(pack_options, command)

            return pyci.run(command=command,
                            binary=binary,
                            catch_exceptions=catch_exceptions)

    return PackSubCommand()
Esempio n. 10
0
def test_sha_doesnt_exist():

    with pytest.raises(exceptions.DownloadFailedException):
        Packager.create(repo='iliapolo/pyci', sha='doesnt-exist')
Esempio n. 11
0
def test_target_dir_doesnt_exist(repo_path):

    with pytest.raises(exceptions.DirectoryDoesntExistException):
        Packager.create(target_dir='doesnt-exist',
                        path=repo_path)
Esempio n. 12
0
def test_path_doesnt_exist():

    with pytest.raises(exceptions.DirectoryDoesntExistException):
        Packager.create(path='doesnt-exist')
Esempio n. 13
0
def test_not_sha_and_not_path():

    with pytest.raises(exceptions.InvalidArgumentsException):
        Packager.create()
Esempio n. 14
0
def test_repo_and_path():

    with pytest.raises(exceptions.InvalidArgumentsException):
        Packager.create(path='path', repo='repo')
Esempio n. 15
0
def test_sha_and_path():

    with pytest.raises(exceptions.InvalidArgumentsException):
        Packager.create(repo='repo', sha='sha', path='path')
Esempio n. 16
0
def test_sha_and_not_repo():

    with pytest.raises(exceptions.InvalidArgumentsException):
        Packager.create(sha='sha')