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
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
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
def test_iter_resp_with_parser(sync_client):
    point = 'm1,host=server02,region=us-west load=0.55 1422568543702900257'
    assert sync_client.write(point)
    r = sync_client.query("SELECT * FROM m1 LIMIT 10")
    for i in iter_resp(r,
                       parser=lambda x, meta: dict(zip(meta['columns'], x))):
        logger.info(i)
        assert 'time' in i
        assert 'load' in i
        assert 'host' in i
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
def test_repr(sync_client):
    logger.info(sync_client)
Beispiel #7
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(f'\n{df.head()}')
Beispiel #8
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))
    assert df_dict['m1'].shape == (5, 6)
    assert df_dict['m2'].shape == (5, 6)
Beispiel #9
0
def test_read_dataframe(df_client):
    df = df_client.select_all(measurement='m1')
    logger.info(f'\n{df.head()}')
    assert df.shape == (50, 7)
Beispiel #10
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, 7)
    logger.info(f'\n{df.head()}')