Coverage for tests/test_segments.py: 100%

20 statements  

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

1"""Test the segments.py module.""" 

2 

3from typing import Any 

4 

5import pytest 

6from pydantic import ValidationError 

7 

8from src.overturetoosm.segments import SegmentProperties 

9# from src.overturetoosm.objects import ConfidenceError 

10 

11 

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

13def props_fix() -> dict[str, Any]: 

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

15 return { 

16 "id": "0892aa87b057ffff043ffa50b0c799df", 

17 "version": 0, 

18 "sources": [ 

19 { 

20 "property": "", 

21 "dataset": "OpenStreetMap", 

22 "record_id": "w590831817", 

23 "update_time": None, 

24 "confidence": None, 

25 } 

26 ], 

27 "subtype": "road", 

28 "class": "secondary", 

29 "names": { 

30 "primary": "South Arlington Ridge Road", 

31 "common": None, 

32 "rules": None, 

33 }, 

34 "level": 3, 

35 "connector_ids": [ 

36 "08f2aa87b042d070047f7e4ae29f3ddf", 

37 "08f2aa87b0553085043f7b50915fc2f9", 

38 "08f2aa87b0550799043f5e54b6721dab", 

39 "08f2aa87b055042c043d5f567e660ef3", 

40 ], 

41 "road_surface": [{"value": "paved", "between": None}], 

42 "speed_limits": [ 

43 { 

44 "min_speed": None, 

45 "max_speed": {"value": 25, "unit": "mph"}, 

46 "is_max_speed_variable": None, 

47 "when": None, 

48 "between": None, 

49 } 

50 ], 

51 } 

52 

53 

54def test_segment_props(props_dict: dict) -> None: 

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

56 new_props = SegmentProperties(**props_dict) 

57 assert isinstance(new_props, SegmentProperties) 

58 

59 

60@pytest.mark.parametrize( 

61 "remove_key", ["road_surface", "speed_limits", "sources", "level", "names"] 

62) 

63def test_segment_props_no_tags(props_dict: dict, remove_key: str) -> None: 

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

65 props_dict.pop(remove_key, None) 

66 new_props = SegmentProperties(**props_dict) 

67 assert isinstance(new_props, SegmentProperties) 

68 

69 

70@pytest.mark.parametrize("remove_key", ["id", "version", "subtype"]) 

71def test_segment_props_no_id(props_dict: dict, remove_key: str) -> None: 

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

73 props_dict.pop(remove_key, None) 

74 with pytest.raises(ValidationError): 

75 SegmentProperties(**props_dict) 

76 

77 

78# def test_segment_props_no_class(props_dict: dict) -> None: 

79# """Test that all properties are processed correctly.""" 

80# props_dict.pop("class", None) 

81# new_props = SegmentProperties(**props_dict).model_dump(exclude_none=True) 

82# assert isinstance(new_props, dict)