Coverage for tests/test_buildings.py: 100%

36 statements  

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

1"""Test the buildings.py module.""" 

2 

3from typing import Any 

4 

5import pytest 

6 

7from src.overturetoosm.buildings import process_building 

8from src.overturetoosm.objects import ConfidenceError 

9 

10 

11@pytest.fixture(name="clean_dict") 

12def clean_fix() -> dict[str, Any]: 

13 """Fixture with the clean building properties.""" 

14 return { 

15 "building": "parking", 

16 "building:levels": 4, 

17 "building:levels:underground": 1, 

18 "height": 21.34, 

19 "source": "metaLidarExtractions, microsoftMLBuildings via overturetoosm", 

20 "name": "Clarendon Family Dentistry", 

21 } 

22 

23 

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

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

26 """Fixture with the raw building properties.""" 

27 return { 

28 "theme": "buildings", 

29 "type": "building", 

30 "version": 1, 

31 "level": 1, 

32 "height": 21.34, 

33 "has_parts": False, 

34 "num_floors": 4, 

35 "names": { 

36 "primary": "Clarendon Family Dentistry", 

37 "common": None, 

38 "rules": None, 

39 }, 

40 "num_floors_underground": 1, 

41 "subtype": "transportation", 

42 "class": "parking", 

43 "is_underground": False, 

44 "sources": [ 

45 {"property": "", "dataset": "microsoftMLBuildings,", "confidence": 0.7}, 

46 { 

47 "property": "/properties/height", 

48 "dataset": "metaLidarExtractions,", 

49 "confidence": 0.45, 

50 }, 

51 ], 

52 } 

53 

54 

55def test_process_building(props_dict: dict, clean_dict: dict) -> None: 

56 """Test the process_building function.""" 

57 props = process_building(props_dict) 

58 assert props == clean_dict 

59 

60 

61def test_process_building_confidence(props_dict: dict) -> None: 

62 """Test the process_building function.""" 

63 with pytest.raises(ConfidenceError): 

64 process_building(props_dict, confidence=0.9) 

65 

66 

67def test_process_building_underground(props_dict: dict, clean_dict: dict) -> None: 

68 """Test the process_building function.""" 

69 props_dict["is_underground"] = True 

70 props = process_building(props_dict) 

71 clean_dict["location"] = "underground" 

72 assert props == clean_dict 

73 

74 

75def test_process_building_no_floors(props_dict: dict, clean_dict: dict) -> None: 

76 """Test the process_building function.""" 

77 props_dict.pop("num_floors", None) 

78 props = process_building(props_dict) 

79 clean_dict.pop("building:levels", None) 

80 assert props == clean_dict 

81 

82 

83def test_process_building_underfloors(props_dict: dict, clean_dict: dict) -> None: 

84 """Test the process_building function.""" 

85 props_dict.pop("num_floors_underground", None) 

86 props = process_building(props_dict) 

87 clean_dict.pop("building:levels:underground", None) 

88 assert props == clean_dict 

89 

90 

91def test_process_building_min_level(props_dict: dict, clean_dict: dict) -> None: 

92 """Test the process_building function.""" 

93 props_dict["min_floor"] = 2 

94 props = process_building(props_dict) 

95 clean_dict["building:min_level"] = 2 

96 assert props == clean_dict