# 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
from diffoscope.config import Config
from diffoscope.comparators.tar import TarFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.nonexisting import assert_non_existing
def differences(tar1, tar2):
    return tar1.compare(tar2).details

def test_listing(differences):
    expected_diff = get_data('tar_listing_expected_diff')
    assert differences[0].unified_diff == expected_diff

def test_symlinks(differences):
    assert differences[2].source1 == 'dir/link'
    assert differences[2].source2 == 'dir/link'
    assert differences[2].comment == 'symlink'
    expected_diff = get_data('symlink_expected_diff')
    assert differences[2].unified_diff == expected_diff

def test_text_file(differences):
    assert differences[1].source1 == 'dir/text'
    assert differences[1].source2 == 'dir/text'
    expected_diff = get_data('text_ascii_expected_diff')
    assert differences[1].unified_diff == expected_diff

def test_compare_non_existing(monkeypatch, tar1):
    assert_non_existing(monkeypatch, tar1)

no_permissions_tar = load_fixture('no-perms.tar')

# Reported as Debian #797164. This is a good way to notice if we unpack directories
# as we won't be able to remove files in one if we don't have write permissions.
def test_no_permissions_dir_in_tarball(monkeypatch, no_permissions_tar):
    # We want to make sure OSError is not raised.
    # Comparing with non-existing file makes it easy to make sure all files are unpacked

# 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_tar.py
import pytest
from diffoscope.config import Config
from diffoscope.comparators.tar import TarFile
from diffoscope.comparators.missing_file import MissingFile
from utils.data import load_fixture, get_data
from utils.nonexisting import assert_non_existing

def differences(tar1, tar2):
    return tar1.compare(tar2).details

def test_listing(differences):
    expected_diff = get_data('tar_listing_expected_diff')
    assert differences[0].unified_diff == expected_diff

def test_symlinks(differences):
    assert differences[2].source1 == 'dir/link'
    assert differences[2].source2 == 'dir/link'
    assert differences[2].comment == 'symlink'
    expected_diff = get_data('symlink_expected_diff')
    assert differences[2].unified_diff == expected_diff

def test_text_file(differences):
    assert differences[1].source1 == 'dir/text'
    assert differences[1].source2 == 'dir/text'
    expected_diff = get_data('text_ascii_expected_diff')
    assert differences[1].unified_diff == expected_diff

def test_compare_non_existing(monkeypatch, tar1):
    assert_non_existing(monkeypatch, tar1)

no_permissions_tar = load_fixture('no-perms.tar')

# Reported as Debian #797164. This is a good way to notice if we unpack directories
# as we won't be able to remove files in one if we don't have write permissions.
def test_no_permissions_dir_in_tarball(monkeypatch, no_permissions_tar):
    # We want to make sure OSError is not raised.
    # Comparing with non-existing file makes it easy to make sure all files are unpacked

    monkeypatch.setattr(Config(), 'new_file', True)