Skip to content

Commit 74441db

Browse files
authored
Add unit testing (hellt#5)
added unit testing
1 parent 453dae7 commit 74441db

File tree

12 files changed

+302
-3
lines changed

12 files changed

+302
-3
lines changed

.github/workflows/cicd.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Push Docker Image
1+
name: Test, Build and Push Docker Image
22

33
"on":
44
push:
@@ -8,10 +8,31 @@ name: Build and Push Docker Image
88
pull_request:
99

1010
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: ["3.9", "3.10", "3.11", "3.12"]
16+
env:
17+
test_dir: tests
18+
steps:
19+
- name: Check out repository code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Run Python unit tests
28+
run: python -m unittest discover -s ${{ env.test_dir }}
29+
1130
docker:
1231
runs-on: ubuntu-latest
1332
permissions:
1433
packages: write
34+
needs:
35+
- "test"
1536
steps:
1637
- name: Set up QEMU
1738
uses: docker/setup-qemu-action@v3
@@ -36,12 +57,12 @@ jobs:
3657
uses: docker/login-action@v3
3758
with:
3859
registry: ghcr.io
39-
username: ${{ github.repository_owner }}
60+
username: ${{ github.actor }}
4061
password: ${{ secrets.GITHUB_TOKEN }}
4162

4263
- name: Build and push
4364
uses: docker/build-push-action@v6
4465
with:
4566
push: true
4667
platforms: linux/amd64,linux/arm64
47-
tags: ${{ steps.meta.outputs.tags }}
68+
tags: ${{ steps.meta.outputs.tags }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,6 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
164+
# vim
165+
*.swp

CONTRIBUTING.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Contributing
2+
3+
🎉 Thank you for your interest in contributing to this project! 🎉
4+
5+
A couple of quick items:
6+
7+
1. To avoid duplicate issues and PRs, [please search open issue and pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/filtering-and-searching-issues-and-pull-requests) before submitting a new one.
8+
1. The general expectation is to [submit a GitHub issue](https://help.github.com/en/github/managing-your-work-on-github/creating-an-issue) to receive feedback before submitting a pull request (PR) with changes.
9+
* _This will help ensure ideas align with the project scope._
10+
1. Unit tests should accompany [Pull Requests (PRs)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) **whenever possible**. :point_left:
11+
* This could mean adding additional tests to an existing unit test file or creating a new one.
12+
13+
## Ways to Contribute
14+
15+
(in no particular order)
16+
17+
* Code
18+
* Documentation
19+
* Expanding Unit Test coverage (where needed)
20+
* Helping others (ex: with [issue tickets](https://github.com/hellt/markdown-footnote-sorter/issues))
21+
22+
## Testing Framework
23+
24+
For minimal dependencies, the "batteries included" [Python `unittest` framework](https://docs.python.org/3/library/unittest.html) is utilized. (Other testing frameworks could be considered should additional testing features be needed.)
25+
26+
## Development Process
27+
>
28+
> This section consists of suggestions.
29+
30+
It is recommended to verify tests are successful before making any code changes. From there make your changes and run the unit tests to validate there is not code regression.
31+
32+
* [Create a fork of this project](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)
33+
* If you have an existing fork of this project be sure [to synchronize it](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork)!
34+
* From the `main` branch of your fork, [create a feature branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository)
35+
* Validate [test cases run successfully](#running-unit-tests) before any changes are made
36+
* Make modifications
37+
* Re-test with the existing unit tests against the modified codebase
38+
* Add any additional unit tests to improve testing coverage
39+
* Re-run the unit tests to confirm they run successfully
40+
* When you are satisfied with the changes and it is ready for review, [submit a Pull Request (PR)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
41+
42+
## Running Unit Tests
43+
44+
Choose one of the below testing commands methods that suits your needs.
45+
46+
> [!IMPORTANT]
47+
> The commands below are to be run from the top level of the project.
48+
49+
1. Discover and run unit tests
50+
* `python -m unittest discover`
51+
52+
1. Verbose version of unit test discovery
53+
* `python -m unittest discover -v`
54+
55+
1. Discover unit tests in specific directory (in this case, `tests`) with verbosity
56+
* `python -m unittest discover -s tests -v`
57+
58+
💡 For additional `unittest` command line options, refer to the [official Python unittest documentation](https://docs.python.org/3/library/unittest.html#command-line-interface).

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ Or download the script and put it in your `$PATH`:
2828
```bash
2929
curl -sL https://raw.githubusercontent.com/hellt/markdown-footnote-sorter/main/fnsort.py
3030
```
31+
32+
33+
## Contributing
34+
For information about contributing to this project, see the [contributing guidelines](CONTRIBUTING.md).

tests/__init__.py

Whitespace-only changes.

tests/default/example.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Footnote sorter demo
2+
3+
The text below has multiple footnotes that are all messed up. Footnote sorter will sort them for you.
4+
5+
You like hedgehogs[^1], right? Well, echidnas[^3] are like hedgehogs, but bigger and better. They're
6+
also knkown as spiny anteaters[^4], and they're one of the only mammals
7+
that lay eggs (the other
8+
being a platypus). Pretty neat eh[^2]?
9+
10+
[^2]: super cool
11+
[^1]: hedgehogs are cool, but echidnas are cooler.
12+
and soon you'll see our mascot
13+
[^3]: actually
14+
you can put complex stuff in the footnotes, like tabs
15+
/// tab | yo
16+
content
17+
///
18+
[^4]: What a name!

tests/default/example_expected.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Footnote sorter demo
2+
3+
The text below has multiple footnotes that are all messed up. Footnote sorter will sort them for you.
4+
5+
You like hedgehogs[^1], right? Well, echidnas[^2] are like hedgehogs, but bigger and better. They're
6+
also knkown as spiny anteaters[^3], and they're one of the only mammals
7+
that lay eggs (the other
8+
being a platypus). Pretty neat eh[^4]?
9+
10+
[^1]: hedgehogs are cool, but echidnas are cooler.
11+
and soon you'll see our mascot
12+
[^2]: actually
13+
you can put complex stuff in the footnotes, like tabs
14+
/// tab | yo
15+
content
16+
///
17+
[^3]: What a name!
18+
[^4]: super cool

tests/duplicates/duplicates.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Example markdown with duplicate footnotes
2+
3+
Horned lizards[^1] are pretty cool too. They're spiny like echidnas[^3], but they're messy since horned lizards [^1] squirt blood from their eyes when threatened.
4+
5+
They are also called horntoads[^2], but are classified as reptiles.
6+
7+
The horns on its head are true horns[^5] as they have a bony core, but the spines on the back are not as they are modified reptile scales to prevent water loss[^4].
8+
9+
Fifteen of the twenty-one species are native to the United States. The Texas horned lizard is not only the largest-bodied horned lizard, but also most widely distributed of the American horned lizard species [^3].
10+
11+
[^1]: the more spiky, the better
12+
[^3]: really cool
13+
[^2]: a bit of a misnomer, right?
14+
[^5]: not to be confused with antlers, since horns don't fall off each year
15+
[^4]: it's hot in the desert
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Example markdown with duplicate footnotes
2+
3+
Horned lizards[^1] are pretty cool too. They're spiny like echidnas[^2], but they're messy since horned lizards [^1] squirt blood from their eyes when threatened.
4+
5+
They are also called horntoads[^3], but are classified as reptiles.
6+
7+
The horns on its head are true horns[^4] as they have a bony core, but the spines on the back are not as they are modified reptile scales to prevent water loss[^5].
8+
9+
Fifteen of the twenty-one species are native to the United States. The Texas horned lizard is not only the largest-bodied horned lizard, but also most widely distributed of the American horned lizard species [^2].
10+
11+
[^1]: the more spiky, the better
12+
[^2]: really cool
13+
[^3]: a bit of a misnomer, right?
14+
[^4]: not to be confused with antlers, since horns don't fall off each year
15+
[^5]: it's hot in the desert
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Footnotes must be last
2+
Footnotes must be last otherwise the other content will be lost.
3+
4+
Red deer[^red_deer] are interesting as well.
5+
The range is vast with red deer native to western Europe, western Asia, parts of the Middle East, and even northern Africa[^n_africa]!
6+
There is a herd of roughly 3000 red deer living in The Netherlands' Oostvaardersplassen [^nl_reserve] (a nature reserve).
7+
The male red deer are referred to as stag or hart [^red_deer] whereas the females are doe or hind and the young are calves.
8+
9+
The size [^desc] of the red deer stags can rival that of North America elk if an ample food supply is present. Red deer are the fourth largest[^size] extant deer species behind moose, elk, and sambar deer.
10+
11+
[^nl_reserve]: https://en.wikipedia.org/wiki/Oostvaardersplassen
12+
[^n_africa]: https://en.wikipedia.org/wiki/Northern_Africa
13+
[^desc]: https://en.wikipedia.org/wiki/Red_deer#Description
14+
[^size]: https://en.wikipedia.org/wiki/Red_deer#Size
15+
[^red_deer]: https://en.wikipedia.org/wiki/Red_deer
16+
<!--- I tried to stash a comment at the bottom, but it will be shuffled around --->

0 commit comments

Comments
 (0)