-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
*.py text eol=lf | ||
*.sh text eol=lf | ||
*.svg text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ jobs: | |
main: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [ "3.8", "3.12" ] # Lowest and highest. | ||
steps: | ||
|
@@ -13,4 +14,6 @@ jobs: | |
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "pip" # caching pip dependencies | ||
- run: pip install -r requirements.txt | ||
- run: pip install -r requirements_dev.txt | ||
- uses: pre-commit/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ documentation/src/generators.inc | |
*.ipynb_checkpoints | ||
venv/ | ||
.vscode/ | ||
tracker.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
inkex | ||
lxml | ||
mypy | ||
pre-commit | ||
pytest>=8.1.1 | ||
types-Markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
from lxml import etree | ||
|
||
try: | ||
import boxes | ||
except ImportError: | ||
sys.path.append(Path(__file__).resolve().parent.parent.__str__()) | ||
import boxes | ||
|
||
import boxes.generators | ||
|
||
|
||
class TestSVG: | ||
all_generators = boxes.generators.getAllBoxGenerators().values() | ||
|
||
notTestGenerator = ('GridfinityTrayLayout', 'TrayLayout', 'TrayLayoutFile', 'TypeTray', 'Edges',) | ||
brokenGenerator = () | ||
avoidGenerator = notTestGenerator + brokenGenerator | ||
|
||
def test_generators_available(self) -> None: | ||
assert len(self.all_generators) != 0 | ||
|
||
# svgcheck currently do not allow inkscape custom tags. | ||
# @staticmethod | ||
# def is_valid_svg(file_path: str) -> bool: | ||
# result = subprocess.run(['svgcheck', file_path], capture_output=True, text=True) | ||
# return "INFO: File conforms to SVG requirements." in result.stdout | ||
|
||
@staticmethod | ||
def is_valid_xml_by_lxml(xml_string: str) -> bool: | ||
try: | ||
etree.fromstring(xml_string) | ||
return True | ||
except etree.XMLSyntaxError: | ||
return False | ||
|
||
@staticmethod | ||
def idfunc(val) -> str: | ||
return f"{val.__name__}" | ||
|
||
@pytest.mark.parametrize( | ||
"generator", | ||
all_generators, | ||
ids=idfunc.__func__, | ||
) | ||
def test_generator(self, generator: type[boxes.Boxes], capsys) -> None: | ||
boxName = generator.__name__ | ||
if boxName in self.avoidGenerator: | ||
pytest.skip("Skipped generator") | ||
box = generator() | ||
box.parseArgs("") | ||
box.metadata["reproducible"] = True | ||
box.open() | ||
box.render() | ||
boxData = box.close() | ||
|
||
out, err = capsys.readouterr() | ||
|
||
assert 100 < boxData.__sizeof__(), "No data generated." | ||
assert 0 == len(out), "Console output generated." | ||
assert 0 == len(err), "Console error generated." | ||
|
||
# Use external library lxml as cross-check. | ||
assert self.is_valid_xml_by_lxml(boxData.getvalue()) is True, "Invalid XML according to library lxml." | ||
|
||
file = Path(__file__).resolve().parent / 'data' / (boxName + '.svg') | ||
file.write_bytes(boxData.getvalue()) | ||
|
||
# Use example data from repository as reference data. | ||
referenceData = Path(__file__).resolve().parent.parent / 'examples' / (boxName + '.svg') | ||
assert referenceData.exists() is True, "Reference file for comparison does not exist." | ||
assert referenceData.is_file() is True, "Reference file for comparison does not exist." | ||
assert referenceData.read_bytes() == boxData.getvalue(), "SVG files are not equal. If change is intended, please update example files." |