new_proposal_test.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 carbon.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),
  33. "scripts/template.md",
  34. ),
  35. "TITLE",
  36. 123,
  37. )
  38. self.assertTrue(content.startswith("# TITLE\n\n"), content)
  39. self.assertTrue(
  40. "[Pull request](https://github.com/carbon-language/carbon-lang/"
  41. "pull/123)" in content,
  42. content,
  43. )
  44. self.assertTrue(
  45. "<!-- tocstop -->\n\n## Abstract\n\n" in content, content
  46. )
  47. def test_run_success(self):
  48. new_proposal._run(["true"])
  49. def test_run_failure(self):
  50. self.assertRaises(SystemExit, new_proposal._run, ["false"])
  51. if __name__ == "__main__":
  52. unittest.main()