mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 17:57:59 +00:00
Simplify and test Item.file_size
This commit is contained in:
parent
5924915d35
commit
4d214e2503
2 changed files with 15 additions and 4 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue