예제 #1
0
def test_deps_cache_chain():
    """
    Test that a Query -> cached1 -> cached2 chain will
    return only a dependency on cached1.

    """
    dl1 = daily_location("2016-01-01")
    hl1 = ModalLocation(daily_location("2016-01-01"),
                        daily_location("2016-01-02"))
    hl1.store().result()
    hl2 = ModalLocation(daily_location("2016-01-03"),
                        daily_location("2016-01-04"))
    flow = Flows(hl1, hl2)
    bad_dep = dl1.md5
    good_dep = hl1.md5
    assert 6 == len(flow._get_stored_dependencies())
    assert good_dep in [x.md5 for x in flow._get_stored_dependencies()]
    assert bad_dep not in [x.md5 for x in flow._get_stored_dependencies()]
예제 #2
0
def test_retrieve_all():
    """
    Test that Query.get_stored returns everything.

    """
    dl1 = daily_location("2016-01-01")
    dl1.store().result()
    hl1 = ModalLocation(daily_location("2016-01-01"),
                        daily_location("2016-01-02"))
    hl1.store().result()
    hl2 = ModalLocation(daily_location("2016-01-03"),
                        daily_location("2016-01-04"))
    flow = Flows(hl1, hl2)
    flow.store().result()

    from_cache = [obj.query_id for obj in Query.get_stored()]
    assert dl1.query_id in from_cache
    assert hl1.query_id in from_cache
    assert flow.query_id in from_cache
예제 #3
0
def test_invalidate_cache_multi(flowmachine_connect):
    """
    Test that invalidating a simple query that is part of
    a bigger one drops both tables, cleans up dependencies
    and removes both from cache.

    """
    dl1 = daily_location("2016-01-01")
    dl1.store().result()
    hl1 = ModalLocation(daily_location("2016-01-01"),
                        daily_location("2016-01-02"))
    hl1.store().result()
    assert dl1.is_stored
    assert hl1.is_stored
    dl1.invalidate_db_cache()
    assert not dl1.is_stored
    assert not hl1.is_stored
    assert not cache_table_exists(get_db(), dl1.query_id)
    assert not cache_table_exists(get_db(), hl1.query_id)
    has_deps = bool(get_db().fetch("SELECT * FROM cache.dependencies"))
    assert has_deps  # the remaining dependencies are due to underlying Table objects
예제 #4
0
def test_contact_reference_location_stats_custom_geometry(get_dataframe):
    """ Test ContactReferenceLocationStats with custom geometry column. """
    cb = ContactBalance("2016-01-01", "2016-01-03")
    ml = ModalLocation(*[
        daily_location(
            d,
            spatial_unit=make_spatial_unit("versioned-cell"),
            subscriber_subset=cb.counterparts_subset(include_subscribers=True),
        ) for d in list_of_dates("2016-01-01", "2016-01-03")
    ])
    cb.store()
    ml.store()
    ml = CustomQuery(
        f"SELECT subscriber, ST_POINT(lon, lat) AS loc FROM ({ml.get_query()}) _",
        ["subscriber", "loc"],
    )
    query = ContactReferenceLocationStats(cb,
                                          ml,
                                          statistic="avg",
                                          geom_column="loc")
    df = get_dataframe(query).set_index("subscriber")
    assert df.value["gwAynWXp4eWvxGP7"] == pytest.approx(298.7215)