add testing with Tox
This commit is contained in:
parent
47a32569a9
commit
91b6bd9c79
7 changed files with 46 additions and 7 deletions
3
Makefile
3
Makefile
|
@ -12,3 +12,6 @@ upload:
|
||||||
hatch publish
|
hatch publish
|
||||||
release:
|
release:
|
||||||
hatch clean && hatch build && hatch publish
|
hatch clean && hatch build && hatch publish
|
||||||
|
# Build the tox docker image, use docker run -v "$(pwd)":"/code" jekyll-to-hugo-tox -e ci to run tox
|
||||||
|
build-tox:
|
||||||
|
docker build . -f ./docker/Tox.Dockerfile -t jekyll-to-hugo-tox
|
|
@ -38,7 +38,7 @@ class FileWriter(IoWriter):
|
||||||
fo.write(data)
|
fo.write(data)
|
||||||
|
|
||||||
|
|
||||||
class TestingWriter(IoWriter):
|
class MockWriter(IoWriter):
|
||||||
"""
|
"""
|
||||||
Writes a post to a string.
|
Writes a post to a string.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,7 +3,7 @@ import pytest
|
||||||
from app.config import ConverterOptions
|
from app.config import ConverterOptions
|
||||||
from app.converter import WordpressMarkdownConverter
|
from app.converter import WordpressMarkdownConverter
|
||||||
from app.io.reader import StringReader
|
from app.io.reader import StringReader
|
||||||
from app.io.writer import TestingWriter
|
from app.io.writer import MockWriter
|
||||||
from app.tests.utils import make_fake_configurator
|
from app.tests.utils import make_fake_configurator
|
||||||
|
|
||||||
|
|
||||||
|
@ -183,6 +183,6 @@ def test_write_hugo_post():
|
||||||
ConverterOptions(),
|
ConverterOptions(),
|
||||||
)
|
)
|
||||||
converter = WordpressMarkdownConverter(configurator)
|
converter = WordpressMarkdownConverter(configurator)
|
||||||
writer = TestingWriter()
|
writer = MockWriter()
|
||||||
converter.write_hugo_post(writer, {"title": "Test"}, "Test\nLine 2")
|
converter.write_hugo_post(writer, {"title": "Test"}, "Test\nLine 2")
|
||||||
assert writer.content == "---\ntitle: Test\n---\nTest\nLine 2"
|
assert writer.content == "---\ntitle: Test\n---\nTest\nLine 2"
|
||||||
|
|
|
@ -2,11 +2,11 @@ FROM python:3.10-slim
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY requirements.txt /app/requirements.txt
|
COPY ../requirements.txt /app/requirements.txt
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
COPY . /app
|
COPY .. /app
|
||||||
|
|
||||||
ENTRYPOINT [ "python" ]
|
ENTRYPOINT [ "python" ]
|
||||||
CMD [ "main.py" ]
|
CMD [ "main.py" ]
|
14
docker/Tox.Dockerfile
Normal file
14
docker/Tox.Dockerfile
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
FROM ubuntu:22.04
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN apt update && apt install -y software-properties-common \
|
||||||
|
&& add-apt-repository ppa:deadsnakes/ppa \
|
||||||
|
&& apt install -y python3.10 && apt install -y python3.11 \
|
||||||
|
&& apt install -y python3-pip && pip3 install tox
|
||||||
|
|
||||||
|
VOLUME /code
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
ENTRYPOINT tox
|
||||||
|
CMD ["-e", "ci"]
|
|
@ -59,7 +59,7 @@ If you don't have Python installed, you can use Docker:
|
||||||
1. Build the image.
|
1. Build the image.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker build -t jekyll-to-hugo .
|
docker build -t jekyll-to-hugo -f ./docker/Dockerfile .
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the image. You will need to mount the following directories: config file, Jekyll posts directory, Hugo posts directory.
|
2. Run the image. You will need to mount the following directories: config file, Jekyll posts directory, Hugo posts directory.
|
||||||
|
|
22
tox.ini
Normal file
22
tox.ini
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# content of: tox.ini , put in same dir as setup.py
|
||||||
|
[tox]
|
||||||
|
skip_missing_interpreters = True
|
||||||
|
envlist = py310,py311
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
# install pytest in the virtualenv where commands will be executed
|
||||||
|
deps =
|
||||||
|
pytest
|
||||||
|
pytest-cov
|
||||||
|
commands =
|
||||||
|
# NOTE: you can run any command line tool here – not just tests
|
||||||
|
pytest -p no:warnings
|
||||||
|
|
||||||
|
[testenv:ci]
|
||||||
|
commands =
|
||||||
|
pytest —junitxml=results.xml \
|
||||||
|
—cov=your-module—cov-config=tox.ini —cov-report=xml
|
||||||
|
coverage2clover -i coverage.xml -o clover.xml
|
||||||
|
deps =
|
||||||
|
{[testenv]deps}
|
||||||
|
coverage2clover
|
Loading…
Reference in a new issue