cheikhaidev-ui commited on
Commit
efe72c1
·
1 Parent(s): 1c045e4

test: add pytest test suite and GitHub Actions CI (batch 3/3)

Browse files

- test(config): 5 tests for classify_risk() and QUARTIERS_DAKAR integrity
- test(features): 5 tests for create_time_features() encoding correctness
- ci: add GitHub Actions workflow (Python 3.12, pytest on push/PR to main)
- All 10 tests passing locally

.github/workflows/ci.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Set up Python 3.12
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.12"
20
+
21
+ - name: Install dependencies
22
+ run: pip install pytest pandas numpy scikit-learn lightgbm
23
+
24
+ - name: Run tests
25
+ run: pytest tests/ -v
tests/__init__.py ADDED
File without changes
tests/test_config.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from pathlib import Path
3
+
4
+ sys.path.insert(0, str(Path(__file__).parent.parent))
5
+
6
+ from src.config import classify_risk, QUARTIERS_DAKAR, QUARTIER_ADJUSTMENT
7
+
8
+
9
+ def test_classify_risk_faible():
10
+ assert classify_risk(25) == "FAIBLE"
11
+
12
+
13
+ def test_classify_risk_moyen():
14
+ assert classify_risk(55) == "MOYEN"
15
+
16
+
17
+ def test_classify_risk_eleve():
18
+ assert classify_risk(80) == "ÉLEVÉ"
19
+
20
+
21
+ def test_quartiers_count():
22
+ assert len(QUARTIERS_DAKAR) == 8
23
+
24
+
25
+ def test_adjustment_keys_match_quartiers():
26
+ assert set(QUARTIER_ADJUSTMENT.keys()) == set(QUARTIERS_DAKAR)
tests/test_features.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ from pathlib import Path
3
+ from datetime import datetime
4
+
5
+ sys.path.insert(0, str(Path(__file__).parent.parent))
6
+
7
+ from streamlit_app.utils_simple import create_time_features
8
+
9
+
10
+ def test_create_time_features_keys():
11
+ result = create_time_features(datetime(2024, 6, 15, 14, 0))
12
+ assert set(result.keys()) == {'hour', 'day_of_week', 'month', 'saison', 'is_peak_hour'}
13
+
14
+
15
+ def test_saison_juillet():
16
+ result = create_time_features(datetime(2024, 7, 1, 12, 0))
17
+ assert result['saison'] == 1
18
+
19
+
20
+ def test_saison_janvier():
21
+ result = create_time_features(datetime(2024, 1, 1, 12, 0))
22
+ assert result['saison'] == 0
23
+
24
+
25
+ def test_is_peak_hour_20h():
26
+ result = create_time_features(datetime(2024, 6, 15, 20, 0))
27
+ assert result['is_peak_hour'] == 1
28
+
29
+
30
+ def test_is_peak_hour_14h():
31
+ result = create_time_features(datetime(2024, 6, 15, 14, 0))
32
+ assert result['is_peak_hour'] == 0