# Path: pre_commit_hooks/pretty_format_json.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '--autofix',
#         action='store_true',
#         dest='autofix',
#         help='Automatically fixes encountered not-pretty-formatted files',
#     )
#     parser.add_argument(
#         '--indent',
#         type=parse_num_to_int,
#         default='2',
#         help=(
#             'The number of indent spaces or a string to be used as delimiter'
#             ' for indentation level e.g. 4 or "\t" (Default: 2)'
#         ),
#     )
#     parser.add_argument(
#         '--no-ensure-ascii',
#         action='store_true',
#         dest='no_ensure_ascii',
#         default=False,
#         help=(
#             'Do NOT convert non-ASCII characters to Unicode escape sequences '
#             '(\\uXXXX)'
#         ),
#     )
#     parser.add_argument(
#         '--no-sort-keys',
#         action='store_true',
#         dest='no_sort_keys',
#         default=False,
#         help='Keep JSON nodes in the same order',
#     )
#     parser.add_argument(
#         '--top-keys',
#         type=parse_topkeys,
#         dest='top_keys',
#         default=[],
#         help='Ordered list of keys to keep at the top of JSON hashes',
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     status = 0
# 
#     for json_file in args.filenames:
#         with open(json_file, encoding='UTF-8') as f:
#             contents = f.read()
# 
#         try:
#             pretty_contents = _get_pretty_format(
#                 contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
#                 sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
#             )
#         except ValueError:
#             print(
#                 f'Input File {json_file} is not a valid JSON, consider using '
#                 f'check-json',
#             )
#             return 1
# 
#         if contents != pretty_contents:
#             if args.autofix:
#                 _autofix(json_file, pretty_contents)
#             else:
#                 diff_output = get_diff(contents, pretty_contents, json_file)
#                 sys.stdout.buffer.write(diff_output.encode())
# 
#             status = 1
# 
#     return status
# 
# Path: pre_commit_hooks/pretty_format_json.py
# def parse_num_to_int(s: str) -> int | str:
#     """Convert string numbers to int, leaving strings as is."""
#     try:
#         return int(s)
#     except ValueError:
#         return s
# 
# Path: testing/util.py
# def get_resource_path(path):
#     return os.path.join(TESTING_DIR, 'resources', path)


import os
import shutil
import pytest
from pre_commit_hooks.pretty_format_json import main
from pre_commit_hooks.pretty_format_json import parse_num_to_int
from testing.util import get_resource_path
from __future__ import annotations





def test_parse_num_to_int():
    assert parse_num_to_int('0') == 0
    assert parse_num_to_int('2') == 2
    assert parse_num_to_int('\t') == '\t'
    assert parse_num_to_int('  ') == '  '


@pytest.mark.parametrize(
    ('filename', 'expected_retval'), (
        ('not_pretty_formatted_json.json', 1),
        ('unsorted_pretty_formatted_json.json', 1),
        ('non_ascii_pretty_formatted_json.json', 1),
        ('pretty_formatted_json.json', 0),
    ),
)
def test_main(filename, expected_retval):

# Path: pre_commit_hooks/pretty_format_json.py
# def main(argv: Sequence[str] | None = None) -> int:
#     parser = argparse.ArgumentParser()
#     parser.add_argument(
#         '--autofix',
#         action='store_true',
#         dest='autofix',
#         help='Automatically fixes encountered not-pretty-formatted files',
#     )
#     parser.add_argument(
#         '--indent',
#         type=parse_num_to_int,
#         default='2',
#         help=(
#             'The number of indent spaces or a string to be used as delimiter'
#             ' for indentation level e.g. 4 or "\t" (Default: 2)'
#         ),
#     )
#     parser.add_argument(
#         '--no-ensure-ascii',
#         action='store_true',
#         dest='no_ensure_ascii',
#         default=False,
#         help=(
#             'Do NOT convert non-ASCII characters to Unicode escape sequences '
#             '(\\uXXXX)'
#         ),
#     )
#     parser.add_argument(
#         '--no-sort-keys',
#         action='store_true',
#         dest='no_sort_keys',
#         default=False,
#         help='Keep JSON nodes in the same order',
#     )
#     parser.add_argument(
#         '--top-keys',
#         type=parse_topkeys,
#         dest='top_keys',
#         default=[],
#         help='Ordered list of keys to keep at the top of JSON hashes',
#     )
#     parser.add_argument('filenames', nargs='*', help='Filenames to fix')
#     args = parser.parse_args(argv)
# 
#     status = 0
# 
#     for json_file in args.filenames:
#         with open(json_file, encoding='UTF-8') as f:
#             contents = f.read()
# 
#         try:
#             pretty_contents = _get_pretty_format(
#                 contents, args.indent, ensure_ascii=not args.no_ensure_ascii,
#                 sort_keys=not args.no_sort_keys, top_keys=args.top_keys,
#             )
#         except ValueError:
#             print(
#                 f'Input File {json_file} is not a valid JSON, consider using '
#                 f'check-json',
#             )
#             return 1
# 
#         if contents != pretty_contents:
#             if args.autofix:
#                 _autofix(json_file, pretty_contents)
#             else:
#                 diff_output = get_diff(contents, pretty_contents, json_file)
#                 sys.stdout.buffer.write(diff_output.encode())
# 
#             status = 1
# 
#     return status
# 
# Path: pre_commit_hooks/pretty_format_json.py
# def parse_num_to_int(s: str) -> int | str:
#     """Convert string numbers to int, leaving strings as is."""
#     try:
#         return int(s)
#     except ValueError:
#         return s
# 
# Path: testing/util.py
# def get_resource_path(path):
#     return os.path.join(TESTING_DIR, 'resources', path)


# Path: tests/pretty_format_json_test.py
import os
import shutil
import pytest
from pre_commit_hooks.pretty_format_json import main
from pre_commit_hooks.pretty_format_json import parse_num_to_int
from testing.util import get_resource_path

from __future__ import annotations





def test_parse_num_to_int():
    assert parse_num_to_int('0') == 0
    assert parse_num_to_int('2') == 2
    assert parse_num_to_int('\t') == '\t'
    assert parse_num_to_int('  ') == '  '


@pytest.mark.parametrize(
    ('filename', 'expected_retval'), (
        ('not_pretty_formatted_json.json', 1),
        ('unsorted_pretty_formatted_json.json', 1),
        ('non_ascii_pretty_formatted_json.json', 1),
        ('pretty_formatted_json.json', 0),
    ),
)
def test_main(filename, expected_retval):

    ret = main([get_resource_path(filename)])