TigerFetch.jl

Download TIGER/Line shapefiles from the US Census Bureau
Log | Files | Refs | README | LICENSE

assets.jl (3845B)


      1 # ABOUTME: Tests for artifact installation and reference data integrity
      2 # ABOUTME: Validates bundled FIPS state/county files, their structure, and data processing functions
      3 
      4 @testset "Asset Installation Tests" begin
      5     @testset "Artifact Configuration" begin
      6 
      7 
      8         artifact_toml = joinpath(@__DIR__, "..", "..", "Artifacts.toml")
      9         @test isfile(artifact_toml)
     10         @test_nowarn ensure_artifact_installed("fips_state_county_list", artifact_toml)
     11 
     12         # Test that the artifact path is valid
     13         artifact_path = TigerFetch.artifact_dir()
     14         @test isdir(artifact_path)
     15 
     16         # Test that both expected files exist in artifact
     17         @test isfile(joinpath(artifact_path, "national_county2020.txt"))
     18         @test isfile(joinpath(artifact_path, "national_state2020.txt"))
     19 
     20     end
     21 
     22     @testset "Reference Data Files" begin
     23         # Get reference data paths
     24         data_paths = TigerFetch.get_reference_data()
     25         
     26         @testset "Data Dictionary Structure" begin
     27             @test data_paths isa Dict
     28             @test haskey(data_paths, "county")
     29             @test haskey(data_paths, "state")
     30         end
     31 
     32         @testset "County Data File" begin
     33             county_path = data_paths["county"]
     34             @test isfile(county_path)
     35             
     36             # Test county file content structure
     37             content = readlines(county_path)
     38             @test length(content) > 0
     39             @test occursin("|", first(content))
     40             
     41             # Test expected column structure
     42             first_line = split(first(content), "|")
     43             @test length(first_line) >= 4  # Should have at least State, County FIPS, Name columns
     44             
     45             # Test file hash matches expected
     46             @test bytes2hex(SHA.sha256(read(county_path))) == 
     47                   "9f6e5f6eb6ac2f5e9a36d5fd01dec77991bddc75118f748a069441a4782970d6"
     48         end
     49 
     50         @testset "State Data File" begin
     51             state_path = data_paths["state"]
     52             @test isfile(state_path)
     53             
     54             # Test state file content structure
     55             content = readlines(state_path)
     56             @test length(content) > 0
     57             @test occursin("|", first(content))
     58             
     59             # Test expected column structure
     60             first_line = split(first(content), "|")
     61             @test length(first_line) >= 4  # Should have at least FIPS, Abbrev, Name columns
     62             
     63             # Test file hash matches expected
     64             @test bytes2hex(SHA.sha256(read(state_path))) == 
     65                   "167942161ec455bf7b0ee81b6ad76c109eb65e63136125d3683f8a44f51bbc66"
     66         end
     67     end
     68 
     69     @testset "Data Processing Functions" begin
     70         @testset "State List Processing" begin
     71             state_list = TigerFetch.get_state_list()
     72             @test length(state_list) > 0
     73             @test all(x -> length(x) == 3, state_list)  # [abbrev, fips, name]
     74             
     75             # Test specific state presence
     76             @test any(x -> x[1] == "AL", state_list)  # Alabama should exist
     77             @test any(x -> x[2] == "06", state_list)  # California FIPS should exist
     78         end
     79 
     80         @testset "County List Processing" begin
     81             # Test full county list
     82             county_list = TigerFetch.get_county_list()
     83             @test length(county_list) > 0
     84             @test all(x -> length(x) == 4, county_list)  # [state, state_fips, county_fips, name]
     85             
     86             # Test state-specific county list
     87             al_counties = TigerFetch.get_county_list("01")  # Alabama FIPS
     88             @test length(al_counties) > 0
     89             @test all(x -> x[1] == "AL", al_counties)  # All should be Alabama counties
     90             
     91             # Test known county existence
     92             @test any(x -> x[3] == "001" && x[2] == "01", al_counties)  # Autauga County, AL
     93         end
     94     end
     95 end