# Path: django_performance_testing/core.py
# class LimitViolationError(RuntimeError):
# 
#     def __init__(self, limit_obj, result, context, tb=None):
#         self.limit_obj = limit_obj
#         self.result = result
#         self.context = context
#         self.tb = tb
#         super(LimitViolationError, self).__init__(self.error_msg)
# 
#     @property
#     def error_msg(self):
#         base = self.base_error_msg
#         ctx = self.context_repr
#         tb = self.tb_msg
#         if ctx:
#             ctx = ' {}'.format(ctx)
#         if tb:
#             tb = '\n{}'.format(tb)
#         return ''.join([base, ctx, tb])
# 
#     @property
#     def tb_msg(self):
#         if self.tb:
#             return self.tb
#         return ''
# 
#     @property
#     def context_repr(self):
#         if self.context:
#             return pprint.pformat(self.context)
#         return ''
# 
#     @property
#     def base_error_msg(self):
#         return 'Too {} ({}) {} {}{} (limit: {})'.format(
#             self.quantifier,
#             self.actual,
#             self.name,
#             self.items_name,
#             self.collector_text,
#             self.limit
#         )
# 
#     @property
#     def quantifier(self):
#         return self.limit_obj.quantifier
# 
#     @property
#     def items_name(self):
#         return self.limit_obj.items_name
# 
#     @property
#     def name(self):
#         return self.result.name
# 
#     @property
#     def collector_text(self):
#         if self.limit_obj.is_anonymous():
#             return ''
#         return ' (for {})'.format(self.limit_obj.collector_id)
# 
#     @property
#     def actual(self):
#         return str(self.result)
# 
#     @property
#     def limit(self):
#         return self.limit_obj.limit_for(self.result)
# 
#     def clone_with_more_info(self, orig_tb):
#         return LimitViolationError(
#             limit_obj=self.limit_obj, result=self.result,
#             context=self.context, tb=orig_tb)
# 
# Path: django_performance_testing/timing.py
# class TimeCollector(BaseCollector):
# 
#     type_name = 'time'
# 
#     def __enter__(self):
#         self.start = time()
#         return self
# 
#     def get_results_to_send(self):
#         return [NameValueResult(name='total', value=time() - self.start)]
# 
#     @classmethod
#     def get_sample_results(cls):
#         return [0.01, 1.00, 3.2]
# 
# class TimeLimit(BaseLimit):
#     collector_cls = TimeCollector
# 
#     quantifier = 'many'
#     items_name = 'elapsed seconds'


from datetime import timedelta
from django_performance_testing.core import LimitViolationError
from django_performance_testing.timing import \
    TimeCollector, TimeLimit
from freezegun import freeze_time
import pytest


def test_it_has_the_correct_collector():
    assert TimeLimit.collector_cls == TimeCollector


def test_it_has_the_correct_attributes_for_limitviolationerror():
    assert TimeLimit.quantifier == 'many'
    assert TimeLimit.items_name == 'elapsed seconds'


@pytest.mark.parametrize('seconds', [10.0, 5.0])
def test_can_limit_elapsed_seconds(seconds):
    with freeze_time('2016-09-22 15:57:01') as frozen_time:

# Path: django_performance_testing/core.py
# class LimitViolationError(RuntimeError):
# 
#     def __init__(self, limit_obj, result, context, tb=None):
#         self.limit_obj = limit_obj
#         self.result = result
#         self.context = context
#         self.tb = tb
#         super(LimitViolationError, self).__init__(self.error_msg)
# 
#     @property
#     def error_msg(self):
#         base = self.base_error_msg
#         ctx = self.context_repr
#         tb = self.tb_msg
#         if ctx:
#             ctx = ' {}'.format(ctx)
#         if tb:
#             tb = '\n{}'.format(tb)
#         return ''.join([base, ctx, tb])
# 
#     @property
#     def tb_msg(self):
#         if self.tb:
#             return self.tb
#         return ''
# 
#     @property
#     def context_repr(self):
#         if self.context:
#             return pprint.pformat(self.context)
#         return ''
# 
#     @property
#     def base_error_msg(self):
#         return 'Too {} ({}) {} {}{} (limit: {})'.format(
#             self.quantifier,
#             self.actual,
#             self.name,
#             self.items_name,
#             self.collector_text,
#             self.limit
#         )
# 
#     @property
#     def quantifier(self):
#         return self.limit_obj.quantifier
# 
#     @property
#     def items_name(self):
#         return self.limit_obj.items_name
# 
#     @property
#     def name(self):
#         return self.result.name
# 
#     @property
#     def collector_text(self):
#         if self.limit_obj.is_anonymous():
#             return ''
#         return ' (for {})'.format(self.limit_obj.collector_id)
# 
#     @property
#     def actual(self):
#         return str(self.result)
# 
#     @property
#     def limit(self):
#         return self.limit_obj.limit_for(self.result)
# 
#     def clone_with_more_info(self, orig_tb):
#         return LimitViolationError(
#             limit_obj=self.limit_obj, result=self.result,
#             context=self.context, tb=orig_tb)
# 
# Path: django_performance_testing/timing.py
# class TimeCollector(BaseCollector):
# 
#     type_name = 'time'
# 
#     def __enter__(self):
#         self.start = time()
#         return self
# 
#     def get_results_to_send(self):
#         return [NameValueResult(name='total', value=time() - self.start)]
# 
#     @classmethod
#     def get_sample_results(cls):
#         return [0.01, 1.00, 3.2]
# 
# class TimeLimit(BaseLimit):
#     collector_cls = TimeCollector
# 
#     quantifier = 'many'
#     items_name = 'elapsed seconds'


# Path: tests/testapp/tests/test_timelimit.py
from datetime import timedelta
from django_performance_testing.core import LimitViolationError
from django_performance_testing.timing import \
    TimeCollector, TimeLimit
from freezegun import freeze_time
import pytest



def test_it_has_the_correct_collector():
    assert TimeLimit.collector_cls == TimeCollector


def test_it_has_the_correct_attributes_for_limitviolationerror():
    assert TimeLimit.quantifier == 'many'
    assert TimeLimit.items_name == 'elapsed seconds'


@pytest.mark.parametrize('seconds', [10.0, 5.0])
def test_can_limit_elapsed_seconds(seconds):
    with freeze_time('2016-09-22 15:57:01') as frozen_time:

        with pytest.raises(LimitViolationError) as excinfo: