new_proposal_test.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python3
  2. """Tests for new_proposal.py."""
  3. __copyright__ = """
  4. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  5. Exceptions. See /LICENSE for license information.
  6. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. """
  8. import os
  9. import unittest
  10. from proposals.scripts import new_proposal
  11. class TestNewProposal(unittest.TestCase):
  12. def test_calculate_branch_short(self):
  13. parsed_args = new_proposal._parse_args(["foo bar"])
  14. self.assertEqual(
  15. new_proposal._calculate_branch(parsed_args), "proposal-foo-bar"
  16. )
  17. def test_calculate_branch_long(self):
  18. parsed_args = new_proposal._parse_args(
  19. ["A really long long long title"]
  20. )
  21. self.assertEqual(
  22. new_proposal._calculate_branch(parsed_args),
  23. "proposal-a-really-long-long-l",
  24. )
  25. def test_calculate_branch_flag(self):
  26. parsed_args = new_proposal._parse_args(["--branch=wiz", "foo"])
  27. self.assertEqual(new_proposal._calculate_branch(parsed_args), "wiz")
  28. def test_fill_template(self):
  29. parsed_args = new_proposal._parse_args(["foo"])
  30. content = new_proposal._fill_template(
  31. os.path.join(
  32. new_proposal._get_proposals_dir(parsed_args), "template.md"
  33. ),
  34. "TITLE",
  35. 123,
  36. )
  37. self.assertTrue(content.startswith("# TITLE\n\n"), content)
  38. self.assertTrue(
  39. "[Pull request](https://github.com/carbon-language/carbon-lang/"
  40. "pull/123)" in content,
  41. content,
  42. )
  43. def test_run_success(self):
  44. new_proposal._run(["true"])
  45. def test_run_failure(self):
  46. self.assertRaises(SystemExit, new_proposal._run, ["false"])
  47. if __name__ == "__main__":
  48. unittest.main()