# Path: diffoscope/config.py
# class Config(object):
#     max_diff_block_lines = 256
#     max_diff_block_lines_parent = 50
#     max_diff_block_lines_saved = float("inf")
#     # html-dir output uses ratio * max-diff-block-lines as its limit
#     max_diff_block_lines_html_dir_ratio = 4
#     # GNU diff cannot process arbitrary large files :(
#     max_diff_input_lines = 2 ** 20
#     max_report_size = 2000 * 2 ** 10 # 2000 kB
#     max_text_report_size = 0
#     max_report_child_size = 500 * 2 ** 10
#     new_file = False
#     fuzzy_threshold = 60
#     enforce_constraints = True
#     excludes = ()
# 
#     _singleton = {}
# 
#     def __init__(self):
#         self.__dict__ = self._singleton
# 
#     def __setattr__(self, k, v):
#         super(Config, self).__setattr__(k, v)
# 
#         if self.enforce_constraints:
#             self.check_constraints()
# 
#     def check_constraints(self):
#         if self.max_diff_block_lines < self.max_diff_block_lines_parent:  # noqa
#             raise ValueError("max_diff_block_lines ({0.max_diff_block_lines}) "
#                 "cannot be smaller than max_diff_block_lines_parent "
#                 "({0.max_diff_block_lines_parent})".format(self),
#             )
# 
#         max_ = self.max_diff_block_lines_html_dir_ratio * \
#             self.max_diff_block_lines
#         if self.max_diff_block_lines_saved < max_:  # noqa
#             raise ValueError("max_diff_block_lines_saved "
#                 "({0.max_diff_block_lines_saved}) cannot be smaller than "
#                 "{0.max_diff_block_lines_html_dir_ratio} * "
#                 "max_diff_block_lines ({1})".format(self, max_),
#             )


import pytest
import subprocess
from diffoscope.config import Config
from diffoscope.comparators.dex import DexFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from test_java import javap_version
def enjarify_version():
    # Module enjarify.typeinference appeared in enjarify 1.0.3.  We use a call
    # directly to the python3 binary over importing with this module to escape
    # virtualenvs and to match the behaviour of enjarify(1).
    if subprocess.call(
        ('python3', '-c', 'import enjarify.typeinference'),
        stderr=subprocess.PIPE,
    ) == 0:
        return '1.0.3'
    return '1.0.2'

def test_identification(dex1):
    assert isinstance(dex1, DexFile)

def test_no_differences(dex1):
    difference = dex1.compare(dex1)
    assert difference is None

@pytest.fixture
def differences(dex1, dex2):
    return dex1.compare(dex2).details

@skip_unless_tools_exist('enjarify', 'zipinfo', 'javap')
@skip_unless_tool_is_at_least('javap', javap_version, '1.8')
@skip_unless_tool_is_at_least('enjarify', enjarify_version, '1.0.3')
def test_differences(differences):
    assert differences[0].source1 == 'test1.jar'
    assert differences[0].source2 == 'test2.jar'
    zipinfo = differences[0].details[0]
    classdiff = differences[0].details[1]

# Path: diffoscope/config.py
# class Config(object):
#     max_diff_block_lines = 256
#     max_diff_block_lines_parent = 50
#     max_diff_block_lines_saved = float("inf")
#     # html-dir output uses ratio * max-diff-block-lines as its limit
#     max_diff_block_lines_html_dir_ratio = 4
#     # GNU diff cannot process arbitrary large files :(
#     max_diff_input_lines = 2 ** 20
#     max_report_size = 2000 * 2 ** 10 # 2000 kB
#     max_text_report_size = 0
#     max_report_child_size = 500 * 2 ** 10
#     new_file = False
#     fuzzy_threshold = 60
#     enforce_constraints = True
#     excludes = ()
# 
#     _singleton = {}
# 
#     def __init__(self):
#         self.__dict__ = self._singleton
# 
#     def __setattr__(self, k, v):
#         super(Config, self).__setattr__(k, v)
# 
#         if self.enforce_constraints:
#             self.check_constraints()
# 
#     def check_constraints(self):
#         if self.max_diff_block_lines < self.max_diff_block_lines_parent:  # noqa
#             raise ValueError("max_diff_block_lines ({0.max_diff_block_lines}) "
#                 "cannot be smaller than max_diff_block_lines_parent "
#                 "({0.max_diff_block_lines_parent})".format(self),
#             )
# 
#         max_ = self.max_diff_block_lines_html_dir_ratio * \
#             self.max_diff_block_lines
#         if self.max_diff_block_lines_saved < max_:  # noqa
#             raise ValueError("max_diff_block_lines_saved "
#                 "({0.max_diff_block_lines_saved}) cannot be smaller than "
#                 "{0.max_diff_block_lines_html_dir_ratio} * "
#                 "max_diff_block_lines ({1})".format(self, max_),
#             )


# Path: tests/comparators/test_dex.py
import pytest
import subprocess
from diffoscope.config import Config
from diffoscope.comparators.dex import DexFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
from test_java import javap_version

def enjarify_version():
    # Module enjarify.typeinference appeared in enjarify 1.0.3.  We use a call
    # directly to the python3 binary over importing with this module to escape
    # virtualenvs and to match the behaviour of enjarify(1).
    if subprocess.call(
        ('python3', '-c', 'import enjarify.typeinference'),
        stderr=subprocess.PIPE,
    ) == 0:
        return '1.0.3'
    return '1.0.2'

def test_identification(dex1):
    assert isinstance(dex1, DexFile)

def test_no_differences(dex1):
    difference = dex1.compare(dex1)
    assert difference is None

@pytest.fixture
def differences(dex1, dex2):
    return dex1.compare(dex2).details

@skip_unless_tools_exist('enjarify', 'zipinfo', 'javap')
@skip_unless_tool_is_at_least('javap', javap_version, '1.8')
@skip_unless_tool_is_at_least('enjarify', enjarify_version, '1.0.3')
def test_differences(differences):
    assert differences[0].source1 == 'test1.jar'
    assert differences[0].source2 == 'test2.jar'
    zipinfo = differences[0].details[0]
    classdiff = differences[0].details[1]

    assert zipinfo.source1 == 'zipinfo -v {}'