Add tests for linguist integration

This commit is contained in:
Jake Howard 2023-06-04 19:25:38 +01:00
parent 8f5ab16891
commit c2d8ef260a
Signed by: jake
GPG Key ID: 57AFB45680EDD477
1 changed files with 26 additions and 1 deletions

View File

@ -1,8 +1,10 @@
import re
from django.test import SimpleTestCase
from django.urls import reverse
from .blocks import CodeStructValue, get_language_choices
from .utils import PYGMENTS_VERSION_SLUG
from .utils import PYGMENTS_VERSION_SLUG, get_linguist_colours
class PygmentsStylesTestCase(SimpleTestCase):
@ -35,6 +37,29 @@ class CodeStructValueTestCase(SimpleTestCase):
block = CodeStructValue(None, [("filename", ""), ("language", "Python")])
self.assertEqual(block.header_text(), "Python")
def test_header_text_uses_language_mapping(self) -> None:
block = CodeStructValue(
None, [("filename", ""), ("language", "Python console session")]
)
self.assertEqual(block.header_text(), "Python")
def test_header_text_empty_when_text(self) -> None:
block = CodeStructValue(None, [("filename", ""), ("language", "Text only")])
self.assertEqual(block.header_text(), "")
def test_linguist_mapping(self) -> None:
linguist_languages = set(get_linguist_colours().keys())
for language in CodeStructValue.LINGUIST_MAPPING.values():
self.assertIn(language.lower(), linguist_languages)
class LinguistColoursTestCase(SimpleTestCase):
HEX_RE = re.compile(r"#[0-9A-F]", re.IGNORECASE)
def test_gets_colours(self) -> None:
colours = get_linguist_colours()
for colour in colours.values():
with self.subTest(colour):
self.assertRegex(colour, self.HEX_RE)