10_test_get_upstream_tree.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # vim: set fileencoding=utf-8 :
  2. """Test L{buildpackage}'s get_upstream_tree method"""
  3. from . import context # noqa: 401
  4. from . import testutils
  5. import gbp.errors
  6. import gbp.scripts.buildpackage as buildpackage
  7. class MockOptions(object):
  8. def __init__(self,
  9. upstream_branch=None,
  10. upstream_tree=None,
  11. upstream_tag=None):
  12. self.upstream_branch = upstream_branch
  13. self.upstream_tree = upstream_tree
  14. self.upstream_tag = upstream_tag
  15. class TestGetUpstreamTree(testutils.DebianGitTestRepo):
  16. def test_valid_upstream_branch(self):
  17. """Get upstream tree from a valid upstream branch"""
  18. self.add_file('foo')
  19. self.repo.create_branch('upstream')
  20. options = MockOptions(upstream_tree='BRANCH',
  21. upstream_branch='upstream')
  22. t = buildpackage.get_upstream_tree(self.repo, None, options)
  23. self.assertEqual(t, 'upstream')
  24. def test_invalid_upstream_branch(self):
  25. """Getting upstream tree from a invalid upstream branch must fail"""
  26. self.add_file('foo')
  27. options = MockOptions(upstream_tree='BRANCH',
  28. upstream_branch='upstream')
  29. self.assertRaises(gbp.errors.GbpError,
  30. buildpackage.get_upstream_tree,
  31. self.repo,
  32. None,
  33. options)
  34. def test_valid_tree(self):
  35. """Get upstream tree from a valid upstream tree"""
  36. self.add_file('foo')
  37. tree = self.repo.rev_parse('master')
  38. options = MockOptions(upstream_tree=tree)
  39. t = buildpackage.get_upstream_tree(self.repo, None, options)
  40. self.assertEqual(t, tree)
  41. def test_invalid_tree(self):
  42. """Getting upstream tree from an invalid tree must fail"""
  43. self.add_file('foo')
  44. options = MockOptions(upstream_tree='doesnotexist')
  45. self.assertRaises(gbp.errors.GbpError,
  46. buildpackage.get_upstream_tree,
  47. self.repo,
  48. None,
  49. options)
  50. def test_valid_tag(self):
  51. """Get upstream tree from a valid tag"""
  52. self.add_file('foo')
  53. self.repo.rev_parse('master')
  54. cp = {'Upstream-Version': '1.0~rc3'}
  55. self.repo.create_tag('upstream/1.0_rc3')
  56. options = MockOptions(upstream_tree="TAG",
  57. upstream_tag="upstream/%(version)s")
  58. tag = buildpackage.get_upstream_tree(self.repo, cp, options)
  59. self.assertEqual(tag, "upstream/1.0_rc3")
  60. def test_invalid_tag(self):
  61. """Getting upstream tree from an invalid tag must fail"""
  62. self.add_file('foo')
  63. cp = {'Upstream-Version': '1.0~rc3'}
  64. options = MockOptions(upstream_tree="TAG",
  65. upstream_tag="upstream/%(version)s")
  66. self.assertRaises(gbp.errors.GbpError,
  67. buildpackage.get_upstream_tree,
  68. self.repo,
  69. cp,
  70. options)
  71. # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: