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'
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
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
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()
def test_sha_doesnt_exist(): with pytest.raises(exceptions.DownloadFailedException): Packager.create(repo='iliapolo/pyci', sha='doesnt-exist')
def test_target_dir_doesnt_exist(repo_path): with pytest.raises(exceptions.DirectoryDoesntExistException): Packager.create(target_dir='doesnt-exist', path=repo_path)
def test_path_doesnt_exist(): with pytest.raises(exceptions.DirectoryDoesntExistException): Packager.create(path='doesnt-exist')
def test_not_sha_and_not_path(): with pytest.raises(exceptions.InvalidArgumentsException): Packager.create()
def test_repo_and_path(): with pytest.raises(exceptions.InvalidArgumentsException): Packager.create(path='path', repo='repo')
def test_sha_and_path(): with pytest.raises(exceptions.InvalidArgumentsException): Packager.create(repo='repo', sha='sha', path='path')
def test_sha_and_not_repo(): with pytest.raises(exceptions.InvalidArgumentsException): Packager.create(sha='sha')