Example #1
0
def test_write_non_string_identifier_and_tags(sync_client):
    point = dict(tags={1: 2}, fields={3: 4})
    with pytest.warns(UserWarning):
        assert sync_client.write(point, measurement='my_measurement')
    resp = sync_client.select_all(measurement='my_measurement')
    logger.info(resp)
    assert len(resp['results'][0]['series'][0]['values']) == 1
Example #2
0
def test_write_to_non_default_rp(sync_client):
    db = sync_client.db
    sync_client.query(f"CREATE RETENTION POLICY myrp ON {db} DURATION 1h REPLICATION 1")
    points = [p for p in utils.random_points(5)]
    assert sync_client.write(points, rp='myrp')
    resp = sync_client.query(f"SELECT * from {db}.myrp.test_measurement")
    logger.info(resp)
    assert len(resp['results'][0]['series'][0]['values']) == 5
Example #3
0
def test_write_without_tags(sync_client):
    points = [p for p in utils.random_points(7)]
    for p in points:
        _ = p.pop('tags')
    logger.info(points)
    assert sync_client.write(points, mytag='foo')
    resp = sync_client.select_all(measurement='test_measurement')
    assert len(resp['results'][0]['series'][0]['values']) == 7
Example #4
0
def test_read_dataframe_multistatement(df_client):
    df_list = df_client.query('SELECT max(*) from m1;SELECT min(*) from m2')
    logger.info(df_list)
    assert type(df_list) is list
    assert 'm1' in df_list[0]
    assert 'm2' in df_list[1]
    assert df_list[0]['m1'].shape == (1, 5)
    assert df_list[1]['m2'].shape == (1, 5)
Example #5
0
async def test_iterpoints_with_parser(iter_client):
    r = await iter_client.query("SELECT * FROM cpu_load LIMIT 3",
                                parser=lambda x, meta: dict(zip(meta['columns'], x)))
    for i in r:
        logger.info(i)
        assert 'time' in i
        assert 'value' in i
        assert 'host' in i
Example #6
0
def test_read_dataframe_groupby(df_client):
    df_dict = df_client.query('SELECT max(*) from /m[1-2]$/ GROUP BY "tag"')
    s = ['\n{}:\n{}'.format(k, v) for k, v in df_dict.items()]
    logger.info('\n'.join(s))
    m1 = pd.concat([df for k, df in df_dict.items() if k[0] == 'm1'])
    m2 = pd.concat([df for k, df in df_dict.items() if k[0] == 'm2'])
    assert m1.shape == (5, 6)
    assert m2.shape == (5, 6)
Example #7
0
def test_write_to_non_default_db(sync_client):
    points = [p for p in utils.random_points(5)]
    sync_client.create_database(db='temp_db')
    assert sync_client.db != 'temp_db'
    assert sync_client.write(points, db='temp_db')
    resp = sync_client.select_all(db='temp_db', measurement='test_measurement')
    logger.info(resp)
    assert len(resp['results'][0]['series'][0]['values']) == 5
    sync_client.drop_database(db='temp_db')
Example #8
0
def test_write_without_timestamp(sync_client):
    points = [p for p in utils.random_points(9)]
    for p in points:
        _ = p.pop('time')
        _ = p.pop('measurement')
    logger.info(points)
    assert sync_client.write(points, measurement='yet_another_measurement')
    resp = sync_client.select_all(measurement='yet_another_measurement')
    # Points with the same tag/timestamp set are overwritten
    assert len(resp['results'][0]['series'][0]['values']) == 1
Example #9
0
def test_write_with_custom_measurement(sync_client):
    points = [p for p in utils.random_points(5)]
    for p in points:
        _ = p.pop('measurement')
    logger.info(points)
    with pytest.raises(ValueError):
        assert sync_client.write(points)
    assert sync_client.write(points, measurement='another_measurement')
    resp = sync_client.select_all(measurement='another_measurement')
    assert len(resp['results'][0]['series'][0]['values']) == 5
Example #10
0
async def test_aiter_chunk(iter_client):
    resp = await iter_client.select_all(measurement='cpu_load',
                                        chunked=True, chunk_size=10, wrap=True)
    assert inspect.isasyncgen(resp.gen)

    chunks = []
    async for chunk in resp.iterchunks():
        chunks.append(chunk)
    logger.info(resp)
    logger.info(chunks[0])
    assert len(chunks) == 10
Example #11
0
def test_read_dataframe_with_tag_info(df_client):
    df_client.get_tag_info()
    logger.info(df_client.tag_cache)
    df = df_client.select_all(measurement='m1')
    assert pd.api.types.CategoricalDtype in {type(d) for d in df.dtypes}
    assert df.shape == (50, 8)
Example #12
0
def test_get_tag_info(sync_client):
    tag_info = sync_client.get_tag_info()
    logger.info(tag_info)
Example #13
0
def test_repr(sync_client):
    logger.info(sync_client)
Example #14
0
def test_read_dataframe_show_databases(df_client):
    df = df_client.show_databases()
    assert isinstance(df.index, pd.RangeIndex)
    assert 'name' in df.columns
    logger.info('\n{}'.format(df.head()))
Example #15
0
def test_read_dataframe(df_client):
    df = df_client.select_all(measurement='m1')
    logger.info('\n{}'.format(df.head()))
    assert df.shape == (50, 8)
Example #16
0
def test_select_into(df_client):
    df_client.query("SELECT * INTO m2_copy from m2")
    df = df_client.select_all(measurement='m2_copy')
    assert df.shape == (50, 8)
    logger.info('\n{}'.format(df.head()))
Example #17
0
async def test_get_tag_info(async_client):
    tag_info = await async_client.get_tag_info()
    logger.info(tag_info)
Example #18
0
async def test_iter_wrap(iter_client):
    resp = await iter_client.select_all(measurement='cpu_load', wrap=True)
    assert 'results' in resp.data
    logger.info(resp)
    assert len(resp.show()) == len(resp)