Skip to content

Commit

Permalink
Add support for stats --mode flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Mar 22, 2021
1 parent f2376be commit 0b3b744
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion e2e/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def emit(self, record):
logger.fatal('Expected to restored file to contain %s (got %s)',
RESTORED_DATA_EXPECTED, RESTORED_DATA_ACTUAL)

stats = restic.stats()
stats = restic.stats(mode='blobs-per-file')
logger.info('repo stats: %s', stats)
if stats['total_size'] != len(RESTORED_DATA_EXPECTED):
logger.fatal('Expected to total size of %d (got %d)',
Expand Down
4 changes: 2 additions & 2 deletions restic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def self_update():
return internal_self_update.run(_make_base_command())


def stats():
return internal_stats.run(_make_base_command())
def stats(*args, **kwargs):
return internal_stats.run(_make_base_command(), *args, **kwargs)


def unlock():
Expand Down
6 changes: 5 additions & 1 deletion restic/internal/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from restic.internal import command_executor


def run(restic_base_command):
def run(restic_base_command, mode=None):
cmd = restic_base_command + ['stats']

if mode:
cmd.extend(['--mode', mode])

return json.loads(command_executor.execute(cmd))
16 changes: 15 additions & 1 deletion restic/internal/stats_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,19 @@ def test_stats(self, mock_execute):
"total_file_count": 3
}
"""
restic.stats()

self.assertEqual({
'total_size': 20,
'total_file_count': 3
}, restic.stats())

mock_execute.assert_called_with(['restic', '--json', 'stats'])

@mock.patch.object(stats.command_executor, 'execute')
def test_stats_with_mode(self, mock_execute):
mock_execute.return_value = '{}'

restic.stats(mode='blobs-per-file')

mock_execute.assert_called_with(
['restic', '--json', 'stats', '--mode', 'blobs-per-file'])

0 comments on commit 0b3b744

Please sign in to comment.