15_test_DebianSource.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # vim: set fileencoding=utf-8 :
  2. # (C) 2013 Guido Günther <agx@sigxcpu.org>
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, please see
  15. # <http://www.gnu.org/licenses/>
  16. """Test L{gbp.pq}"""
  17. from . import context
  18. from . import testutils
  19. import os
  20. from gbp.deb.source import DebianSource, DebianSourceError
  21. from gbp.deb.format import DebianSourceFormat
  22. from gbp.git.vfs import GitVfs
  23. class TestDebianSource(testutils.DebianGitTestRepo):
  24. """Test L{gbp.deb.source}'s """
  25. def setUp(self):
  26. testutils.DebianGitTestRepo.setUp(self)
  27. context.chdir(self.repo.path)
  28. def test_is_native_file_3_file(self):
  29. """Test native package of format 3"""
  30. source = DebianSource('.')
  31. os.makedirs('debian/source')
  32. self.assertRaises(DebianSourceError,
  33. source.is_native)
  34. dsf = DebianSourceFormat.from_content("3.0", "native")
  35. self.assertEqual(dsf.type, 'native')
  36. self.assertTrue(source.is_native())
  37. dsf = DebianSourceFormat.from_content("3.0", "quilt")
  38. self.assertEqual(dsf.type, 'quilt')
  39. self.assertFalse(source.is_native())
  40. def test_is_native_fallback_file(self):
  41. """Test native package without a debian/source/format file"""
  42. source = DebianSource('.')
  43. os.makedirs('debian/')
  44. self.assertRaises(DebianSourceError,
  45. source.is_native)
  46. with open('debian/changelog', 'w') as f:
  47. f.write("""git-buildpackage (0.2.3) git-buildpackage; urgency=low
  48. * git doesn't like '~' in tag names so replace this with a dot when tagging
  49. -- Guido Guenther <agx@sigxcpu.org> Mon, 2 Oct 2006 18:30:20 +0200
  50. """)
  51. source = DebianSource('.')
  52. self.assertTrue(source.is_native())
  53. def _commit_format(self, version, format):
  54. # Commit a format file to disk
  55. if not os.path.exists('debian/source'):
  56. os.makedirs('debian/source')
  57. dsf = DebianSourceFormat.from_content(version, format)
  58. self.assertEqual(dsf.type, format)
  59. self.repo.add_files('.')
  60. self.repo.commit_all('foo')
  61. os.unlink('debian/source/format')
  62. self.assertFalse(os.path.exists('debian/source/format'))
  63. def test_is_native_file_3_git(self):
  64. """Test native package of format 3 from git"""
  65. self._commit_format('3.0', 'native')
  66. source = DebianSource(GitVfs(self.repo))
  67. self.assertTrue(source.is_native())
  68. self._commit_format('3.0', 'quilt')
  69. source = DebianSource(GitVfs(self.repo))
  70. self.assertFalse(source.is_native())