Coverage for tests/test_buildings.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.6.0, created at 2024-07-28 10:12 -0400

1from copy import deepcopy 

2from typing import Any, Dict 

3import pytest 

4import pydantic 

5from src.overturetoosm.buildings import ( 

6 process_building, 

7) 

8from src.overturetoosm.objects import ConfidenceError 

9 

10 

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

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

13 return { 

14 "building": "parking", 

15 "building:levels": 4, 

16 "building:levels:underground": 1, 

17 "height": 21.34, 

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

19 } 

20 

21 

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

23def props_fix() -> Dict[str, Any]: 

24 return { 

25 "theme": "buildings", 

26 "type": "building", 

27 "version": 1, 

28 "level": 1, 

29 "height": 21.34, 

30 "num_floors": 4, 

31 "num_floors_underground": 1, 

32 "subtype": "transportation", 

33 "class": "parking", 

34 "is_underground": False, 

35 "sources": [ 

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

37 { 

38 "property": "/properties/height", 

39 "dataset": "metaLidarExtractions,", 

40 "confidence": 0.45, 

41 }, 

42 ], 

43 } 

44 

45 

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

47 """Test the process_building function""" 

48 props = process_building(props_dict) 

49 assert props == clean_dict 

50 

51 

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

53 """Test the process_building function""" 

54 with pytest.raises(ConfidenceError): 

55 process_building(props_dict, confidence=0.9) 

56 

57 

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

59 """Test the process_building function""" 

60 props_dict["is_underground"] = True 

61 props = process_building(props_dict) 

62 clean_dict["location"] = "underground" 

63 assert props == clean_dict 

64 

65 

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

67 """Test the process_building function""" 

68 props_dict.pop("num_floors", None) 

69 props = process_building(props_dict) 

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

71 assert props == clean_dict 

72 

73 

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

75 """Test the process_building function""" 

76 props_dict.pop("num_floors_underground", None) 

77 props = process_building(props_dict) 

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

79 assert props == clean_dict 

80 

81 

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

83 """Test the process_building function""" 

84 props_dict["min_floor"] = 2 

85 props = process_building(props_dict) 

86 clean_dict["building:min_level"] = 2 

87 assert props == clean_dict