Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ jobs:
name: wheels-${{ runner.os }}-${{ matrix.target }}
path: dist/*

test:
name: Test wheels on ${{ matrix.os }} (${{ matrix.python-version }})
needs: linux
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Download x86_64 wheels
uses: actions/download-artifact@v4
with:
name: wheels-Linux-x86_64
path: dist
- name: Install wheel and dependencies
run: |
pip install --upgrade pip
pip install --no-index --find-links=dist lightningcss
pip install --group dev
- name: Run tests
run: pytest

sdist:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ classifiers = [
[project.urls]
Source = "https://github.com/pydsigner/python-lightningcss"

[dependency-groups]
dev = [
"pytest>=9.0.2",
]

[tool.maturin]
features = ["pyo3/extension-module"]
5 changes: 5 additions & 0 deletions tests/data/invalid.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* {
box-sizing: border-box;
}

something invalid
5 changes: 5 additions & 0 deletions tests/data/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "normalize.css" layer(normalize);

a {
color: blue;
}
3 changes: 3 additions & 0 deletions tests/data/normalize.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* {
box-sizing: border-box;
}
30 changes: 30 additions & 0 deletions tests/test_bundle_css.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path
import pytest
import lightningcss as lcss

TEST_DATA_DIR = Path(__file__).parent / "data"
MAIN_CSS_PATH = TEST_DATA_DIR / "main.css"
NORMALIZE_CSS_PATH = TEST_DATA_DIR / "normalize.css"
MISSING_CSS_PATH = TEST_DATA_DIR / "not-there.css"
INVALID_CSS_PATH = TEST_DATA_DIR / "invalid.css"


def test_minify():
expected = "@layer normalize{*{box-sizing:border-box}}a{color:#00f}"

result = lcss.bundle_css(str(MAIN_CSS_PATH))
assert result == expected

def test_pretty_print():
expected = "* {\n box-sizing: border-box;\n}\n"

result = lcss.bundle_css(str(NORMALIZE_CSS_PATH), minify=False)
assert result == expected

def test_file_not_found():
with pytest.raises(OSError):
lcss.bundle_css(str(MISSING_CSS_PATH))

def test_parse_error():
with pytest.raises(ValueError):
lcss.bundle_css(str(INVALID_CSS_PATH))
33 changes: 33 additions & 0 deletions tests/test_process_stylesheet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import lightningcss as lcss
import pytest


def test_minify():
code = ".content { margin-inline: 3vw; padding: 1rem 2rem 1rem 2rem; }"
expected = ".content{margin-inline:3vw;padding:1rem 2rem}"

result = lcss.process_stylesheet(code)
assert result == expected

def test_pretty_print():
code = ".content { margin: 3vw; }"
expected = ".content {\n margin: 3vw;\n}\n"

result = lcss.process_stylesheet(code, minify=False)
assert result == expected

def test_parse_error():
code = "img { display: block; } nonsense }{ non-terminated"

with pytest.raises(ValueError):
lcss.process_stylesheet(code)

def test_error_recovery():
code = "img { display: block; } nonsense }{ non-terminated"
expected = "img{display:block}"

with pytest.raises(ValueError):
lcss.process_stylesheet(code, error_recovery=False)

result = lcss.process_stylesheet(code, error_recovery=True)
assert result == expected