Skip to content

Commit 0dedd4c

Browse files
add basic tests for coverage and remove extra deps
1 parent bf8e0ed commit 0dedd4c

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

pyproject.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ classifiers = [
2525
]
2626
dependencies = [
2727
"django>=4.2",
28-
"lxml>=5.3.0",
2928
]
3029
description = "A UI Kit for your Django projects"
3130
dynamic = ["version"]
@@ -248,7 +247,4 @@ dev-dependencies = [
248247
"pytest-randomly>=3.15.0",
249248
"pytest-xdist>=3.6.1",
250249
"ruff>=0.6.6",
251-
"types-lxml>=2024.9.16",
252-
"django-bootstrap5>=24.3",
253-
"scipy>=1.14.1",
254250
]

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from .settings import DEFAULT_SETTINGS
99

10-
pytest_plugins = [] # type: ignore
10+
pytest_plugins = []
1111

1212

1313
def pytest_configure(config):
@@ -19,7 +19,6 @@ def pytest_configure(config):
1919
TEST_SETTINGS = {
2020
"INSTALLED_APPS": [
2121
"django_bird",
22-
"django_bootstrap5",
2322
],
2423
"TEMPLATES": [
2524
{

tests/templates/with_bird.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% spaceless %}
2+
<div>
3+
<h1>{{ title }}</h1>
4+
<p>{{ content }}</p>
5+
<bird:button class="btn-primary">Click me</bird:button>
6+
</div>
7+
{% endspaceless %}

tests/templates/without_bird.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% spaceless %}
2+
<div>
3+
<h1>{{ title }}</h1>
4+
<p>{{ content }}</p>
5+
<button class="btn-primary">Click me</button>
6+
</div>
7+
{% endspaceless %}

tests/test_compiler.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import annotations
2+
3+
from django_bird.compiler import Compiler
4+
5+
6+
def test_compiler():
7+
component_template = """
8+
<style>
9+
body { font-family: Arial, sans-serif; }
10+
</style>
11+
12+
<h1>Welcome to my page</h1>
13+
{{ user.name }}
14+
15+
<script>
16+
console.log('Hello, world!');
17+
</script>
18+
19+
<p>This is some more content.</p>
20+
21+
<style>
22+
.highlight { color: red; }
23+
</style>
24+
"""
25+
compiler = Compiler()
26+
27+
tokens = compiler.tokenize(component_template)
28+
parsed = compiler.parse(tokens)
29+
transformed = compiler.transform(parsed)
30+
compiled = compiler.compile(component_template)
31+
32+
assert tokens
33+
assert parsed
34+
assert transformed
35+
assert compiled

tests/test_loader.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from __future__ import annotations
2+
3+
import pytest
4+
from django.template.loader import get_template
5+
6+
7+
@pytest.mark.parametrize(
8+
"template_name",
9+
(
10+
"with_bird.html",
11+
"without_bird.html",
12+
),
13+
)
14+
def test_render_template(template_name):
15+
context = {
16+
"title": "Test Title",
17+
"content": "Test Content",
18+
}
19+
20+
template = get_template(template_name)
21+
rendered = template.render(context)
22+
23+
assert rendered

0 commit comments

Comments
 (0)