Max Rasskazov | a8db7a9 | 2015-05-30 02:23:43 +0300 | [diff] [blame] | 1 | #-*- coding: utf-8 -*- |
| 2 | |
| 3 | import rsync_url |
| 4 | import unittest |
| 5 | import yaml |
| 6 | |
| 7 | |
| 8 | class 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 | |
| 27 | testdata = yaml.load(open('test_rsync_url.yaml')) |
| 28 | |
| 29 | index = 1 |
| 30 | for 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 | |
| 49 | if __name__ == '__main__': |
| 50 | unittest.main() |