# Path: tests/util.py
# def dt(dtstr):  # (parse datetime str)
#     """
#     Return datetime parsed from str of various accepted formats, eg:
#       - '2014-02-14 16:30:45 001234'
#       - '2014-02-14 16:30:45'
#       - '2014-02-14 16:30'
#       - '2014-02-14'
#     Raise ValueError if not recognizable.
#     """
#     FORMATS = (
#         '%Y-%m-%d %H:%M:%S %f',
#         '%Y-%m-%d %H:%M:%S',
#         '%Y-%m-%d %H:%M',
#         '%Y-%m-%d',
#     )
#     for fmt in FORMATS:
#         try:
#             dt1 = datetime.strptime(dtstr, fmt)
#             return dt1
#         except ValueError as e:
#             pass
#     raise ValueError("time data '{dtstr}' does not match any format"
#         .format(dtstr=dtstr))
# 
# def log_config(level=logging.DEBUG):
#     """
#     Configure logging.
#     Hackily colors log output if 'colorlog' is installed.
#     See: https://pypi.python.org/pypi/colorlog/
#     """
# 
#     format  = ("%(asctime)s %(levelname)-8s [%(name)s]  %(message)s")
#     cformat = ("%(bg_black)s%(asctime)s "+
#         "%(log_color)s%(levelname)-8s [%(name)-50s] %(reset)s "+
#         "%(log_color)s%(bold)s%(message)s")
# 
#     def color_if_possible():
#         try:
#             from colorlog import ColoredFormatter
#         except ImportError:
#             return  # optional lib not available, so don't color
#         formatter = ColoredFormatter(cformat)
#         logging.getLogger().handlers[0].formatter = formatter
# 
#     logging.basicConfig(level=level, format=format)
#     color_if_possible()
# 
# def load_metset(asset):
#     """Helper to load test asset and parse as MetSet, returning."""
#     yaml_metset1 = load_test_asset(asset)
#     parser1 = mdefl.MetSetParser()
#     return parser1.parse_ystr_metset(yaml_metset1)
# 
# def load_query(asset):
#     """Helper to load test asset and parse as Query, returning."""
#     yaml_query1 = load_test_asset(asset)
#     parser1 = mql.QueryParser()
#     return parser1.parse_ystr_query(yaml_query1)


import pytest
import axonchisel.metrics.foundation.chrono.framespec as framespec
import axonchisel.metrics.foundation.metricdef.mdefl as mdefl
import axonchisel.metrics.foundation.query.query as query
import axonchisel.metrics.foundation.query.qdata as qdata
import axonchisel.metrics.foundation.query.qtimeframe as qtimeframe
import axonchisel.metrics.foundation.query.qformat as qformat
import axonchisel.metrics.foundation.query.qghosts as qghosts
import axonchisel.metrics.foundation.query.queryset as queryset
import axonchisel.metrics.foundation.query.mql as mql
import axonchisel.metrics.run.mqengine.mqengine as mqengine
import logging
from .util import dt, log_config, load_metset, load_query
Ax_Metrics - Test MQEngine

------------------------------------------------------------------------------
Author: Dan Kamins <dos at axonchisel dot net>
Copyright (c) 2014 Dan Kamins, AxonChisel.net
"""


# ----------------------------------------------------------------------------







# ----------------------------------------------------------------------------


# Enable TEST_EXTRA_HTTP to run a more complex HTTP stat through MQEngine.
# This can add significant time to the test run!
# The HTTP components are already tested separately, so this test is more
# for testing HTTP receivers and whole system throughput.
TEST_EXTRA_HTTP = False


# ----------------------------------------------------------------------------


def setup_module(module):

# Path: tests/util.py
# def dt(dtstr):  # (parse datetime str)
#     """
#     Return datetime parsed from str of various accepted formats, eg:
#       - '2014-02-14 16:30:45 001234'
#       - '2014-02-14 16:30:45'
#       - '2014-02-14 16:30'
#       - '2014-02-14'
#     Raise ValueError if not recognizable.
#     """
#     FORMATS = (
#         '%Y-%m-%d %H:%M:%S %f',
#         '%Y-%m-%d %H:%M:%S',
#         '%Y-%m-%d %H:%M',
#         '%Y-%m-%d',
#     )
#     for fmt in FORMATS:
#         try:
#             dt1 = datetime.strptime(dtstr, fmt)
#             return dt1
#         except ValueError as e:
#             pass
#     raise ValueError("time data '{dtstr}' does not match any format"
#         .format(dtstr=dtstr))
# 
# def log_config(level=logging.DEBUG):
#     """
#     Configure logging.
#     Hackily colors log output if 'colorlog' is installed.
#     See: https://pypi.python.org/pypi/colorlog/
#     """
# 
#     format  = ("%(asctime)s %(levelname)-8s [%(name)s]  %(message)s")
#     cformat = ("%(bg_black)s%(asctime)s "+
#         "%(log_color)s%(levelname)-8s [%(name)-50s] %(reset)s "+
#         "%(log_color)s%(bold)s%(message)s")
# 
#     def color_if_possible():
#         try:
#             from colorlog import ColoredFormatter
#         except ImportError:
#             return  # optional lib not available, so don't color
#         formatter = ColoredFormatter(cformat)
#         logging.getLogger().handlers[0].formatter = formatter
# 
#     logging.basicConfig(level=level, format=format)
#     color_if_possible()
# 
# def load_metset(asset):
#     """Helper to load test asset and parse as MetSet, returning."""
#     yaml_metset1 = load_test_asset(asset)
#     parser1 = mdefl.MetSetParser()
#     return parser1.parse_ystr_metset(yaml_metset1)
# 
# def load_query(asset):
#     """Helper to load test asset and parse as Query, returning."""
#     yaml_query1 = load_test_asset(asset)
#     parser1 = mql.QueryParser()
#     return parser1.parse_ystr_query(yaml_query1)


# Path: tests/test_mqengine.py
import pytest
import axonchisel.metrics.foundation.chrono.framespec as framespec
import axonchisel.metrics.foundation.metricdef.mdefl as mdefl
import axonchisel.metrics.foundation.query.query as query
import axonchisel.metrics.foundation.query.qdata as qdata
import axonchisel.metrics.foundation.query.qtimeframe as qtimeframe
import axonchisel.metrics.foundation.query.qformat as qformat
import axonchisel.metrics.foundation.query.qghosts as qghosts
import axonchisel.metrics.foundation.query.queryset as queryset
import axonchisel.metrics.foundation.query.mql as mql
import axonchisel.metrics.run.mqengine.mqengine as mqengine
import logging
from .util import dt, log_config, load_metset, load_query

Ax_Metrics - Test MQEngine

------------------------------------------------------------------------------
Author: Dan Kamins <dos at axonchisel dot net>
Copyright (c) 2014 Dan Kamins, AxonChisel.net
"""


# ----------------------------------------------------------------------------







# ----------------------------------------------------------------------------


# Enable TEST_EXTRA_HTTP to run a more complex HTTP stat through MQEngine.
# This can add significant time to the test run!
# The HTTP components are already tested separately, so this test is more
# for testing HTTP receivers and whole system throughput.
TEST_EXTRA_HTTP = False


# ----------------------------------------------------------------------------


def setup_module(module):

    log_config(level=logging.INFO)