blob: 5166b6c4a42f34f676887b321c2bcecdd57c4350 [file] [log] [blame]
Max Rasskazova8db7a92015-05-30 02:23:43 +03001#-*- coding: utf-8 -*-
2
3import rsync_url
4import unittest
5import yaml
6
7
8class TestRsyncUrl(unittest.TestCase):
9
10 def exact_match_num(self, remote, expected_result):
11 url = rsync_url.RsyncUrl(remote)
12 matching_regexps = url._get_all_matching_regexps()
13 self.assertEqual(len(matching_regexps), expected_result)
14
15 def classed(self, remote, expected_result):
16 url = rsync_url.RsyncUrl(remote)
17 self.assertEqual(url.url_type, expected_result)
18
19 def parsed(self, remote, expected_result):
20 url = rsync_url.RsyncUrl(remote)
21 self.assertEqual(
22 [url.user, url.host, url.port, url.path],
23 expected_result
24 )
25
26
27testdata = yaml.load(open('test_rsync_url.yaml'))
28
29index = 1
30for remote, tests in testdata.items():
31
32 for test, expected in tests.items():
33
34 print index, test, expected
35
36 def test_function(self, test=test,
37 remote=remote, expected_result=expected):
38 getattr(self, test)(remote, expected_result)
39
40 test_function.__name__ = \
41 'test_{}_{}_{}'.format(index, tests['classed'], test)
42 test_function.__doc__ = test_function.__name__
43 setattr(TestRsyncUrl, test_function.__name__, test_function)
44 del test_function
45
46 index += 1
47
48
49if __name__ == '__main__':
50 unittest.main()