Beispiel #1
0
def test_system_rows_fail_with_inheritance():
    """
    Test whether the system row method fails if the subscriber queries for random rows on a parent table.
    """
    with pytest.raises(ValueError):
        df = Table(name="events.calls").random_sample(
            size=8, sampling_method="system_rows")
Beispiel #2
0
def test_random_from_table(get_dataframe):
    """
    Tests whether class selects random rows from query.
    """
    df = get_dataframe(
        Table(name="infrastructure.sites",
              columns=["id", "version"]).random_sample(size=8))
    assert list(df.columns) == ["id", "version"]
    assert len(df) == 8
Beispiel #3
0
def test_random_sites(get_dataframe):
    """
    Tests whether class selects a random sample of sites.
    """
    df = get_dataframe(
        Table("infrastructure.sites",
              columns=["id", "version"]).random_sample(size=5))
    assert list(df.columns) == ["id", "version"]
    assert len(df) == 5
Beispiel #4
0
def test_pickling():
    """
    Test that we can pickle and unpickle random classes.
    """
    ss1 = UniqueSubscribers(start="2016-01-01",
                            stop="2016-01-04").random_sample(
                                size=10, sampling_method="system_rows")
    ss2 = Table("events.calls").random_sample(size=10,
                                              sampling_method="bernoulli",
                                              seed=0.73)
    for ss in [ss1, ss2]:
        assert ss.get_query() == pickle.loads(pickle.dumps(ss)).get_query()
        assert ss.query_id == pickle.loads(pickle.dumps(ss)).query_id