Coverage for tests/test_addresses.py: 100%

18 statements  

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

1"""Tests for the address module.""" 

2 

3from typing import Any 

4 

5import pytest 

6 

7from src.overturetoosm.addresses import process_address 

8 

9 

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

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

12 """Fixture with the clean address properties.""" 

13 return { 

14 "addr:country": "US", 

15 "addr:postcode": "02459", 

16 "addr:street": "COMMONWEALTH AVE", 

17 "addr:housenumber": "1000", 

18 "addr:state": "MA", 

19 "source": "NAD via overturetoosm", 

20 } 

21 

22 

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

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

25 """Fixture with the raw address properties.""" 

26 return { 

27 "theme": "addresses", 

28 "type": "address", 

29 "version": 0, 

30 "country": "US", 

31 "address_levels": [{"value": "MA"}, {"value": "NEWTON CENTRE"}], 

32 "postcode": "02459", 

33 "street": "COMMONWEALTH AVE", 

34 "number": "1000", 

35 "sources": [ 

36 { 

37 "property": "", 

38 "dataset": "NAD", 

39 "record_id": None, 

40 "update_time": None, 

41 "confidence": None, 

42 } 

43 ], 

44 } 

45 

46 

47def test_process_address(props_dict, clean_dict) -> None: 

48 """Test that address properties are processed correctly.""" 

49 assert process_address(props_dict) == clean_dict 

50 

51 

52def test_process_address_no_levels(props_dict, clean_dict) -> None: 

53 """Test that address properties are processed correctly.""" 

54 props_dict.pop("address_levels", None) 

55 clean_dict.pop("addr:state", None) 

56 assert process_address(props_dict) == clean_dict 

57 

58 

59def test_process_address_not_us(props_dict, clean_dict) -> None: 

60 """Test that address properties are processed correctly.""" 

61 clean_dict.pop("addr:state", None) 

62 assert process_address(props_dict, style="CA") == clean_dict