05_test_detection.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # vim: set fileencoding=utf-8 :
  2. """Test tarball compression type detection"""
  3. from . import context
  4. import unittest
  5. from gbp.scripts import buildpackage
  6. from gbp.deb import (DebianPkgPolicy, orig_file)
  7. from gbp.errors import GbpError
  8. class MockGitRepository:
  9. def __init__(self, with_branch=False, subject=None):
  10. self.with_branch = with_branch
  11. self.subject = subject
  12. def has_pristine_tar_branch(self):
  13. return self.with_branch
  14. def pristine_tar_branch(self):
  15. 'pristine-tar'
  16. def grep_log(self, regex, branch):
  17. return None
  18. def get_commit_info(self, commit):
  19. return {'subject': self.subject}
  20. class TestDetection(unittest.TestCase):
  21. def setUp(self):
  22. self.tmpdir = context.new_tmpdir(__name__)
  23. self.cp = {'Source': 'source', 'Upstream-Version': '1.2'}
  24. def tearDown(self):
  25. context.teardown()
  26. def test_guess_comp_type_no_pristine_tar_no_orig(self):
  27. repo = MockGitRepository(with_branch=False)
  28. guessed = buildpackage.guess_comp_type(
  29. repo, 'auto', self.cp, str(self.tmpdir))
  30. self.assertEqual('gzip', guessed)
  31. def test_guess_comp_type_no_pristine_tar_with_orig(self):
  32. open(self.tmpdir.join('source_1.2.orig.tar.bz2'), "w").close()
  33. repo = MockGitRepository(with_branch=False)
  34. guessed = buildpackage.guess_comp_type(
  35. repo, 'auto', self.cp, str(self.tmpdir))
  36. self.assertEqual('bzip2', guessed)
  37. def test_guess_comp_type_no_pristine_tar_with_multiple_origs(self):
  38. open(self.tmpdir.join('source_1.2.orig.tar.gz'), "w").close()
  39. open(self.tmpdir.join('source_1.2.orig.tar.xz'), "w").close()
  40. repo = MockGitRepository(with_branch=False)
  41. self.assertRaises(
  42. GbpError,
  43. buildpackage.guess_comp_type,
  44. repo,
  45. 'auto',
  46. self.cp,
  47. str(self.tmpdir))
  48. def test_guess_comp_type_auto_bzip2(self):
  49. subject = 'pristine-tar data for source_1.2-3.orig.tar.bz2'
  50. repo = MockGitRepository(with_branch=True, subject=subject)
  51. guessed = buildpackage.guess_comp_type(
  52. repo, 'auto', self.cp, str(self.tmpdir))
  53. self.assertEqual("bzip2", guessed)
  54. def test_has_orig_false(self):
  55. self.assertFalse(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), str(self.tmpdir)))
  56. def test_has_orig_true(self):
  57. open(self.tmpdir.join('source_1.2.orig.tar.gz'), "w").close()
  58. self.assertTrue(DebianPkgPolicy.has_orig(orig_file(self.cp, 'gzip'), str(self.tmpdir)))
  59. def test_guess_comp_type_bzip2(self):
  60. repo = MockGitRepository(with_branch=False)
  61. guessed = buildpackage.guess_comp_type(
  62. repo, 'bzip2', self.cp, None)
  63. self.assertEqual("bzip2", guessed)
  64. def test_guess_comp_type_gzip(self):
  65. repo = MockGitRepository(with_branch=False)
  66. guessed = buildpackage.guess_comp_type(
  67. repo, 'gzip', self.cp, None)
  68. self.assertEqual("gzip", guessed)
  69. def test_guess_comp_type_bz(self):
  70. repo = MockGitRepository(with_branch=False)
  71. guessed = buildpackage.guess_comp_type(
  72. repo, 'xz', self.cp, None)
  73. self.assertEqual("xz", guessed)
  74. def test_guess_comp_type_lzma(self):
  75. repo = MockGitRepository(with_branch=False)
  76. guessed = buildpackage.guess_comp_type(
  77. repo, 'lzma', self.cp, None)
  78. self.assertEqual("lzma", guessed)
  79. def test_guess_comp_type_bz2(self):
  80. repo = MockGitRepository(with_branch=False)
  81. guessed = buildpackage.guess_comp_type(
  82. repo, 'bz2', self.cp, None)
  83. self.assertEqual("bzip2", guessed)
  84. def test_guess_comp_type_gz(self):
  85. repo = MockGitRepository(with_branch=False)
  86. guessed = buildpackage.guess_comp_type(
  87. repo, 'gz', self.cp, None)
  88. self.assertEqual("gzip", guessed)