Coverage for tests/test_other.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-07-22 06:43 -0400

1"""Test miscelaneous functions in the project.""" 

2 

3import json 

4import pytest 

5from src.overturetoosm import objects, segments 

6 

7 

8@pytest.fixture(name="props_dict") 

9def props_fix() -> dict: 

10 """Fixture with the clean segment properties.""" 

11 return { 

12 "property": "", 

13 "dataset": "OpenStreetMap", 

14 "record_id": "w590831817", 

15 "update_time": None, 

16 "confidence": None, 

17 } 

18 

19 

20def test_util_source() -> None: 

21 """Test the source statement function.""" 

22 source_1 = objects.Sources( 

23 **{"property": "property1", "dataset": "dataset1", "confidence": 0.8} 

24 ) 

25 source_2 = objects.Sources( 

26 **{"property": "property2", "dataset": "dataset2", "confidence": 0.8} 

27 ) 

28 

29 assert ( 

30 objects.source_statement([source_1, source_2]) 

31 == "dataset1, dataset2 via overturetoosm" 

32 ) 

33 

34 

35def test_segment_sources(props_dict: dict) -> None: 

36 """Test that source URL is processed correctly.""" 

37 source = objects.Sources(**props_dict) 

38 assert source.get_osm_link() == "https://www.openstreetmap.org/way/590831817" 

39 

40 

41def test_segment_sources_not_osm(props_dict: dict) -> None: 

42 """Test that source URL is processed correctly.""" 

43 props_dict.update({"dataset": "dataset1"}) 

44 source = objects.Sources(**props_dict) 

45 assert source.get_osm_link() == None 

46 

47 

48@pytest.mark.parametrize( 

49 "type", 

50 [ 

51 ("place", objects.PlaceProps), 

52 ("building", objects.BuildingProps), 

53 ("address", objects.AddressProps), 

54 ("segment", segments.SegmentProperties), 

55 ], 

56) 

57def test_objects(type) -> None: 

58 """Test that all properties are processed correctly.""" 

59 with open(f"scripts/test_{type[0]}.geojson", encoding="utf-8") as f: 

60 data = json.load(f) 

61 

62 for feature in data["features"]: 

63 type[1](**feature["properties"])