Skip to content

Commit cbb8622

Browse files
authored
Merge pull request #50 from europanite/feature/wsl
Feature/wsl
2 parents 040e2ef + 4d893a1 commit cbb8622

File tree

10 files changed

+38
-40
lines changed

10 files changed

+38
-40
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ docker compose exec service bash
5555

5656
### Windows
5757

58-
```bash
58+
```powershell
5959
# Clone this repository
6060
git clone https://github.com/europanite/standard_python_environment.git
6161
cd standard_python_environment
@@ -73,5 +73,12 @@ If you use JupyterLab, just you need to access http://localhost:8888
7373

7474
---
7575

76+
### Test
77+
78+
```bash
79+
docker compose -f docker-compose.test.yml run --rm --entrypoint /bin/sh service_test -lc '
80+
pytest'
81+
```
82+
7683
## License
7784
- Apache License 2.0

docker-compose.test.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
environment:
77
- JUPYTER_PLATFORM_DIRS=1
88
- COVERAGE_FILE=/tmp/.coverage
9+
- PYTHONPATH=/
910
ports:
1011
- 8888:8888
1112
user: "0:0"
@@ -14,8 +15,8 @@ services:
1415
image: local/service-test:ci
1516
volumes:
1617
- ./service/app:/app
17-
- ./service/root/jupyter:/root/.jupyter
18-
- ./service/reports:/reports
19-
- ./service/pytest.ini:/app/pytest.ini:ro
2018
- ./service/data:/data
19+
- ./service/tests:/tests
20+
- ./service/reports:/reports
21+
- ./service/root/jupyter:/root/.jupyter
2122
command: ["pytest", "-q"]

service/Dockerfile.test

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ARG DEBIAN_FRONTEND=noninteractive
77

88
# Python dependencies
99
WORKDIR /root
10-
COPY requirements.txt requirements.test.txt ./
10+
COPY requirements.txt requirements.test.txt pytest.ini pyproject.toml ./
1111
RUN python -m pip install --upgrade pip setuptools wheel
1212
RUN pip install --no-cache-dir -r requirements.txt -r requirements.test.txt
1313

@@ -21,9 +21,6 @@ ARG HOST_GROUPNAME=group
2121
RUN groupadd -g $HOST_GID $HOST_GROUPNAME && \
2222
useradd -m -s /bin/bash -u $HOST_UID -g $HOST_GID $HOST_USERNAME
2323

24-
# App workspace
25-
WORKDIR /app
26-
2724
# User
2825
USER $HOST_USERNAME
2926

service/app/main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import os
21

32
# write your code.
4-
print("Hello World!")
5-
print("abspath:", os.path.abspath(__file__))
3+
def run():
4+
print("Hello World!")
5+
6+
if __name__ == "__main__": # pragma: no cover
7+
run() # pragma: no cover

service/app/pytest.ini

Whitespace-only changes.

service/app/tests/test_main.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

service/pytest.ini

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
testpaths = /tests
33
addopts =
44
-q
5-
--cov=.
5+
--cov=/app
66
--cov-branch
77
--cov-report=term-missing:skip-covered
88
--cov-report=xml:/reports/ci/coverage.xml
99
--cov-report=html:/reports/ci/html
1010
--cov-fail-under=80
1111
python_files = test_*.py
12-
asyncio_mode = auto
13-
asyncio_default_fixture_loop_scope = function

service/tests/test_main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import csv
2+
import os
3+
4+
from app.main import run
5+
6+
7+
def test_run(capfd):
8+
run()
9+
output, _ = capfd.readouterr()
10+
assert "Hello World!" in output
11+
12+
13+
def test_sample_csv_content():
14+
csv_path = os.path.join(os.path.dirname(__file__), "..", "data", "sample.csv")
15+
with open(csv_path, newline="") as f:
16+
reader = csv.DictReader(f)
17+
rows = list(reader)
18+
assert rows == [{"a": "1", "b": "1", "c": "1"}]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# service/tests/test_notebook.py
21
from pathlib import Path
32

43
import nbformat
54
from nbclient import NotebookClient
65

76

87
def test_workspace_notebook_runs_and_prints_hello():
9-
nb_path = Path(__file__).resolve().parents[1] / "main.ipynb"
8+
nb_path = Path(__file__).resolve().parents[1] / "app" / "main.ipynb"
109
assert nb_path.exists(), f"Notebook not found: {nb_path}"
1110

1211
nb = nbformat.read(str(nb_path), as_version=4)

0 commit comments

Comments
 (0)