Devuan deployment of britney2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

82 lines
2.9 KiB

  1. import unittest
  2. from britney2 import Suite, Suites, SuiteClass
  3. from britney2.hints import HintParser, single_hint_taking_list_of_packages
  4. from britney2.migrationitem import MigrationItemFactory
  5. from . import HINTS_ALL, TEST_HINTER
  6. SUITES = Suites(
  7. Suite(SuiteClass.TARGET_SUITE, 'testing', "/somewhere/target", ''),
  8. [Suite(SuiteClass.PRIMARY_SOURCE_SUITE, 'unstable', "/somewhere/source", '')],
  9. )
  10. def new_hint_parser():
  11. mi_factory = MigrationItemFactory(SUITES)
  12. return HintParser(mi_factory)
  13. def parse_should_not_call_this_function(*args, **kwargs):
  14. raise AssertionError("Should not be called")
  15. class HintParsing(unittest.TestCase):
  16. def test_parse_invalid_hints(self):
  17. hint_parser = new_hint_parser()
  18. hint_parser.register_hint_type('min-10-arg', parse_should_not_call_this_function, min_args=10)
  19. hint_parser.register_hint_type('simple-hint', parse_should_not_call_this_function)
  20. tests = [
  21. {
  22. 'hint_text': 'min-10-arg foo bar',
  23. 'permissions': HINTS_ALL,
  24. 'error_message_contains': 'Needs at least 10 argument(s), got'
  25. },
  26. {
  27. 'hint_text': 'undefined-hint with some arguments',
  28. 'permissions': HINTS_ALL,
  29. 'error_message_contains': 'Unknown hint found in'
  30. },
  31. {
  32. 'hint_text': 'simple-hint foo/1.0',
  33. 'permissions': ['not-this-hint'],
  34. 'error_message_contains': 'not a part of the permitted hints for'
  35. },
  36. ]
  37. for test in tests:
  38. with self.assertLogs() as cm:
  39. hint_parser.parse_hints(TEST_HINTER, test['permissions'], 'test-parse-hint', [test['hint_text']])
  40. assert len(cm.output) == 1
  41. assert test['error_message_contains'] in cm.output[0]
  42. assert hint_parser.hints.is_empty
  43. def test_alias(self):
  44. hint_parser = new_hint_parser()
  45. hint_parser.register_hint_type('real-name',
  46. single_hint_taking_list_of_packages,
  47. aliases=['alias1', 'alias2']
  48. )
  49. hint_parser.parse_hints(TEST_HINTER,
  50. HINTS_ALL,
  51. 'test-parse-hint',
  52. [
  53. 'alias1 foo/1.0',
  54. 'alias2 bar/2.0',
  55. ])
  56. hints = hint_parser.hints
  57. # Aliased hints can be found by the real name
  58. assert hints.search(type='real-name', package='foo', version='1.0')
  59. assert hints.search(type='real-name', package='bar', version='2.0')
  60. # But not by their alias
  61. assert not hints.search(type='alias1', package='foo', version='1.0')
  62. assert not hints.search(type='alias2', package='bar', version='2.0')
  63. if __name__ == '__main__':
  64. unittest.main()