From 28d0a9ce843e3461b45fbbfd1c8cc1a2b84ef82e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 16 Oct 2015 01:38:53 -0400 Subject: [PATCH] human-readable representation of stats --- borg/helpers.py | 6 ++++++ borg/testsuite/helpers.py | 2 ++ 2 files changed, 8 insertions(+) diff --git a/borg/helpers.py b/borg/helpers.py index 5a93bd182..b793ca492 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -168,6 +168,12 @@ def update(self, size, csize, unique): 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) diff --git a/borg/testsuite/helpers.py b/borg/testsuite/helpers.py index 37f6fcc4c..ac2cbacad 100644 --- a/borg/testsuite/helpers.py +++ b/borg/testsuite/helpers.py @@ -442,3 +442,5 @@ def test_stats_format(stats): """ 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__() == ''.format(id(stats))