mirror of https://github.com/borgbackup/borg.git
Simplify and test Item.file_size
This commit is contained in:
parent
5924915d35
commit
4d214e2503
|
@ -160,10 +160,7 @@ class Item(PropDict):
|
||||||
def file_size(self):
|
def file_size(self):
|
||||||
if 'chunks' not in self:
|
if 'chunks' not in self:
|
||||||
return 0
|
return 0
|
||||||
total_size = 0
|
return sum(chunk.size for chunk in self.chunks)
|
||||||
for chunk_id, size, csize in self.chunks:
|
|
||||||
total_size += size
|
|
||||||
return total_size
|
|
||||||
|
|
||||||
|
|
||||||
class EncryptedKey(PropDict):
|
class EncryptedKey(PropDict):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from ..cache import ChunkListEntry
|
||||||
from ..item import Item
|
from ..item import Item
|
||||||
from ..helpers import StableDict
|
from ..helpers import StableDict
|
||||||
|
|
||||||
|
@ -145,3 +146,16 @@ def test_unknown_property():
|
||||||
item = Item()
|
item = Item()
|
||||||
with pytest.raises(AttributeError):
|
with pytest.raises(AttributeError):
|
||||||
item.unknown_attribute = None
|
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 New Issue