# Path: pre_commit_hooks/check_added_large_files.py
# def find_large_added_files(
#         filenames: Sequence[str],
#         maxkb: int,
#         *,
#         enforce_all: bool = False,
# ) -> int:
#     # Find all added files that are also in the list of files pre-commit tells
#     # us about
#     retv = 0
#     filenames_filtered = set(filenames)
#     filter_lfs_files(filenames_filtered)
# 
#     if not enforce_all:
#         filenames_filtered &= added_files()
# 
#     for filename in filenames_filtered:
#         kb = int(math.ceil(os.stat(filename).st_size / 1024))
#         if kb > maxkb:
#             print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
#             retv = 1
# 
#     return retv
# 
# Path: pre_commit_hooks/check_added_large_files.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         'filenames', nargs='*',
#         help='Filenames pre-commit believes are changed.',
#     )
#     parser.add_argument(
#         '--enforce-all', action='store_true',
#         help='Enforce all files are checked, not just staged files.',
#     )
#     parser.add_argument(
#         '--maxkb', type=int, default=500,
#         help='Maximum allowable KB for added files',
#     )
#     args = parser.parse_args(argv)
# 
#     return find_large_added_files(
#         args.filenames,
#         args.maxkb,
#         enforce_all=args.enforce_all,
#     )
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout
# 
# Path: testing/util.py
# def git_commit(*args, **kwargs):
#     cmd = ('git', 'commit', '--no-gpg-sign', '--no-verify', '--no-edit', *args)
#     subprocess.check_call(cmd, **kwargs)


import shutil
import pytest
from pre_commit_hooks.check_added_large_files import find_large_added_files
from pre_commit_hooks.check_added_large_files import main
from pre_commit_hooks.util import cmd_output
from testing.util import git_commit
from __future__ import annotations





def test_nothing_added(temp_git_dir):
    with temp_git_dir.as_cwd():
        assert find_large_added_files(['f.py'], 0) == 0


def test_adding_something(temp_git_dir):
    with temp_git_dir.as_cwd():
        temp_git_dir.join('f.py').write("print('hello world')")

# Path: pre_commit_hooks/check_added_large_files.py
# def find_large_added_files(
#         filenames: Sequence[str],
#         maxkb: int,
#         *,
#         enforce_all: bool = False,
# ) -> int:
#     # Find all added files that are also in the list of files pre-commit tells
#     # us about
#     retv = 0
#     filenames_filtered = set(filenames)
#     filter_lfs_files(filenames_filtered)
# 
#     if not enforce_all:
#         filenames_filtered &= added_files()
# 
#     for filename in filenames_filtered:
#         kb = int(math.ceil(os.stat(filename).st_size / 1024))
#         if kb > maxkb:
#             print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
#             retv = 1
# 
#     return retv
# 
# Path: pre_commit_hooks/check_added_large_files.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         'filenames', nargs='*',
#         help='Filenames pre-commit believes are changed.',
#     )
#     parser.add_argument(
#         '--enforce-all', action='store_true',
#         help='Enforce all files are checked, not just staged files.',
#     )
#     parser.add_argument(
#         '--maxkb', type=int, default=500,
#         help='Maximum allowable KB for added files',
#     )
#     args = parser.parse_args(argv)
# 
#     return find_large_added_files(
#         args.filenames,
#         args.maxkb,
#         enforce_all=args.enforce_all,
#     )
# 
# Path: pre_commit_hooks/util.py
# def cmd_output(*cmd: str, retcode: int | None = 0, **kwargs: Any) -> str:
#     kwargs.setdefault('stdout', subprocess.PIPE)
#     kwargs.setdefault('stderr', subprocess.PIPE)
#     proc = subprocess.Popen(cmd, **kwargs)
#     stdout, stderr = proc.communicate()
#     stdout = stdout.decode()
#     if retcode is not None and proc.returncode != retcode:
#         raise CalledProcessError(cmd, retcode, proc.returncode, stdout, stderr)
#     return stdout
# 
# Path: testing/util.py
# def git_commit(*args, **kwargs):
#     cmd = ('git', 'commit', '--no-gpg-sign', '--no-verify', '--no-edit', *args)
#     subprocess.check_call(cmd, **kwargs)


# Path: tests/check_added_large_files_test.py
import shutil
import pytest
from pre_commit_hooks.check_added_large_files import find_large_added_files
from pre_commit_hooks.check_added_large_files import main
from pre_commit_hooks.util import cmd_output
from testing.util import git_commit

from __future__ import annotations





def test_nothing_added(temp_git_dir):
    with temp_git_dir.as_cwd():
        assert find_large_added_files(['f.py'], 0) == 0


def test_adding_something(temp_git_dir):
    with temp_git_dir.as_cwd():
        temp_git_dir.join('f.py').write("print('hello world')")

        cmd_output('git', 'add', 'f.py')