File: test_docs.py

package info (click to toggle)
django-htmx 1.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: javascript: 3,395; python: 956; makefile: 27; sh: 19
file content (36 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from __future__ import annotations

import re
from pathlib import Path

from django.test import SimpleTestCase


class TemplateTagsTests(SimpleTestCase):
    def test_htmx_versions_match(self):
        base_dir = Path(__file__).resolve().parent.parent
        htmx_js_path = base_dir / "django_htmx/static/django_htmx/htmx.js"
        htmx_min_js_path = base_dir / "django_htmx/static/django_htmx/htmx.min.js"
        scripts_rst_path = base_dir / "docs/template_tags.rst"

        htmx_js_version = read_version(
            htmx_js_path,
            r"version: '(\d+\.\d+\.\d+)'",
        )
        htmx_min_js_version = read_version(
            htmx_min_js_path, r'version:"(\d+\.\d+\.\d+)"'
        )
        scripts_rst_version = read_version(
            scripts_rst_path,
            r"The current vendored version of htmx is (\d+\.\d+\.\d+)\.",
        )

        assert htmx_js_version == htmx_min_js_version
        assert htmx_js_version == scripts_rst_version


def read_version(path: Path, regex: str) -> str:
    content = path.read_text()
    match = re.search(regex, content)
    assert match
    return match[1]