Skip to content

Commit b5af732

Browse files
authored
Initial Test Suite (#58)
* basic tests on tile macro * empty id error fix * fixed invalid img attributes * fix missing alt attribute * add img_width and img_height to docs * test that img width and height are set by the image macro * refactor make * only run pytest on mac/linux * future test for breaking change
1 parent 83e5568 commit b5af732

22 files changed

+386
-72
lines changed

.github/workflows/test.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@ jobs:
88
test:
99
strategy:
1010
matrix:
11-
# python: ['3.7']
12-
# platform: ['ubuntu-latest']
1311
python: ['3.7', '3.8', '3.9', '3.10']
1412
platform: [ubuntu-latest, macos-latest, windows-latest]
1513
runs-on: ${{ matrix.platform }}
1614
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v3
19-
- name: Set up Python ${{ matrix.python }}
20-
uses: actions/setup-python@v3
21-
with:
22-
python-version: ${{ matrix.python }}
23-
- name: Install test dependencies
24-
run: python -m pip install -U tox
25-
- name: Test
26-
run: python -m tox -e py
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Set up Python ${{ matrix.python }}
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: ${{ matrix.python }}
21+
- if: ${{ matrix.platform == 'ubuntu-latest' }}
22+
name: (ubuntu) Install Testing Prereqs
23+
run: |
24+
make USE_SUDO=1 install-test-prereqs
25+
- if: ${{ matrix.platform == 'macos-latest' }}
26+
name: (macos) Install Testing Prereqs
27+
run: |
28+
brew install tidy-html5
29+
- name: Install Tox
30+
run: make install-tox
31+
- name: Test Build/Package with Tox
32+
run: python -m tox -e py
33+
- if: ${{ matrix.platform == 'ubuntu-latest' }}
34+
name: (ubuntu) Run Tox pytests
35+
run: |
36+
python -m tox -e pytest-linux
37+
- if: ${{ matrix.platform == 'macos-latest' }}
38+
name: (macos) Run Tox pytests
39+
run: |
40+
python -m tox -e pytest-darwin
41+

DEVELOPER_README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ make tox
127127
```
128128

129129
### Add Tests
130-
Test suite setup is not complete yet. See progress on this issue [here](https://github.com/ntno/mkdocs-terminal/issues/13). If you have experience creating automated tests for Jinja2 please consider making a contribution!
130+
Test suite setup is in progress. See [GitHub issue](https://github.com/ntno/mkdocs-terminal/issues/13) for details. If you have experience creating automated tests for Jinja2 please consider making a contribution!
131131

132132
### Push Changes and Create PR
133133
See [Work On Pull Request](https://github.com/susam/gitpr#work-on-pull-request) for help on adding/pushing changes to your feature branch.

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ exclude CONTRIBUTING.md
1313
exclude CODE_OF_CONDUCT.md
1414
exclude DEVELOPER_README.md
1515
exclude SECURITY.md
16-
exclude package-lock.json
16+
exclude package-lock.json
17+
exclude requirements.test.txt

Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version=$(shell cat package.json | jq .version -r)
22

3+
ifeq ($(USE_SUDO),1)
4+
SUDO_FLAG = sudo
5+
endif
36

47
.PHONY: check-version-match clean
58

@@ -52,15 +55,27 @@ clean-node:
5255

5356
clean: clean-dist clean-node
5457

55-
install-tox-requirements:
58+
install-test-prereqs:
59+
$(SUDO_FLAG) apt-get update && $(SUDO_FLAG) apt install -y tidy
60+
61+
install-test-requirements:
62+
pip install -r requirements.test.txt
63+
64+
install-tox:
5665
python -m pip install -U tox
5766

58-
tox: install-tox-requirements
59-
python -m tox -e py
67+
tox: install-tox install-test-prereqs
68+
python -m tox -e py
69+
python -m tox -e pytest-linux
6070

6171
check-version-match:
6272
cat terminal/theme_version.html | grep -s --silent $(version)\"\>\$$ -o
6373

74+
#for developer use, assumes you have already installed prereqs
75+
quick-tests:
76+
flake8 --ignore E501
77+
pytest --color=yes --capture=no tests
78+
6479
check-site:
6580
ifndef site
6681
$(error site is not set)

NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Terminal for MkDocs' Tile Grid relies on the *meta*[^mkdocs-page-meta] attribute
3535
- img: https://picsum.photos/id/{id}/200/200
3636
- to read: [Make for devops](https://alexharv074.github.io/2019/12/26/gnu-make-for-devops-engineers.html)
3737
- to read: [testing bash scripts](https://alexharv074.github.io/2017/07/07/unit-testing-a-bash-script-with-shunit2.html)
38+
- [pytidylib](https://pythonhosted.org/pytidylib/)

documentation/docs/tile-grid/tile.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ A tile can represent an image, a link, or a linked image.
3333

3434
: Alternate text for the image if the image cannot be displayed.
3535

36+
`img_width`
37+
38+
: Width to set on the image element.
39+
40+
`img_height`
41+
42+
: Height to set on the image element.
43+
3644
`link_href`
3745

3846
: Web page URL. Can be an external web page or an internal MkDocs page like `./default/`.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mkdocs-terminal",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Terminal.css theme for MkDocs",
55
"keywords": [
66
"mkdocs",
@@ -25,4 +25,4 @@
2525
"engines": {
2626
"node": ">= 16"
2727
}
28-
}
28+
}

requirements.test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mkdocs
2+
pytest > 7
3+
pytidylib >= 0.3.2

terminal/macros/tile-image.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% macro make_image( tile ) -%}
22
<img src="{{ tile.img_src }}"
33
{% if tile.img_title is defined and tile.img_title|length %}title="{{ tile.img_title }}"{% endif %}
4-
{% if tile.img_alt is defined and tile.img_alt|length %}alt="{{ tile.img_alt }}"{% endif %}
5-
width="{{ tile.img_width|default('auto', true ) }}"
6-
height="{{ tile.img_height|default('auto', true ) }}"
4+
alt="{{ tile.img_alt|default('', true ) }}"
5+
{% if tile.img_width is defined and tile.img_width|length %}width="{{ tile.img_width }}"{% endif %}
6+
{% if tile.img_height is defined and tile.img_height|length %}height="{{ tile.img_height }}"{% endif %}
77
>
88
{%- endmacro -%}

0 commit comments

Comments
 (0)