Skip to content

Commit 9e80850

Browse files
improve tests
- remove redundant tests - improve comments / name - improve comparison to use less-than
1 parent 9b0cb70 commit 9e80850

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

src/borg/testsuite/archiver.py

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,43 +1617,12 @@ def test_info(self):
16171617
info_archive = self.cmd('info', '--first', '1', self.repository_location)
16181618
assert 'Archive name: test\n' in info_archive
16191619

1620-
def test_info_matches_create_deduplicated_size(self):
1621-
# Create two identical files to ensure intra-archive deduplication happens,
1622-
# so the deduplicated size is visibly different from compressed size.
1623-
data = b'X' * (1024 * 80)
1624-
self.create_regular_file('file1', contents=data)
1625-
self.create_regular_file('file2', contents=data)
1626-
self.cmd('init', '--encryption=repokey', self.repository_location)
1627-
create_json = json.loads(self.cmd('create', '--json', self.repository_location + '::test', 'input'))
1628-
info_json = json.loads(self.cmd('info', '--json', self.repository_location + '::test'))
1629-
1630-
# Compare deduplicated size of "This archive" between create and info.
1631-
dedup_create = create_json['archive']['stats']['deduplicated_size']
1632-
assert len(info_json['archives']) == 1
1633-
dedup_info = info_json['archives'][0]['stats']['deduplicated_size']
1634-
assert dedup_create == dedup_info
1635-
1636-
def test_info_matches_create_all_archives_deduplicated_size(self):
1637-
# Verify that the "All archives" deduplicated size reported by `borg create --json`
1638-
# matches the one reported by `borg info --json <repo>`.
1639-
data = b'Y' * (1024 * 80)
1640-
self.create_regular_file('file1', contents=data)
1641-
self.create_regular_file('file2', contents=data)
1642-
self.cmd('init', '--encryption=repokey', self.repository_location)
1643-
# Create two archives so that the "All archives" section is meaningful and stable.
1644-
self.cmd('create', '--json', self.repository_location + '::a1', 'input')
1645-
create_json2 = json.loads(self.cmd('create', '--json', self.repository_location + '::a2', 'input'))
1646-
info_repo_json = json.loads(self.cmd('info', '--json', self.repository_location))
1647-
1648-
# In JSON, the repository-wide deduplicated size corresponds to cache.stats.unique_size.
1649-
dedup_create_all = create_json2['cache']['stats']['unique_size']
1650-
dedup_info_all = info_repo_json['cache']['stats']['unique_size']
1651-
assert dedup_create_all == dedup_info_all
1652-
1653-
def test_single_archive_all_equals_this_info_and_create(self):
1654-
# With a single archive in the repository, the deduplicated size for
1655-
# "This archive" and "All archives" should be identical, both in
1656-
# `borg create --json` and in `borg info --json` (repo and archive views).
1620+
def test_info_and_create_stats(self):
1621+
# "This archive" deduplicated size should match between `borg info` and `borg create --stats`.
1622+
# "All archives" deduplicated size should match between `borg info` and `borg create --stats`.
1623+
# However, even if there is only one archive in the repo, the deduplicated-size stats for
1624+
# "All archives" do not match those for "This archive" because metadata is accounted for at the
1625+
# repository level ("All archives"), but not for an individual archive ("This archive").
16571626
data = b'Z' * (1024 * 80)
16581627
self.create_regular_file('file1', contents=data)
16591628
self.create_regular_file('file2', contents=data)
@@ -1676,8 +1645,8 @@ def test_single_archive_all_equals_this_info_and_create(self):
16761645
assert dedup_all_create == dedup_all_info
16771646
# accounting for "all archives" includes metadata chunks, for "this archive" it does not,
16781647
# thus a mismatch is expected.
1679-
assert dedup_this_create != dedup_all_create
1680-
assert dedup_this_info != dedup_all_info
1648+
assert dedup_this_create < dedup_all_create
1649+
assert dedup_this_info < dedup_all_info
16811650

16821651
def test_info_json(self):
16831652
self.create_regular_file('file1', size=1024 * 80)

0 commit comments

Comments
 (0)