08_test_patch.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # vim: set fileencoding=utf-8 :
  2. """Test L{Patch} class"""
  3. from . import context # noqa: 401
  4. import os
  5. import unittest
  6. from gbp.patch_series import Patch
  7. class TestPatch(unittest.TestCase):
  8. data_dir = os.path.splitext(__file__)[0] + '_data'
  9. def test_filename(self):
  10. """Get patch information from the filename"""
  11. p = Patch(os.path.join(self.data_dir, "doesnotexist.diff"))
  12. self.assertEqual('doesnotexist', p.subject)
  13. self.assertEqual({}, p.info)
  14. p = Patch(os.path.join(self.data_dir, "doesnotexist.patch"))
  15. self.assertEqual('doesnotexist', p.subject)
  16. p = Patch(os.path.join(self.data_dir, "doesnotexist"))
  17. self.assertEqual('doesnotexist', p.subject)
  18. self.assertEqual(None, p.author)
  19. self.assertEqual(None, p.email)
  20. self.assertEqual(None, p.date)
  21. def test_header(self):
  22. """Get the patch information from a patch header"""
  23. patchfile = os.path.join(self.data_dir, "patch1.diff")
  24. self.assertTrue(os.path.exists(patchfile))
  25. p = Patch(patchfile)
  26. self.assertEqual('This is patch1', p.subject)
  27. self.assertEqual("foo", p.author)
  28. self.assertEqual("foo@example.com", p.email)
  29. self.assertEqual("This is the long description.\n"
  30. "It can span several lines.\n",
  31. p.long_desc)
  32. self.assertEqual('Sat, 24 Dec 2011 12:05:53 +0100', p.date)