Skip to content

Commit c02027f

Browse files
committed
Add pytest and tests for CLI and Python module
- Add pytest configuration for test management - Implement test suite for CLI functionality and Python module - Update README with testing instructions and badge - Fix Dockerfile - Create .dockerignore to exclude unnecessary files from Docker builds - Add GitHub Actions workflows for testing - Clean up makefile to include test commands
1 parent 2eec5fa commit c02027f

File tree

11 files changed

+796
-9
lines changed

11 files changed

+796
-9
lines changed

.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build artifacts
2+
*.o
3+
*.so
4+
*.pyc
5+
imctermite
6+
main.cpp.cpp
7+
8+
# Python build
9+
python/build/
10+
python/dist/
11+
python/*.so
12+
python/*.cpp
13+
python/lib/
14+
python/LICENSE
15+
python/README.md
16+
python/*.egg-info/
17+
__pycache__/
18+
19+
# Git and editor
20+
.git/
21+
.venv/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# Test outputs
27+
.pytest_cache/

.github/workflows/pypi-deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ on:
88

99
jobs:
1010

11+
test:
12+
uses: ./.github/workflows/test.yml
13+
1114
build_setup:
1215
name: Prepare environment for wheel builds
1316
runs-on: ubuntu-24.04
17+
needs: [test]
1418
steps:
1519
- uses: actions/checkout@v2
1620
- name: Prepare wheel build

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Build Docker image
18+
run: docker build -t imctermite .
19+
20+
- name: Run tests in container
21+
run: docker run --rm imctermite make test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ python/*.soc
4343
python/lib/
4444
python/*.cpp
4545
python/wheelhouse/
46+
47+
__pycache__/
48+
.pytest_cache/

Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
2-
FROM debian:bullseye-20210111
1+
FROM debian:bullseye
32

43
USER root
54

65
RUN apt-get update && apt-get install -y \
76
build-essential git vim \
87
python3 python3-pip
9-
RUN python3 -m pip install cython
8+
RUN python3 -m pip install cython pytest
9+
RUN ln -s /usr/bin/python3 /usr/bin/python
1010

1111
RUN g++ -v
1212

13-
COPY ./ /IMCtermite/
13+
WORKDIR /IMCtermite
14+
COPY ./ .
1415

1516
# install CLI tool
16-
RUN cd /IMCtermite && ls -lh && make install && ls -lh /usr/local/bin/imctermite
17+
RUN make install
1718

1819
# install Python module
19-
RUN cd /IMCtermite && ls -lh && make cython-install
20+
RUN make python-build
2021

2122
CMD ["sleep","infinity"]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
[![LICENSE](https://img.shields.io/github/license/RecordEvolution/IMCtermite)](https://img.shields.io/github/license/RecordEvolution/IMCtermite)
33
[![STARS](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)](https://img.shields.io/github/stars/RecordEvolution/IMCtermite)
4+
![Tests](https://github.com/RecordEvolution/IMCtermite/actions/workflows/test.yml/badge.svg)
45
![CI Build Wheel](https://github.com/RecordEvolution/IMCtermite/actions/workflows/pypi-deploy.yml/badge.svg?branch=&event=push)
56
[![PYPI](https://img.shields.io/pypi/v/IMCtermite.svg)](https://pypi.org/project/imctermite/)
67

@@ -27,6 +28,7 @@ Python module to integrate the _.raw_ format into any ETL workflow.
2728
* [File format](#Fileformat)
2829
* [Build and Installation](#Installation)
2930
* [Usage and Examples](#Usage)
31+
* [Testing](#Testing)
3032
* [References](#References)
3133

3234
## File format
@@ -217,6 +219,12 @@ A more complete [example](python/examples/usage.py), including the methods for
217219
obtaining the channels, i.a. their data and/or directly printing them to files,
218220
can be found in the `python/examples` folder.
219221

222+
## Testing
223+
224+
Run end-to-end tests: `make test`
225+
226+
See [tests/README.md](tests/README.md) for details.
227+
220228
## References
221229

222230
### IMC

makefile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ INST := /usr/local/bin
3535
# C++ and CLI tool
3636

3737
# build executable
38-
$(EXE): check-tags $(GVSN) main.o
38+
$(EXE): check-tags main.o
3939
$(CC) $(OPT) main.o -o $@
4040

4141
# build main.cpp and include git version/commit tag
@@ -86,7 +86,7 @@ docker-run:
8686
#-----------------------------------------------------------------------------#
8787
# python
8888

89-
python-build: check-tags $(GVSN)
89+
python-build: check-tags
9090
make -C python/ build-inplace
9191
cp python/imctermite*.so ./ -v
9292

@@ -97,10 +97,29 @@ python-clean:
9797
python-test:
9898
PYTHONPATH=./ python python/examples/usage.py
9999

100+
#-----------------------------------------------------------------------------#
101+
# tests
102+
103+
test: $(EXE) python-build
104+
@echo "Running all tests..."
105+
@PYTHONPATH=./ pytest
106+
107+
test-cli: $(EXE)
108+
@echo "Running CLI tests..."
109+
@PYTHONPATH=./ pytest tests/test_cli.py
110+
111+
test-python: python-build
112+
@echo "Running Python tests..."
113+
@PYTHONPATH=./ pytest tests/test_python.py
114+
100115
#-----------------------------------------------------------------------------#
101116
# clean
102117

103-
clean: cpp-clean python-clean
118+
test-clean:
119+
rm -rf .pytest_cache
120+
find tests/ -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
121+
122+
clean: cpp-clean python-clean test-clean
104123

105124
#-----------------------------------------------------------------------------#
106125
# github actions

pytest.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[pytest]
2+
testpaths = tests
3+
pythonpath = .
4+
python_files = test_*.py
5+
python_classes = Test*
6+
python_functions = test_*
7+
addopts = -v --strict-markers --tb=short
8+
markers =
9+
slow: marks tests as slow (deselect with '-m "not slow"')

tests/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# IMCtermite Tests
2+
3+
End-to-end tests for both the CLI tool and Python module.
4+
5+
6+
## Running Tests
7+
8+
### All Tests
9+
```bash
10+
make test # Via makefile (builds if needed)
11+
pytest # Direct pytest
12+
```
13+
14+
### CLI Tests Only
15+
```bash
16+
make test-cli
17+
pytest tests/test_cli.py
18+
```
19+
20+
### Python Module Tests Only
21+
```bash
22+
make test-python
23+
pytest tests/test_python.py
24+
```
25+
26+
## Prerequisites
27+
28+
```bash
29+
pip install cython pytest setuptools
30+
```

0 commit comments

Comments
 (0)