diff options
author | Marian Beermann <public@enkore.de> | 2016-08-09 20:49:56 +0200 |
---|---|---|
committer | Marian Beermann <public@enkore.de> | 2016-08-21 01:09:21 +0200 |
commit | 4d214e2503bc28f4b75b89288935f8fecf7cda4e (patch) | |
tree | 3f0be35596888c51a102e5ad8ad8596e058f3c9c /src | |
parent | 5924915d3579e38a8f8c86b16f427dd32d1f206f (diff) |
Simplify and test Item.file_size
Diffstat (limited to 'src')
-rw-r--r-- | src/borg/item.py | 5 | ||||
-rw-r--r-- | src/borg/testsuite/item.py | 14 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/borg/item.py b/src/borg/item.py index b97b470f2..0bc336239 100644 --- a/src/borg/item.py +++ b/src/borg/item.py @@ -160,10 +160,7 @@ class Item(PropDict): def file_size(self): if 'chunks' not in self: return 0 - total_size = 0 - for chunk_id, size, csize in self.chunks: - total_size += size - return total_size + return sum(chunk.size for chunk in self.chunks) class EncryptedKey(PropDict): diff --git a/src/borg/testsuite/item.py b/src/borg/testsuite/item.py index b0b7569e3..fc60e91df 100644 --- a/src/borg/testsuite/item.py +++ b/src/borg/testsuite/item.py @@ -1,5 +1,6 @@ import pytest +from ..cache import ChunkListEntry from ..item import Item from ..helpers import StableDict @@ -145,3 +146,16 @@ def test_unknown_property(): item = Item() with pytest.raises(AttributeError): item.unknown_attribute = None + + +def test_item_file_size(): + item = Item(chunks=[ + ChunkListEntry(csize=1, size=1000, id=None), + ChunkListEntry(csize=1, size=2000, id=None), + ]) + assert item.file_size() == 3000 + + +def test_item_file_size_no_chunks(): + item = Item() + assert item.file_size() == 0 |