Skip to content

Commit 36bb72f

Browse files
authored
Merge pull request #29 from pythonhealthdatascience/dev
Dev
2 parents 4ff198d + 3c7ad1e commit 36bb72f

71 files changed

Lines changed: 1074 additions & 399 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.lintr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
linters: linters_with_defaults(object_usage_linter = NULL)
2+
exclusions: "pages/code"

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[main]
2+
check-quote-consistency = yes

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
This file is for contributors. It describes how the `stars-testing-intro` site is set-up and quality controlled.
44

5+
## Linting
6+
7+
Simply run from terminal:
8+
9+
```
10+
bash lint.sh
11+
```
12+
513
## Example code
614

715
The example code is contained in `examples`.

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Imports:
44
devtools
55
DT
66
knitr
7+
lintr
78
patrick
89
reticulate
910
rmarkdown

_quarto.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ website:
2626
- pages/write_basic_test.qmd
2727
- pages/run_tests.qmd
2828
- pages/parametrising_tests.qmd
29+
- pages/temp_mock.qmd
2930
- section: Types of test
3031
contents:
3132
- pages/smoke_tests.qmd
3233
- pages/unit_tests.qmd
33-
- pages/functional_tests.qmd
34-
- pages/back_tests.qmd
34+
- pages/system_tests.qmd
35+
- pages/regression_tests.qmd
3536
- pages/break.qmd
3637
- pages/test_coverage.qmd
3738
- pages/github_actions.qmd

assets/styles.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
padding: 1em 1em 0.2em 1em;
4646
margin-bottom: 1em;
4747
}
48+
.box-green {
49+
background-color: #d3ebba;
50+
border-radius: 8px;
51+
padding: 1em 1em 0.2em 1em;
52+
margin-bottom: 1em;
53+
}
54+
.box-red {
55+
background-color: #fbcbca;
56+
border-radius: 8px;
57+
padding: 1em 1em 0.2em 1em;
58+
margin-bottom: 1em;
59+
}
4860

4961
/* Add space before H2 + H3 */
5062
h2 {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Using mocking to provide CSV data to a test
3+
"""
4+
5+
import pandas as pd
6+
7+
from waitingtimes.patient_analysis import import_patient_data
8+
9+
def test_mocking(monkeypatch):
10+
"""Providing data to a test via mocking"""
11+
12+
# Create sample patient data
13+
testdata = pd.DataFrame(
14+
[["p1", "2024-01-01", "08:00", "2024-01-01", "09:00"]],
15+
columns=[
16+
"PATIENT_ID", "ARRIVAL_DATE", "ARRIVAL_TIME",
17+
"SERVICE_DATE", "SERVICE_TIME",
18+
],
19+
)
20+
21+
# Define a fake CSV reader that just returns our DataFrame
22+
def mock_read_csv(path):
23+
return testdata
24+
25+
# Temporarily replace pd.read_csv with our fake version
26+
monkeypatch.setattr(pd, "read_csv", mock_read_csv)
27+
28+
# Call the function with any path - it does not matter - it will use the
29+
# mocked reader, and pd.read_csv is never actually called
30+
df = import_patient_data("does_not_matter.csv")
31+
assert not df.empty
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Importing a real data file to a test
3+
"""
4+
5+
from pathlib import Path
6+
7+
from waitingtimes.patient_analysis import import_patient_data
8+
9+
def test_real_data_file():
10+
"""Importing a real data file to a test"""
11+
12+
# Path to example test data
13+
csv_path = Path(__file__).parent.joinpath("data/patient_data.csv")
14+
15+
# Load the data and check it was read
16+
df = import_patient_data(csv_path)
17+
assert not df.empty
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Using temporary file to provide CSV to a test
3+
"""
4+
5+
import pandas as pd
6+
7+
from waitingtimes.patient_analysis import import_patient_data
8+
9+
def test_temporary_file(tmp_path):
10+
"""Providing data to a test via a temporary file"""
11+
12+
# Create sample patient data
13+
testdata = pd.DataFrame(
14+
[["p1", "2024-01-01", "08:00", "2024-01-01", "09:00"]],
15+
columns=[
16+
"PATIENT_ID", "ARRIVAL_DATE", "ARRIVAL_TIME",
17+
"SERVICE_DATE", "SERVICE_TIME",
18+
],
19+
)
20+
21+
# Create a temporary CSV file
22+
csv_path = tmp_path / "patients.csv"
23+
testdata.to_csv(csv_path, index=False)
24+
25+
# Load the data and check it was read
26+
df = import_patient_data(csv_path)
27+
assert not df.empty

examples/python_package/tests/test_back.py renamed to examples/python_package/tests/test_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Back testing.
2+
Regression testing.
33
"""
44

55
from pathlib import Path

0 commit comments

Comments
 (0)