# Path: valohai_cli/exceptions.py
# class ConfigurationError(CLIException, RuntimeError):
#     kind = 'Configuration Error'
# 
# class NoCommit(ValueError, CLIException):
#     color = 'yellow'
# 
#     def __init__(self, directory: str) -> None:
#         self.directory = directory
#         super().__init__(f'{directory} has no commits')
# 
# class PackageTooLarge(CLIException):
#     pass
# 
# Path: valohai_cli/git.py
# def describe_current_commit(directory: str) -> str:
#     """
#     (Try to) describe the lineage and status of the Git working copy in `directory`.
#     :param directory: Directory path.
#     :return: Git description string
#     """
#     return check_git_output(['git', 'describe', '--always', '--long', '--dirty', '--all'], directory).strip().decode()


import os
import pytest
import valohai_cli.packager as pkg
from subprocess import check_call, check_output
from typing import Set
from click import termui
from valohai_cli.exceptions import ConfigurationError, NoCommit, PackageTooLarge
from valohai_cli.git import describe_current_commit
        pth = str(tmpdir.join('large_file.dat'))
        with open(pth, 'wb') as outfp:
            outfp.truncate(large_file_size)
        assert os.stat(pth).st_size == large_file_size


def get_tar_files(tarball):
    return set(check_output(f'tar tf {tarball}', shell=True).decode('utf8').splitlines())


def get_expected_filenames(original_set: Set[str], *, with_gitignore, with_vhignore) -> Set[str]:
    new_set = original_set.copy()
    if with_vhignore:  # vhignore stops kahvikuppi
        new_set.discard('kahvikuppi')
    if with_gitignore:  # gitignore stops asbestos
        new_set.discard('asbestos')
    return new_set


@pytest.mark.parametrize('with_commit', (False, True))
@pytest.mark.parametrize('with_vhignore', (False, True))
def test_package_git(tmpdir, with_commit, with_vhignore):
    check_call('git init', cwd=str(tmpdir), shell=True)
    write_temp_files(tmpdir, with_vhignore=with_vhignore)
    if with_commit:
        check_call('git add .', cwd=str(tmpdir), shell=True)
        check_call('git commit -m test', cwd=str(tmpdir), shell=True)
        assert describe_current_commit(str(tmpdir))
    else:
        with pytest.raises(NoCommit):

# Path: valohai_cli/exceptions.py
# class ConfigurationError(CLIException, RuntimeError):
#     kind = 'Configuration Error'
# 
# class NoCommit(ValueError, CLIException):
#     color = 'yellow'
# 
#     def __init__(self, directory: str) -> None:
#         self.directory = directory
#         super().__init__(f'{directory} has no commits')
# 
# class PackageTooLarge(CLIException):
#     pass
# 
# Path: valohai_cli/git.py
# def describe_current_commit(directory: str) -> str:
#     """
#     (Try to) describe the lineage and status of the Git working copy in `directory`.
#     :param directory: Directory path.
#     :return: Git description string
#     """
#     return check_git_output(['git', 'describe', '--always', '--long', '--dirty', '--all'], directory).strip().decode()


# Path: tests/test_packaging.py
import os
import pytest
import valohai_cli.packager as pkg
from subprocess import check_call, check_output
from typing import Set
from click import termui
from valohai_cli.exceptions import ConfigurationError, NoCommit, PackageTooLarge
from valohai_cli.git import describe_current_commit

        pth = str(tmpdir.join('large_file.dat'))
        with open(pth, 'wb') as outfp:
            outfp.truncate(large_file_size)
        assert os.stat(pth).st_size == large_file_size


def get_tar_files(tarball):
    return set(check_output(f'tar tf {tarball}', shell=True).decode('utf8').splitlines())


def get_expected_filenames(original_set: Set[str], *, with_gitignore, with_vhignore) -> Set[str]:
    new_set = original_set.copy()
    if with_vhignore:  # vhignore stops kahvikuppi
        new_set.discard('kahvikuppi')
    if with_gitignore:  # gitignore stops asbestos
        new_set.discard('asbestos')
    return new_set


@pytest.mark.parametrize('with_commit', (False, True))
@pytest.mark.parametrize('with_vhignore', (False, True))
def test_package_git(tmpdir, with_commit, with_vhignore):
    check_call('git init', cwd=str(tmpdir), shell=True)
    write_temp_files(tmpdir, with_vhignore=with_vhignore)
    if with_commit:
        check_call('git add .', cwd=str(tmpdir), shell=True)
        check_call('git commit -m test', cwd=str(tmpdir), shell=True)
        assert describe_current_commit(str(tmpdir))
    else:
        with pytest.raises(NoCommit):

            describe_current_commit(str(tmpdir))