# 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))


import pytest
import axonchisel.metrics.foundation.chrono.timerange as timerange
import axonchisel.metrics.foundation.chrono.framespec as framespec
import axonchisel.metrics.foundation.chrono.ghost as ghost
import axonchisel.metrics.foundation.chrono.stepper as stepper
from datetime import datetime, timedelta
from .util import dt

    def test_quarters_smooth1(self, dts):
        tmfrspec_dict = {
            'range_unit' : 'QUARTER',
            'range_val'  : 1,
            'gran_unit'  : 'WEEK',
            'smooth_unit': 'DAY',
            'smooth_val' : 14,
            'mode'       : 'CURRENT',
            'reframe_dt' : dts[4],
        }
        steps = self._steps(tmfrspec_dict)
        assert len(steps) == 13
        assert steps[0].anchor ==    dt('2014-01-01 00:00:00 000000')
        assert steps[1].anchor ==    dt('2014-01-08 00:00:00 000000')
        assert steps[5].anchor ==    dt('2014-02-05 00:00:00 000000')
        assert steps[5].inc_begin == dt('2014-01-29 00:00:00 000000')
        assert steps[5].exc_end ==   dt('2014-02-12 00:00:00 000000')

    def test_accumulate(self, dts):
        steps = self._steps({
            'range_unit' : 'MONTH',
            'range_val'  : 1,
            'gran_unit'  : 'DAY',
            'mode'       : 'CURRENT',
            'reframe_dt' : dts[5],
            'accumulate' : True,
        })
        assert len(steps) == 30
        assert steps[ 5].inc_begin == dt('2014-04-01 00:00:00 000000')

# 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))


# Path: tests/test_chrono.py
import pytest
import axonchisel.metrics.foundation.chrono.timerange as timerange
import axonchisel.metrics.foundation.chrono.framespec as framespec
import axonchisel.metrics.foundation.chrono.ghost as ghost
import axonchisel.metrics.foundation.chrono.stepper as stepper
from datetime import datetime, timedelta
from .util import dt


    def test_quarters_smooth1(self, dts):
        tmfrspec_dict = {
            'range_unit' : 'QUARTER',
            'range_val'  : 1,
            'gran_unit'  : 'WEEK',
            'smooth_unit': 'DAY',
            'smooth_val' : 14,
            'mode'       : 'CURRENT',
            'reframe_dt' : dts[4],
        }
        steps = self._steps(tmfrspec_dict)
        assert len(steps) == 13
        assert steps[0].anchor ==    dt('2014-01-01 00:00:00 000000')
        assert steps[1].anchor ==    dt('2014-01-08 00:00:00 000000')
        assert steps[5].anchor ==    dt('2014-02-05 00:00:00 000000')
        assert steps[5].inc_begin == dt('2014-01-29 00:00:00 000000')
        assert steps[5].exc_end ==   dt('2014-02-12 00:00:00 000000')

    def test_accumulate(self, dts):
        steps = self._steps({
            'range_unit' : 'MONTH',
            'range_val'  : 1,
            'gran_unit'  : 'DAY',
            'mode'       : 'CURRENT',
            'reframe_dt' : dts[5],
            'accumulate' : True,
        })
        assert len(steps) == 30
        assert steps[ 5].inc_begin == dt('2014-04-01 00:00:00 000000')

        assert steps[ 5].exc_end ==   dt('2014-04-07 00:00:00 000000')