|
8 | 8 | from unittest import TestCase |
9 | 9 | from unittest.mock import patch |
10 | 10 |
|
11 | | -from ..tree_diff import main |
| 11 | +from parameterized import parameterized |
| 12 | + |
| 13 | +from ..tree_diff import (_replace_special_keywords_for_ebuild, enrich_config, main, |
| 14 | + parse_command_line) |
| 15 | + |
| 16 | + |
| 17 | +class ReplaceSpecialKeywordsTest(TestCase): |
| 18 | + @parameterized.expand([ |
| 19 | + ('no ops', {'one', '~two'}, {'three', '~four'}, {'one', '~two'}), |
| 20 | + ('star op', {'one', '~two', '*'}, {'three', '~four'}, {'one', '~two', 'three'}), |
| 21 | + ('tilde star op', {'one', '~two', '~*'}, {'three', '~four'}, {'one', '~two', '~four'}), |
| 22 | + ('double star op', {'one', '~two', '**'}, {'three', |
| 23 | + '~four'}, {'one', '~two', 'three', '~four'}), |
| 24 | + ('start op + tilde star op', {'one', '~two', '*', |
| 25 | + '~*'}, {'three', '~four'}, {'one', '~two', 'three', |
| 26 | + '~four'}), |
| 27 | + ]) |
| 28 | + def test(self, _, accept_keywords, ebuild_keywords, expected_effective_keywords): |
| 29 | + actual_effective_keywords = _replace_special_keywords_for_ebuild( |
| 30 | + accept_keywords, ebuild_keywords) |
| 31 | + self.assertEqual(actual_effective_keywords, expected_effective_keywords) |
| 32 | + |
| 33 | + |
| 34 | +class EnrichConfigTest(TestCase): |
| 35 | + magic_keywords = 'one two ~*' |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def _fake_subprocess_check_output(cls, argv): |
| 39 | + if argv == ['portageq', 'envvar', 'ACCEPT_KEYWORDS']: |
| 40 | + stdout = cls.magic_keywords |
| 41 | + else: |
| 42 | + stdout = f'Hello from: {" ".join(argv)}' |
| 43 | + return (stdout + '\n').encode('ascii') |
| 44 | + |
| 45 | + def test_given__empty(self): |
| 46 | + config = parse_command_line(['gentoo-tree-diff', '--keywords', '', 'dir1', 'dir2']) |
| 47 | + with self.assertRaises(ValueError): |
| 48 | + enrich_config(config) |
| 49 | + |
| 50 | + def test_given__not_empty(self): |
| 51 | + config = parse_command_line( |
| 52 | + ['gentoo-tree-diff', '--keywords', 'one ~two *', 'dir1', 'dir2']) |
| 53 | + enrich_config(config) |
| 54 | + self.assertEqual(config.keywords, {'one', 'two', '~two', '*'}) |
| 55 | + |
| 56 | + def test_not_given__auto_detection(self): |
| 57 | + config = parse_command_line(['gentoo-tree-diff', 'dir1', 'dir2']) |
| 58 | + with patch('subprocess.check_output', self._fake_subprocess_check_output): |
| 59 | + enrich_config(config) |
| 60 | + self.assertEqual(config.keywords, {'one', 'two', '~*'}) |
12 | 61 |
|
13 | 62 |
|
14 | 63 | class MainTest(TestCase): |
|
0 commit comments