From 043b1e918f567ddf5d2f2af69da5ac2aaed559b3 Mon Sep 17 00:00:00 2001 From: truePhilipp Date: Fri, 3 May 2024 08:11:50 +0000 Subject: [PATCH] added test_block_formatter; restructured workflows; added workflow badges --- .github/workflows/main.yml | 37 ----------------------- .github/workflows/stylecheck.yml | 29 ++++++++++++++++++ .github/workflows/tests.yml | 27 +++++++++++++++++ README.md | 3 ++ tests/formatters/__init__.py | 0 tests/formatters/tests_block_formatter.py | 20 ++++++++++++ 6 files changed, 79 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/stylecheck.yml create mode 100644 .github/workflows/tests.yml create mode 100644 tests/formatters/__init__.py create mode 100644 tests/formatters/tests_block_formatter.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 479c7bd..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Python package - -on: [push] - -jobs: - stylecheck: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Setup Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: 3.12 - - name: Install Dependencies - run: | - pip install ".[test]" - mypy html_to_django || true - mypy --install-types --non-interactive - - name: Stylecheck - run: | - mypy --strict html_to_django - pycodestyle --max-line-length 120 html_to_django - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.12"] - steps: - - uses: actions/checkout@v4 - - name: Setup Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install Dependencies - run: pip install ".[test]" - - name: Test on Python ${{ matrix.python-version }} - run: python -m unittest discover tests --verbose diff --git a/.github/workflows/stylecheck.yml b/.github/workflows/stylecheck.yml new file mode 100644 index 0000000..8becc50 --- /dev/null +++ b/.github/workflows/stylecheck.yml @@ -0,0 +1,29 @@ +name: Stylecheck + +on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + workflow_dispatch: + +jobs: + stylecheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Install Dependencies + run: | + pip install ".[test]" + mypy html_to_django || true + mypy --install-types --non-interactive + - name: MyPy + run: mypy --strict html_to_django + - name: Pycodestyle + run: pycodestyle --max-line-length 120 html_to_django diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..04aaf4d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,27 @@ +name: Tests + +on: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + workflow_dispatch: + +jobs: + unittest: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@v4 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: pip install ".[test]" + - name: Test on Python ${{ matrix.python-version }} + run: python -m unittest discover tests --verbose diff --git a/README.md b/README.md index cfca094..7f092a5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ HTML To Django === +![tests workflow](https://github.com/truePhilipp/html_to_django/actions/workflows/tests.yml/badge.svg) +![stylecheck workflow](https://github.com/truePhilipp/html_to_django/actions/workflows/stylecheck.yml/badge.svg) + Convert HTML files with special syntax to Django template files. Installation diff --git a/tests/formatters/__init__.py b/tests/formatters/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/formatters/tests_block_formatter.py b/tests/formatters/tests_block_formatter.py new file mode 100644 index 0000000..f78dbcc --- /dev/null +++ b/tests/formatters/tests_block_formatter.py @@ -0,0 +1,20 @@ +from unittest import TestCase +from bs4 import BeautifulSoup +from html_to_django.formatters import block_formatter + + +class BlockTests(TestCase): + def test_basic(self): + soup = BeautifulSoup('
', "html.parser") + block_formatter.format(soup) + self.assertEqual("{% block content %}{% endblock %}", str(soup)) + + def test_with_content(self): + soup = BeautifulSoup('
Test
', "html.parser") + block_formatter.format(soup) + self.assertEqual("{% block content %}Test{% endblock %}", str(soup)) + + def test_with_block_inside(self): + soup = BeautifulSoup('
Test
', "html.parser") + block_formatter.format(soup) + self.assertEqual("{% block content %}{% block inner %}Test{% endblock %}{% endblock %}", str(soup)) \ No newline at end of file