Files
carbon-lang/proposals/scripts/new_proposal_test.py
T
Jon Meow f2d48f1bd0 Move the jekyll sidebar to a python script for consistent generation. (#205)
One implication here is that both proposals/README.md and the website should use basically the same format for their proposal lists. Another subtle change is that the website sidebar was previously sorted by *filename*, and is now sorted by *title*, which seems better because it's something that readers can see.

Enumerating why files change:

- gen_sidebar.py is the centerpiece, with a couple helpful functions for re-use elsewhere
- Delete the old sidebar html includes
- Modify the Makefile to handle gen_sidebar.py reasonably well (let's be honest... I'm not great at Makefiles)
- Move proposal listing out to its own file (proposals.py) for re-use
- Add a few PYTHONPATH things + `__init__.py` files to get modules importing correctly (may be a better way at this, I've hit a wall though).
2020-12-04 08:26:25 -08:00

71 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Tests for new_proposal.py."""
__copyright__ = """
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
Exceptions. See /LICENSE for license information.
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import os
import unittest
from unittest import mock
from proposals.scripts import new_proposal
class FakeExitError(Exception):
pass
def _fake_exit(message):
raise FakeExitError(message)
class TestNewProposal(unittest.TestCase):
def test_calculate_branch_short(self):
parsed_args = new_proposal._parse_args(["foo bar"])
self.assertEqual(
new_proposal._calculate_branch(parsed_args), "proposal-foo-bar"
)
def test_calculate_branch_long(self):
parsed_args = new_proposal._parse_args(
["A really long long long title"]
)
self.assertEqual(
new_proposal._calculate_branch(parsed_args),
"proposal-a-really-long-long-l",
)
def test_calculate_branch_flag(self):
parsed_args = new_proposal._parse_args(["--branch=wiz", "foo"])
self.assertEqual(new_proposal._calculate_branch(parsed_args), "wiz")
def test_fill_template(self):
content = new_proposal._fill_template(
os.path.join(new_proposal._get_proposals_dir(), "template.md"),
"TITLE",
123,
)
self.assertTrue(content.startswith("# TITLE\n\n"), content)
self.assertTrue(
"[Pull request](https://github.com/carbon-language/carbon-lang/"
"pull/123)" in content,
content,
)
def test_run_success(self):
new_proposal._run(["true"])
def test_run_failure(self):
with mock.patch(
"proposals.scripts.new_proposal._exit", side_effect=_fake_exit
):
self.assertRaises(FakeExitError, new_proposal._run, ["false"])
if __name__ == "__main__":
unittest.main()