Download tests/test_preprocessing.py from alaa3/TouRa: direct link, hf CLI and curl.
- Browser
- Download file 1.32 kB
-
https://huggingface.co/spaces/alaa3/TouRa/resolve/main/tests/test_preprocessing.py
- Command line
-
hf download hf://spaces/alaa3/TouRa/tests/test_preprocessing.py
-
curl -L -o test_preprocessing.py https://huggingface.co/spaces/alaa3/TouRa/resolve/main/tests/test_preprocessing.py
1.32 kB
| """ | |
| Unit tests for the preprocessing pipeline. | |
| """ | |
| import pytest | |
| import pandas as pd | |
| from app.services.preprocessing import extract_city, filter_by_city, dataframe_to_json_string | |
| def test_extract_city_known(): | |
| assert extract_city("123 Street, Cairo, Egypt") == "Cairo" | |
| assert extract_city("Near Luxor Temple, Luxor") == "Luxor" | |
| def test_extract_city_none(): | |
| assert extract_city(None) is None | |
| assert extract_city(float("nan")) is None | |
| def test_extract_city_unknown(): | |
| result = extract_city("Some unknown village far away") | |
| assert result is None | |
| def test_filter_by_city(): | |
| df = pd.DataFrame({ | |
| "name": ["Place A", "Place B", "Place C"], | |
| "city": ["Cairo", "Luxor", "Cairo"], | |
| }) | |
| filtered = filter_by_city(df, "Cairo") | |
| assert len(filtered) == 2 | |
| assert set(filtered["name"]) == {"Place A", "Place C"} | |
| def test_filter_by_city_case_insensitive(): | |
| df = pd.DataFrame({"name": ["X"], "city": ["Luxor"]}) | |
| filtered = filter_by_city(df, "luxor") | |
| assert len(filtered) == 1 | |
| def test_dataframe_to_json_string(): | |
| df = pd.DataFrame({"a": [1, 2], "b": ["x", "y"]}) | |
| result = dataframe_to_json_string(df) | |
| import json | |
| parsed = json.loads(result) | |
| assert isinstance(parsed, list) | |
| assert len(parsed) == 2 | |
| assert parsed[0]["a"] == 1 | |