# 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 load_test_asset(fname):
#     """
#     Load a test file from assets directory, returning contents as str.
#     """
#     path = os.path.dirname(os.path.realpath(__file__))
#     fname = os.path.join(path, 'assets', fname)
#     with open(fname, 'r') as f:
#         return f.read()


import pytest
import yaml
import axonchisel.metrics.foundation.query.mql as mql
from .util import dt, load_test_asset
    #
    # Internal Helpers
    #

    def _yaml1_minus_section(self, section, srcstr=None):
        """
        Return yaml but without the top level section named as indicated.
        If srcstr not specified, uses self.yaml_query1.
        """
        if srcstr is None:
            srcstr = self.yaml_query1
        obj = yaml.load(srcstr)
        del(obj[section])
        outstr = yaml.dump(obj)
        return outstr


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


class TestQuerySetParse(object):
    """
    Test QuerySet parsing.
    """

    #
    # Setup / Teardown
    #

    def setup_method(self, method):

# 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 load_test_asset(fname):
#     """
#     Load a test file from assets directory, returning contents as str.
#     """
#     path = os.path.dirname(os.path.realpath(__file__))
#     fname = os.path.join(path, 'assets', fname)
#     with open(fname, 'r') as f:
#         return f.read()


# Path: tests/test_mql.py
import pytest
import yaml
import axonchisel.metrics.foundation.query.mql as mql
from .util import dt, load_test_asset

    #
    # Internal Helpers
    #

    def _yaml1_minus_section(self, section, srcstr=None):
        """
        Return yaml but without the top level section named as indicated.
        If srcstr not specified, uses self.yaml_query1.
        """
        if srcstr is None:
            srcstr = self.yaml_query1
        obj = yaml.load(srcstr)
        del(obj[section])
        outstr = yaml.dump(obj)
        return outstr


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


class TestQuerySetParse(object):
    """
    Test QuerySet parsing.
    """

    #
    # Setup / Teardown
    #

    def setup_method(self, method):

        self.yaml_queryset1 = load_test_asset('queryset1.yml')