Beispiel #1
0
def test_alabama(patched_geoservice):
    # setup constants and mock data
    AA_IDX = 1
    UNKNOWN_IDX = 3

    cases = {
        'Racecat': ['Asian', 'Black', 'Other', 'Unknown', 'White'],
        'value': [200, 19000, 3000, 18000, 20000]
    }

    deaths = {
        'Racecat': ['Asian', 'Black', 'Other', 'Unknown', 'White'],
        'value': [10, 500, 25, 50, 600]
    }

    known_cases_by_race = sum(cases['value']) - cases['value'][UNKNOWN_IDX]
    known_deaths_by_race = sum(deaths['value']) - deaths['value'][UNKNOWN_IDX]

    # patch geoservice
    patched_geoservice.side_effect = [
        util.make_query_geoservice_data(data=cases),
        util.make_query_geoservice_data(data=deaths)
    ]

    # run and test
    util.run_scraper_and_assert(scraper_cls=Alabama,
                                assertions={
                                    'Date Published':
                                    date.today(),
                                    'Total Cases':
                                    sum(cases['value']),
                                    'Total Deaths':
                                    sum(deaths['value']),
                                    'Count Cases Black/AA':
                                    cases['value'][AA_IDX],
                                    'Count Deaths Black/AA':
                                    deaths['value'][AA_IDX],
                                    'Pct Includes Unknown Race':
                                    False,
                                    'Pct Includes Hispanic Black':
                                    False,
                                    'Pct Cases Black/AA':
                                    to_percentage(cases['value'][AA_IDX],
                                                  known_cases_by_race),
                                    'Pct Deaths Black/AA':
                                    to_percentage(deaths['value'][AA_IDX],
                                                  known_deaths_by_race),
                                    'Count Cases Known Race':
                                    known_cases_by_race,
                                    'Count Deaths Known Race':
                                    known_deaths_by_race
                                })
Beispiel #2
0
def test_wisconsin():
    _, df = util.make_query_geoservice_data(json_file='wisconsin.json')
    df['DATE'] = pd.Timestamp.today()
    with mock.patch('covid19_scrapers.states.wisconsin.query_geoservice', mock.MagicMock(return_value=(date, df))):
        util.run_scraper_and_assert(
            scraper_cls=Wisconsin,
            assertions={
                'Date Published': date.today(),
                'Total Cases': 40000,
                'Total Deaths': 800,
                'Count Cases Black/AA': 6600,
                'Count Deaths Black/AA': 200,
                'Pct Includes Unknown Race': False,
                'Pct Includes Hispanic Black': True,
                'Pct Cases Black/AA': to_percentage(6600, 40000 - 3800),
                'Pct Deaths Black/AA': to_percentage(200, 800 - 10),
                'Count Cases Known Race': 40000 - 3800,
                'Count Deaths Known Race': 800 - 10
            })
Beispiel #3
0
from datetime import date
import mock

from covid19_scrapers.states.arkansas import Arkansas
from covid19_scrapers.test.states import util
from covid19_scrapers.utils.misc import to_percentage


@mock.patch('covid19_scrapers.states.arkansas.query_geoservice',
            mock.MagicMock(return_value=util.make_query_geoservice_data(json_file='arkansas.json')))
def test_arkansas():
    util.run_scraper_and_assert(
        scraper_cls=Arkansas,
        assertions={
            'Date Published': date.today(),
            'Total Cases': 31000,
            'Total Deaths': 300,
            'Count Cases Black/AA': 6000,
            'Count Deaths Black/AA': 90,
            'Pct Includes Unknown Race': False,
            'Pct Includes Hispanic Black': True,
            'Pct Cases Black/AA': to_percentage(6000, 27000),
            'Pct Deaths Black/AA': to_percentage(90, 297),
            'Count Cases Known Race': 27000,
            'Count Deaths Known Race': 297
        })
Beispiel #4
0
from datetime import date

import mock

from covid19_scrapers.states.wisconsin import Wisconsin
from covid19_scrapers.test.states import util
from covid19_scrapers.utils.misc import to_percentage


@mock.patch('covid19_scrapers.states.wisconsin.query_geoservice',
            mock.MagicMock(return_value=util.make_query_geoservice_data(json_file='wisconsin.json')))
def test_wisconsin():
    util.run_scraper_and_assert(
        scraper_cls=Wisconsin,
        assertions={
            'Date Published': date.today(),
            'Total Cases': 40000,
            'Total Deaths': 800,
            'Count Cases Black/AA': 6600,
            'Count Deaths Black/AA': 200,
            'Pct Includes Unknown Race': False,
            'Pct Includes Hispanic Black': True,
            'Pct Cases Black/AA': to_percentage(6600, 40000 - 3800),
            'Pct Deaths Black/AA': to_percentage(200, 800 - 10),
            'Count Cases Known Race': 40000 - 3800,
            'Count Deaths Known Race': 800 - 10
        })