-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathstats_test.py
74 lines (59 loc) · 2.07 KB
/
stats_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import unittest
from unittest import mock
import restic
from restic.internal import stats
class SelfUpdateTest(unittest.TestCase):
@mock.patch.object(stats.command_executor, 'execute')
def test_stats(self, mock_execute):
mock_execute.return_value = """{
"total_size": 20,
"total_file_count": 3
}
"""
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 = """{
"total_size": 20,
"total_file_count": 1,
"total_blob_count": 1
}
"""
self.assertEqual(
{
'total_size': 20,
'total_file_count': 1,
'total_blob_count': 1
}, restic.stats(mode='blobs-per-file'))
mock_execute.assert_called_with(
['restic', '--json', 'stats', '--mode', 'blobs-per-file'])
@mock.patch.object(stats.command_executor, 'execute')
def test_stats_with_tag(self, mock_execute):
mock_execute.return_value = """{
"total_size": 10,
"total_file_count": 2
}
"""
self.assertEqual({
'total_size': 10,
'total_file_count': 2
}, restic.stats(tags=['musician1']))
mock_execute.assert_called_with(
['restic', '--json', 'stats', '--tag', 'musician1'])
@mock.patch.object(stats.command_executor, 'execute')
def test_stats_with_host(self, mock_execute):
mock_execute.return_value = """{
"total_size": 10,
"total_file_count": 2
}
"""
self.assertEqual({
'total_size': 10,
'total_file_count': 2
}, restic.stats(host='myhost'))
mock_execute.assert_called_with(
['restic', '--json', 'stats', '--host', 'myhost'])