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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
import os
import unittest
import json
import jc.parsers.rsync
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
class MyTests(unittest.TestCase):
# input
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/rsync-i.out'), 'r', encoding='utf-8') as f:
generic_rsync_i = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-ivvv.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_ivvv = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_ivvv = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-ivvv-nochange.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_ivvv_nochange = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv-nochange.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_ivvv_nochange = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-logfile.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_logfile = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-v-logfile.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_v_logfile = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vv-logfile.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vv_logfile = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vvv-logfile.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vvv_logfile = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vvv-logfile-nochange.out'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vvv_logfile_nochange = f.read()
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv-logfile-nochange.out'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_i_vvv_logfile_nochange = f.read()
# output
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/rsync-i.json'), 'r', encoding='utf-8') as f:
generic_rsync_i_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-ivvv.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_ivvv_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_ivvv_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-ivvv-nochange.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_ivvv_nochange_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv-nochange.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_ivvv_nochange_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-logfile.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_logfile_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-v-logfile.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_v_logfile_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vv-logfile.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vv_logfile_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vvv-logfile.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vvv_logfile_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/rsync-i-vvv-logfile-nochange.json'), 'r', encoding='utf-8') as f:
centos_7_7_rsync_i_vvv_logfile_nochange_json = json.loads(f.read())
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/rsync-i-vvv-logfile-nochange.json'), 'r', encoding='utf-8') as f:
osx_10_14_6_rsync_i_vvv_logfile_nochange_json = json.loads(f.read())
def test_rsync_nodata(self):
"""
Test 'rsync' with no data
"""
self.assertEqual(jc.parsers.rsync.parse('', quiet=True), [])
def test_rsync_centos_7_7_rsync_i(self):
"""
Test 'rsync -i' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i, quiet=True), self.centos_7_7_rsync_i_json)
def test_rsync_generic_rsync_i(self):
"""
Test 'rsync -i'
"""
self.assertEqual(jc.parsers.rsync.parse(self.generic_rsync_i, quiet=True), self.generic_rsync_i_json)
def test_rsync_centos_7_7_rsync_ivvv(self):
"""
Test 'rsync -ivvv' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_ivvv, quiet=True), self.centos_7_7_rsync_ivvv_json)
def test_rsync_osx_10_14_6_rsync_ivvv(self):
"""
Test 'rsync -ivvv' on OSX 10.14.6
"""
self.assertEqual(jc.parsers.rsync.parse(self.osx_10_14_6_rsync_ivvv, quiet=True), self.osx_10_14_6_rsync_ivvv_json)
def test_rsync_osx_10_14_6_rsync_ivvv_nochange(self):
"""
Test 'rsync -ivvv' on OSX 10.14.6 with no file changes
"""
self.assertEqual(jc.parsers.rsync.parse(self.osx_10_14_6_rsync_ivvv_nochange, quiet=True), self.osx_10_14_6_rsync_ivvv_nochange_json)
def test_rsync_centos_7_7_rsync_ivvv_nochange(self):
"""
Test 'rsync -ivvv' on Centos 7.7 with no file changes
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_ivvv_nochange, quiet=True), self.centos_7_7_rsync_ivvv_nochange_json)
def test_rsync_centos_7_7_rsync_i_logfile(self):
"""
Test 'rsync -i --log-file=xxx' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i_logfile, quiet=True), self.centos_7_7_rsync_i_logfile_json)
def test_rsync_centos_7_7_rsync_i_v_logfile(self):
"""
Test 'rsync -iv --log-file=xxx' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i_v_logfile, quiet=True), self.centos_7_7_rsync_i_v_logfile_json)
def test_rsync_centos_7_7_rsync_i_vv_logfile(self):
"""
Test 'rsync -ivv --log-file=xxx' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i_vv_logfile, quiet=True), self.centos_7_7_rsync_i_vv_logfile_json)
def test_rsync_centos_7_7_rsync_i_vvv_logfile(self):
"""
Test 'rsync -ivvv --log-file=xxx' on Centos 7.7
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i_vvv_logfile, quiet=True), self.centos_7_7_rsync_i_vvv_logfile_json)
def test_rsync_centos_7_7_rsync_i_vvv_logfile_nochange(self):
"""
Test 'rsync -ivvv --log-file=xxx' on Centos 7.7 with no file changes
"""
self.assertEqual(jc.parsers.rsync.parse(self.centos_7_7_rsync_i_vvv_logfile_nochange, quiet=True), self.centos_7_7_rsync_i_vvv_logfile_nochange_json)
def test_rsync_osx_10_14_6_rsync_i_vvv_logfile_nochange(self):
"""
Test 'rsync -ivvv --log-file=xxx' on OSX 10.14.6 with no file changes
"""
self.assertEqual(jc.parsers.rsync.parse(self.osx_10_14_6_rsync_i_vvv_logfile_nochange, quiet=True), self.osx_10_14_6_rsync_i_vvv_logfile_nochange_json)
def test_rsync_simple_summary(self):
"""
Test 'rsync avh' output with a simple summary
"""
data = '''sending incremental file list
sent 8.71M bytes received 29.88K bytes 10.99K bytes/sec
total size is 221.79G speedup is 25,388.23
'''
expected = [{"summary":{"sent":8710000,"received":29880,"bytes_sec":10990.0,"total_size":221790000000,"speedup":25388.23},"files":[]}]
self.assertEqual(jc.parsers.rsync.parse(data, quiet=True), expected)
if __name__ == '__main__':
unittest.main()
|