コード例 #1
0
def test_returns_set(get_dataframe):
    """
    UniqueSubscribers() returns set.
    """
    UU = UniqueSubscribers("2016-01-01", "2016-01-02")
    u_set = UU.as_set()
    assert isinstance(u_set, set)
    assert len(u_set) == len(get_dataframe(UU))
コード例 #2
0
def test_has_right_columns(get_dataframe):
    """
    NewSubscribers() returned dataframe has the right column..
    """
    nu = NewSubscribers(
        unique_subscribers_bench_mark=UniqueSubscribers(
            "2016-01-01", "2016-01-03"),
        unique_subscribers_focal=UniqueSubscribers("2016-01-05", "2016-01-07"),
    )
    assert nu.column_names == ["subscriber"]
コード例 #3
0
def test_subscriber_identifier_mismatch_error():
    """
    NewSubscribers requires matching subscriber_identifier
    """
    with pytest.raises(ValueError):
        nu = NewSubscribers(
            unique_subscribers_bench_mark=UniqueSubscribers(
                "2016-01-01", "2016-01-03", subscriber_identifier="imei"),
            unique_subscribers_focal=UniqueSubscribers(
                "2016-01-05", "2016-01-07", subscriber_identifier="msisdn"),
        )
コード例 #4
0
 def test_can_subset_by_sampler(self):
     """Test that we can use the output of another query to subset by."""
     unique_subs_sample = UniqueSubscribers(
         "2016-01-01", "2016-01-07").random_sample(size=10,
                                                   method="system",
                                                   seed=0.1)
     su = EventTableSubset("2016-01-01",
                           "2016-01-03",
                           subscriber_subset=unique_subs_sample)
     su_set = set(su.get_dataframe().subscriber)
     uu_set = set(unique_subs_sample.get_dataframe().subscriber)
     self.assertSetEqual(su_set, uu_set)
     self.assertEqual(len(su_set), 10)
コード例 #5
0
def test_specific_values(get_dataframe):
    """
    NewSubscribers() results match a few know values from the query that we have.
    """
    UU = NewSubscribers(
        unique_subscribers_bench_mark=UniqueSubscribers(
            "2016-01-01 01:00:00", "2016-01-02 02:00:00"),
        unique_subscribers_focal=UniqueSubscribers("2016-01-03", "2016-01-04"),
    )
    df = get_dataframe(UU)
    nus = set(df.subscriber)
    assert "BGXbdrXG9J2gVZoA" in nus
    assert "Va0P7xJQVOmMpQn6" in nus
    assert "148ZaRZe54wPGQ9r" not in nus
コード例 #6
0
def test_subscribers_make_atleast_one_call_in_admin0():
    """
    The set of subscribers who make at least one call within admin0 over
    whole test time period should be equal to set of unique subscribers
    in test calls table.
    """

    start, stop = "2016-01-01", "2016-01-07"

    sls = SubscriberLocationSubset(start, stop, min_calls=1, level="admin0")
    us = UniqueSubscribers(start, stop, table="events.calls")

    sls_subs = set(sls.get_dataframe()["subscriber"])
    us_subs = set(us.get_dataframe()["subscriber"])

    assert sls_subs == us_subs
コード例 #7
0
def test_can_subset_by_sampler(get_dataframe):
    """Test that we can use the output of another query to subset by."""
    unique_subs_sample = UniqueSubscribers(
        "2016-01-01", "2016-01-07").random_sample(size=10,
                                                  sampling_method="system",
                                                  seed=0.1)
    su = EventTableSubset(start="2016-01-01",
                          stop="2016-01-03",
                          subscriber_subset=unique_subs_sample)
    su_set = set(get_dataframe(su).subscriber)
    uu_set = set(get_dataframe(unique_subs_sample).subscriber)
    assert su_set == uu_set
    assert len(su_set) == 10
コード例 #8
0
 def tearDown(self):
     UniqueSubscribers("2016-01-01", "2016-01-07").invalidate_db_cache()
コード例 #9
0
def test_unique_subscriber_column_names(get_dataframe):
    """Test that column_names property of UniqueSubscribers is accurate"""
    us = UniqueSubscribers("2016-01-01", "2016-01-02")
    assert get_dataframe(us).columns.tolist() == us.column_names
コード例 #10
0
def test_subscribers_unique(get_dataframe):
    """
    Returned dataframe has unique subscribers.
    """
    UU = UniqueSubscribers("2016-01-01", "2016-01-02")
    assert get_dataframe(UU)["subscriber"].is_unique