Exemplo n.º 1
0
def test_execute():
    agg = Aggregate("results='Fail'", ["count"], IMPUTE_RULES)
    st = Aggregation(
        [agg],
        from_obj='food_inspections',
        groups=['license_no', 'zip'],
        state_table='all_licenses',
        state_group='license_no',
    )
    with Postgresql() as postgresql:
        engine = create_engine(postgresql.url())
        st.execute(engine.connect())
Exemplo n.º 2
0
def test_Aggregation_colname_agg_function():
    n = Aggregate("x", "sum", {})
    d = Aggregate("1", "count", {})
    m = Aggregate("y", "stddev_samp", {})
    aggregation = Aggregation([n, d, m],
                              groups=['entity_id'],
                              from_obj="source",
                              prefix="mysource",
                              state_table="tbl")

    assert aggregation.colname_agg_function(
        'mysource_entity_id_x_sum') == 'sum'
    assert aggregation.colname_agg_function(
        'mysource_entity_id_y_stddev_samp') == 'stddev_samp'
Exemplo n.º 3
0
def test_aggregation_table_name_no_schema():
    # no schema
    assert (Aggregation(
        [], from_obj="source", groups=[],
        state_table="tbl").get_table_name() == '"source_aggregation"')
    assert (Aggregation([], from_obj="source", groups=[],
                        state_table="tbl").get_table_name(
                            imputed=True) == '"source_aggregation_imputed"')

    # prefix
    assert (Aggregation(
        [], from_obj="source", prefix="mysource", groups=[],
        state_table="tbl").get_table_name() == '"mysource_aggregation"')
    assert (Aggregation([],
                        from_obj="source",
                        prefix="mysource",
                        groups=[],
                        state_table="tbl").get_table_name(
                            imputed=True) == '"mysource_aggregation_imputed"')

    # schema
    assert (Aggregation(
        [], from_obj="source", schema="schema", groups=[],
        state_table="tbl").get_table_name() == '"schema"."source_aggregation"')
    assert (Aggregation(
        [], from_obj="source", schema="schema", groups=[],
        state_table="tbl").get_table_name(
            imputed=True) == '"schema"."source_aggregation_imputed"')
Exemplo n.º 4
0
def test_Aggregation_colname_aggregate_lookup():
    n = Aggregate("x", "sum", {})
    d = Aggregate("1", "count", {})
    m = Aggregate("y", "avg", {})
    aggregation = Aggregation([n, d, m],
                              groups=['entity_id'],
                              from_obj="source",
                              prefix="mysource",
                              state_table="tbl")
    assert aggregation.colname_aggregate_lookup == {
        'mysource_entity_id_x_sum': 'sum',
        'mysource_entity_id_1_count': 'count',
        'mysource_entity_id_y_avg': 'avg'
    }
Exemplo n.º 5
0
def test_Aggregation_imputation_flag_base():
    n = Aggregate("x", ["sum", "count"], {})
    m = Aggregate("y", "stddev_samp", {})
    aggregation = Aggregation([n, m],
                              groups=['entity_id'],
                              from_obj="source",
                              prefix="mysource",
                              state_table="tbl")

    assert aggregation.imputation_flag_base(
        'mysource_entity_id_x_sum') == 'mysource_entity_id_x'
    assert aggregation.imputation_flag_base(
        'mysource_entity_id_x_count') == 'mysource_entity_id_x'
    assert aggregation.imputation_flag_base(
        'mysource_entity_id_y_stddev_samp'
    ) == 'mysource_entity_id_y_stddev_samp'
    with pytest.raises(KeyError):
        aggregation.imputation_flag_base('mysource_entity_id_x_stddev_samp')
Exemplo n.º 6
0
def test_aggregation_table_name_no_schema():
    # no schema
    assert Aggregation([], from_obj='source', groups=[], state_table='tbl')\
            .get_table_name() == '"source_aggregation"'
    assert Aggregation([], from_obj='source', groups=[], state_table='tbl')\
            .get_table_name(imputed=True) == '"source_aggregation_imputed"'

    # prefix
    assert Aggregation([], from_obj='source', prefix="mysource",
            groups=[], state_table='tbl')\
            .get_table_name() == '"mysource_aggregation"'
    assert Aggregation([], from_obj='source', prefix="mysource",
            groups=[], state_table='tbl')\
            .get_table_name(imputed=True) == '"mysource_aggregation_imputed"'

    # schema
    assert Aggregation([], from_obj='source', schema='schema',
            groups=[], state_table='tbl')\
            .get_table_name() == '"schema"."source_aggregation"'
    assert Aggregation([], from_obj='source', schema='schema',
            groups=[], state_table='tbl')\
            .get_table_name(imputed=True) == '"schema"."source_aggregation_imputed"'