Преглед изворни кода

Simplify and test Item.file_size

Marian Beermann пре 8 година
родитељ
комит
4d214e2503
2 измењених фајлова са 15 додато и 4 уклоњено
  1. 1 4
      src/borg/item.py
  2. 14 0
      src/borg/testsuite/item.py

+ 1 - 4
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):

+ 14 - 0
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