Debian Codegraph @

mkdocs/tests/utils/templates_tests.py

raw
1 import unittest
2 from textwrap import dedent
3
4 import yaml
5
6 from mkdocs.tests.base import load_config
7 from mkdocs.utils import templates
8
9
10 class UtilsTemplatesTests(unittest.TestCase):
11 def test_script_tag(self):
12 cfg_yaml = dedent(
13 '''
14 extra_javascript:
15 - some_plain_javascript.js
16 - implicitly_as_module.mjs
17 - path: explicitly_as_module.mjs
18 type: module
19 - path: deferred_plain.js
20 defer: true
21 - path: scripts/async_module.mjs
22 type: module
23 async: true
24 - path: 'aaaaaa/"my script".mjs'
25 type: module
26 async: true
27 defer: true
28 - path: plain.mjs
29 '''
30 )
31 config = load_config(**yaml.safe_load(cfg_yaml))
32 config.extra_javascript.append('plain_string.mjs')
33
34 self.assertEqual(
35 [
36 str(templates.script_tag_filter({'page': None, 'base_url': 'here'}, item))
37 for item in config.extra_javascript
38 ],
39 [
40 '<script src="here/some_plain_javascript.js"></script>',
41 '<script src="here/implicitly_as_module.mjs" type="module"></script>',
42 '<script src="here/explicitly_as_module.mjs" type="module"></script>',
43 '<script src="here/deferred_plain.js" defer></script>',
44 '<script src="here/scripts/async_module.mjs" type="module" async></script>',
45 '<script src="here/aaaaaa/&#34;my script&#34;.mjs" type="module" defer async></script>',
46 '<script src="here/plain.mjs"></script>',
47 '<script src="here/plain_string.mjs"></script>',
48 ],
49 )