From 4a720e9abdee66d847c65853ea937bbd0e9e49c4 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 13 Sep 2022 00:25:57 +0200 Subject: [PATCH] move item related test to item testing module --- src/borg/testsuite/archiver/__init__.py | 20 +------------------- src/borg/testsuite/item.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/borg/testsuite/archiver/__init__.py b/src/borg/testsuite/archiver/__init__.py index f5a915efd..98950a750 100644 --- a/src/borg/testsuite/archiver/__init__.py +++ b/src/borg/testsuite/archiver/__init__.py @@ -35,7 +35,7 @@ from ...helpers import flags_noatime, flags_normal from ...manifest import Manifest, MandatoryFeatureUnsupported from ...patterns import IECommand, PatternMatcher, parse_pattern -from ...item import Item, chunks_contents_equal +from ...item import Item from ...logger import setup_logging from ...remote import RemoteRepository, PathNotAllowed from ...repository import Repository @@ -2187,24 +2187,6 @@ def test_old_version_interfered(self): assert "Cache integrity data not available: old Borg version modified the cache." in out -def test_chunk_content_equal(): - def ccc(a, b): - chunks_a = [data for data in a] - chunks_b = [data for data in b] - compare1 = chunks_contents_equal(iter(chunks_a), iter(chunks_b)) - compare2 = chunks_contents_equal(iter(chunks_b), iter(chunks_a)) - assert compare1 == compare2 - return compare1 - - assert ccc([b"1234", b"567A", b"bC"], [b"1", b"23", b"4567A", b"b", b"C"]) - # one iterator exhausted before the other - assert not ccc([b"12345"], [b"1234", b"56"]) - # content mismatch - assert not ccc([b"1234", b"65"], [b"1234", b"56"]) - # first is the prefix of second - assert not ccc([b"1234", b"56"], [b"1234", b"565"]) - - class TestBuildFilter: def test_basic(self): matcher = PatternMatcher() diff --git a/src/borg/testsuite/item.py b/src/borg/testsuite/item.py index e7cb9b2ac..d7e56be89 100644 --- a/src/borg/testsuite/item.py +++ b/src/borg/testsuite/item.py @@ -1,7 +1,7 @@ import pytest from ..cache import ChunkListEntry -from ..item import Item +from ..item import Item, chunks_contents_equal from ..helpers import StableDict from ..helpers.msgpack import Timestamp @@ -156,3 +156,21 @@ def test_item_file_size_no_chunks(): def test_item_optr(): item = Item() assert Item.from_optr(item.to_optr()) is item + + +def test_chunk_content_equal(): + def ccc(a, b): + chunks_a = [data for data in a] + chunks_b = [data for data in b] + compare1 = chunks_contents_equal(iter(chunks_a), iter(chunks_b)) + compare2 = chunks_contents_equal(iter(chunks_b), iter(chunks_a)) + assert compare1 == compare2 + return compare1 + + assert ccc([b"1234", b"567A", b"bC"], [b"1", b"23", b"4567A", b"b", b"C"]) + # one iterator exhausted before the other + assert not ccc([b"12345"], [b"1234", b"56"]) + # content mismatch + assert not ccc([b"1234", b"65"], [b"1234", b"56"]) + # first is the prefix of second + assert not ccc([b"1234", b"56"], [b"1234", b"565"])