Kaynağa Gözat

human-readable representation of stats

Antoine Beaupré 9 yıl önce
ebeveyn
işleme
28d0a9ce84
2 değiştirilmiş dosya ile 8 ekleme ve 0 silme
  1. 6 0
      borg/helpers.py
  2. 2 0
      borg/testsuite/helpers.py

+ 6 - 0
borg/helpers.py

@@ -168,6 +168,12 @@ class Statistics:
     def __str__(self):
         return self.summary.format(stats=self, label='This archive:')
 
+    def __repr__(self):
+        fmt = "<{cls} object at {hash:#x} ({self.osize}, {self.csize}, {self.usize})>"
+        return fmt.format(cls=type(self).__name__,
+                          hash=id(self),
+                          self=self)
+
     @property
     def osize_fmt(self):
         return format_file_size(self.osize)

+ 2 - 0
borg/testsuite/helpers.py

@@ -442,3 +442,5 @@ This archive:                   10 B                 10 B                 10 B
 """
     s = "{0.osize_fmt}".format(stats)
     assert s == "10 B"
+    # kind of redundant, but id is variable so we can't match reliably
+    assert stats.__repr__() == '<Statistics object at {:#x} (10, 10, 10)>'.format(id(stats))