23_test_dch_extract_bts_cmds.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # (C) 2015 Jonathan Toppins <jtoppins@cumulusnetworks.com>
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, please see
  14. # <http://www.gnu.org/licenses/>
  15. """Test gbp.dch.extract_bts_cmds()"""
  16. import os
  17. import unittest
  18. from gbp.dch import extract_bts_cmds
  19. class OptionsStub:
  20. def __init__(self):
  21. self.meta_closes = "Closes|LP"
  22. self.meta_closes_bugnum = r'(?:bug|issue)?\#?\s?\d+'
  23. class TestExtractBTSCmds(unittest.TestCase):
  24. def test_debian_commands(self):
  25. """Test default BTS command extraction that is applicable to Debian"""
  26. options = OptionsStub()
  27. lines = """This is a test commit
  28. Closes: bug#12345
  29. Closes: 456
  30. """
  31. bugs, dummy = extract_bts_cmds(lines.split('\n'), options)
  32. self.assertEquals(bugs, {'Closes': ['bug#12345', '456']})
  33. def test_nondebian_commands(self):
  34. """Test non-default BTS commands. We use the example given in the
  35. documentation manpages."""
  36. options = OptionsStub()
  37. options.meta_closes_bugnum = "(?:bug)?\s*ex-\d+"
  38. lines = """This is a test commit
  39. some more lines...
  40. Closes: bug EX-12345
  41. Closes: ex-01273
  42. Closes: bug ex-1ab
  43. Closes: EX--12345
  44. """
  45. bugs, dummy = extract_bts_cmds(lines.split('\n'), options)
  46. self.assertEquals(bugs, {'Closes': ['bug EX-12345', 'ex-01273',
  47. 'bug ex-1']})