<commit_before>""" InfluxAlchemy client tests. """

import mock
import influxdb
from influxalchemy.client import InfluxAlchemy
from influxalchemy.measurement import Measurement
from influxalchemy.query import InfluxDBQuery


@mock.patch("influxdb.InfluxDBClient")
def test_query(mock_flux):
    db = influxdb.InfluxDBClient(database="fizz")
    db.query.side_effect = influxdb.exceptions.InfluxDBClientError(None)
    client = InfluxAlchemy(db)
    query = client.query(Measurement.new("buzz"))
    assert str(query) == "SELECT * FROM buzz;"


@mock.patch("influxdb.InfluxDBClient.query")
def test_measurements(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [{"name": "fizz"}]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    measurements = list(client.measurements())
    mock_flux.assert_called_once_with("SHOW MEASUREMENTS;")


@mock.patch("influxdb.InfluxDBClient.query")
def test_tags(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [{"name": "fizz"}]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    assert client.tags(Measurement.new("foo")) == ["fizz"]


@mock.patch("influxdb.InfluxDBClient.query")
def test_fields(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [{"name": "fizz"}]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    assert client.fields(Measurement.new("foo")) == ["fizz"]<commit_msg>Fix test cases related to getting tags and fields<commit_after>""" InfluxAlchemy client tests. """

import mock
import influxdb
from influxalchemy.client import InfluxAlchemy
from influxalchemy.measurement import Measurement
from influxalchemy.query import InfluxDBQuery


@mock.patch("influxdb.InfluxDBClient")
def test_query(mock_flux):
    db = influxdb.InfluxDBClient(database="fizz")
    db.query.side_effect = influxdb.exceptions.InfluxDBClientError(None)
    client = InfluxAlchemy(db)
    query = client.query(Measurement.new("buzz"))
    assert str(query) == "SELECT * FROM buzz;"


@mock.patch("influxdb.InfluxDBClient.query")
def test_measurements(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [{"name": "fizz"}]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    measurements = list(client.measurements())
    mock_flux.assert_called_once_with("SHOW MEASUREMENTS;")


@mock.patch("influxdb.InfluxDBClient.query")
def test_tags(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [{'tagKey': 'sensor_id'}]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    assert client.tags(Measurement.new("environment")) == ["sensor_id"]


@mock.patch("influxdb.InfluxDBClient.query")
def test_fields(mock_flux):
    mock_res = mock.MagicMock()
    mock_res.get_points.return_value = [
        {'fieldKey': 'humidity', 'fieldType': 'float'},
        {'fieldKey': 'temperature', 'fieldType': 'float'}
    ]
    mock_flux.return_value = mock_res
    db = influxdb.InfluxDBClient(database="fizz")
    client = InfluxAlchemy(db)
    assert client.fields(Measurement.new("environment")) == ["humidity", "temperature"]
{'fraction_non_alphanumeric': 0.1304222093695778, 'fraction_numerical': 0.0, 'mean_word_length': 5.198924731182796, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2601891', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1140, 'n_words': 190}