Coverage for tests / test_multiple_download.py: 93%
54 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-11 16:02 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-11 16:02 +0000
1"""
2Tests for downloads of irregular cases.
3"""
5import unittest
6from pathlib import Path
7from functools import partial
9import pandas as pd
11import acspsuedo.query as apq
12from acspsuedo.datasets import ACS5_SUBJECT
13from acspsuedo.fips.states import NORTH_DAKOTA, MINNESOTA, NEW_YORK, NEVADA
14from acspsuedo.source.low.exceptions import APIException
18apq.shapefile_handler.cache_path = Path.cwd() / 'tests' / 'cache'
22class TestMultipleDownload(unittest.TestCase):
24 def setUp(self) -> None:
25 self.DATASET = ACS5_SUBJECT
27 self.North_Dakota_CD_download = partial(
28 apq.download,
29 dataset = ACS5_SUBJECT,
30 variables = 'NAME',
31 state = NORTH_DAKOTA,
32 congressional_district = '*',
33 include_geometries = True
34 )
36 self.Minnesota_PUMA_download = partial(
37 apq.download,
38 dataset = ACS5_SUBJECT,
39 variables = 'NAME',
40 state = MINNESOTA,
41 public_use_microdata_area = '*',
42 include_geometries = True
43 )
45 self.UA_download = partial(
46 apq.download,
47 dataset = ACS5_SUBJECT,
48 variables = 'NAME',
49 urban_area = '*',
50 include_geometries = True
51 )
54 def test_lacking_state_outer_scope_nation_wide_congressional_districts_2024_download(self) -> None:
55 """
56 Simulate a scenario where a user queries a certain scope (congressional
57 districts in 2024) that requires a state outer-scope (for geographic info
58 from TIGER shapefiles).
60 Note that we have proxied this via two states, New York and Nevada,
61 because of server-based blocking.
62 """
63 NY_NV_congressional_districts = pd.DataFrame({
64 'STATE': [NEVADA, NEW_YORK],
65 'CONGRESSIONAL_DISTRICT': ['01', '01'],
66 'YEAR': [2024, 2024],
67 })
68 apq._get_shpfile(NY_NV_congressional_districts, 2024, congressional_district = '*')
71 def test_ND_congressional_districts_2010_download(self) -> None:
72 """
73 Tests for congressional districts in North Dakota for 2010.
74 """
75 self.North_Dakota_CD_download(year = 2010)
77 def test_ND_congressional_districts_2014_download(self) -> None:
78 """
79 Tests for congressional districts in North Dakota for 2014.
80 """
81 self.North_Dakota_CD_download(year = 2014)
83 def test_ND_congressional_districts_2020_download(self) -> None:
84 """
85 Tests for congressional districts in North Dakota for 2020.
86 """
87 self.North_Dakota_CD_download(year = 2020)
89 def test_ND_congressional_districts_2024_download(self) -> None:
90 """
91 Tests for congressional districts in North Dakota for 2024.
92 """
93 self.North_Dakota_CD_download(year = 2024)
97 def test_MN_public_use_microdata_area_2008_download(self) -> None:
98 """
99 Tests for public use microdata areas in Minnesota for 2008.
100 """
101 with self.assertRaises(APIException):
102 self.Minnesota_PUMA_download(year = 2008)
104 def test_MN_public_use_microdata_area_2010_download(self) -> None:
105 """
106 Tests for public use microdata areas in Minnesota for 2010.
107 """
108 self.Minnesota_PUMA_download(year = 2010)
110 def test_MN_public_use_microdata_area_2014_download(self) -> None:
111 """
112 Tests for public use microdata areas in Minnesota for 2014.
113 """
114 self.Minnesota_PUMA_download(year = 2014)
116 def test_MN_public_use_microdata_area_2020_download(self) -> None:
117 """
118 Tests for public use microdata areas in Minnesota for 2020.
119 """
120 self.Minnesota_PUMA_download(year = 2020)
122 def test_MN_public_use_microdata_area_2024_download(self) -> None:
123 """
124 Tests for public use microdata areas in Minnesota for 2024.
126 *Note*: At the time of testing (April 16, 2025), Minnesota PUMA
127 geographies aren't returned despite the correct URL (server error?).
128 In any case, we use a try-except block.
129 """
130 try:
131 self.Minnesota_PUMA_download(year = 2024)
132 except:
133 # Returns html content
134 with self.assertRaises(APIException):
135 self.Minnesota_PUMA_download(year = 2024)
139 def test_urban_area_2008_download(self) -> None:
140 """
141 Tests for urban areas for 2008.
142 """
143 with self.assertRaises(APIException):
144 self.UA_download(year = 2008)
146 def test_urban_area_2010_download(self) -> None:
147 """
148 Tests for urban areas for 2010.
149 """
150 self.UA_download(year = 2010)
152 def test_urban_area_2015_download(self) -> None:
153 """
154 Tests for urban areas for 2015.
155 """
156 self.UA_download(year = 2015)
158 def test_urban_area_2021_download(self) -> None:
159 """
160 Tests for urban areas for 2021.
161 """
162 self.UA_download(year = 2021)
164 def test_urban_area_2024_download(self) -> None:
165 """
166 Tests for urban areas for 2024.
167 """
168 self.UA_download(year = 2024)
172if __name__ == '__main__':
173 unittest.main()