# Path: django_test_tools/re/regexp.py
# class CommonRegExp(object):
#     """
#     This class is a utility for commonly used regular expressions.
# 
#     .. code-block:: python
# 
#         str_data = '10:45'
#         common_regexp = CommonRegExp()
#         regular_expression, key = common_regexp.match_regexp(str_data)
#         self.assertEqual(regular_expression, '([0-1][0-9]|2[0-4]):([0-5][0-9])')
#         self.assertEqual(key, 'time_military')
# 
#     if the strict keyword is used the class will add ^ at the begining and a $ at the end if the already are not present.
# 
#     """
# 
#     def __init__(self,**kwargs):
#         self.strict = kwargs.get('strict', False)
#         self.regular_expressions = dict()
#         self.regular_expressions['time_military'] = {
#             'pattern': r'([0-1][0-9]|2[0-4]):([0-5][0-9])'
#         }
#         self.regular_expressions['integer'] = {
#             'pattern': r'^(\d+)$'
#         }
#         self.regular_expressions['decimal'] = {
#             'pattern': r'(\d+\.\d+)'
#         }
#         self.regular_expressions['url'] = {
#             'pattern': r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
#         }
#         if kwargs.get('reg_exps'):
#             self.regular_expressions.update(kwargs.get('reg_exps'))
# 
#         self.regular_expressions_compiled = dict()
#         for key, reg_exp in self.regular_expressions.items():
#             #self.regular_expressions_compiled[key] = re.compile(reg_exp['pattern'])
#             self.regular_expressions_compiled[key] = self._compile_regular_expression(self.regular_expressions[key])
# 
#     def match_regexp(self, value):
#         for key, regexp in self.regular_expressions_compiled.items():
#             match = regexp.match(value)
#             if match:
#                 return regexp.pattern, key
# 
#         return None, None
# 
#     def add_regular_expression(self, name, pattern, **kwargs):
#         regexp_dict = dict()
#         regexp_dict['pattern'] = pattern
#         if kwargs.get('strict') is not None:
#             regexp_dict['strict'] = kwargs.get('strict')
#         self.regular_expressions_compiled[name] = self._compile_regular_expression(regexp_dict)
# 
#     def _compile_regular_expression(self, regexp_dict):
#         if (self.strict or regexp_dict.get('strict')) and not regexp_dict['pattern'].startswith('^'):
#             regexp_dict['pattern'] = '^{}'.format(regexp_dict['pattern'])
# 
#         if (self.strict or regexp_dict.get('strict')) and not regexp_dict['pattern'].endswith('$'):
#             regexp_dict['pattern'] = '{}$'.format(regexp_dict['pattern'])
#         return re.compile(regexp_dict['pattern'])
# 
# Path: django_test_tools/utils.py
# @deprecated('Should use django_test_tools.file_utils.create_dated() function')
# def create_output_filename_with_date(filename):
#     """
#     Based on the filename will create a full path filename incluidn the date and time in '%Y%m%d_%H%M' format.
#     The path to the filename will be set in the TEST_OUTPUT_PATH settings variable.
# 
#     :param filename: base filename. my_excel_data.xlsx for example
#     :return: string, full path to file with date and time in the TEST_OUTPUT_PATH folder
#     """
#     if getattr(settings, 'TEST_OUTPUT_PATH', None) is None:
#         msg = 'You need a the variable TEST_OUTPUT_PATH in settings. It should point to a folder' \
#               'for temporary data to be written and reviewed.'
#         raise ValueError(msg)
#     if not os.path.exists(settings.TEST_OUTPUT_PATH):
#         os.makedirs(settings.TEST_OUTPUT_PATH)
#     return add_date(os.path.join(settings.TEST_OUTPUT_PATH, filename))


import collections
from datetime import datetime, date
from decimal import Decimal
from openpyxl.compat import deprecated
from .re.regexp import CommonRegExp
from .utils import create_output_filename_with_date


class AssertionWriter(object):
    """
    This class generates assertions using Django practice of putting actual value first and then expected value.
    """

    def __init__(self, **kwargs):
        self.excluded_variable_names = ['created', 'modified']
        if kwargs.get('excluded_keys') is not None:
            for key in kwargs.get('excluded_keys'):
                self.excluded_variable_names.append(key)

        self.use_regexp_assertion = kwargs.get('use_regexp_assertion', False)
        if self.use_regexp_assertion:
            self.common_regexp = CommonRegExp(strict=True)
        self.check_for_type_only = kwargs.get('type_only', False)

    def add_regular_expression(self, name, pattern, **kwargs):
        self.common_regexp.add_regular_expression(name, pattern, **kwargs)

    def write_assert_list(self, dictionary_list, variable_name, **kwargs):
        """
        Function to generate assertions for a dictionary or list content.
        :param kwargs:
        :param dictionary_list:
        :param variable_name:
        :return:
        """
        if kwargs.get('filename') is None:

# Path: django_test_tools/re/regexp.py
# class CommonRegExp(object):
#     """
#     This class is a utility for commonly used regular expressions.
# 
#     .. code-block:: python
# 
#         str_data = '10:45'
#         common_regexp = CommonRegExp()
#         regular_expression, key = common_regexp.match_regexp(str_data)
#         self.assertEqual(regular_expression, '([0-1][0-9]|2[0-4]):([0-5][0-9])')
#         self.assertEqual(key, 'time_military')
# 
#     if the strict keyword is used the class will add ^ at the begining and a $ at the end if the already are not present.
# 
#     """
# 
#     def __init__(self,**kwargs):
#         self.strict = kwargs.get('strict', False)
#         self.regular_expressions = dict()
#         self.regular_expressions['time_military'] = {
#             'pattern': r'([0-1][0-9]|2[0-4]):([0-5][0-9])'
#         }
#         self.regular_expressions['integer'] = {
#             'pattern': r'^(\d+)$'
#         }
#         self.regular_expressions['decimal'] = {
#             'pattern': r'(\d+\.\d+)'
#         }
#         self.regular_expressions['url'] = {
#             'pattern': r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
#         }
#         if kwargs.get('reg_exps'):
#             self.regular_expressions.update(kwargs.get('reg_exps'))
# 
#         self.regular_expressions_compiled = dict()
#         for key, reg_exp in self.regular_expressions.items():
#             #self.regular_expressions_compiled[key] = re.compile(reg_exp['pattern'])
#             self.regular_expressions_compiled[key] = self._compile_regular_expression(self.regular_expressions[key])
# 
#     def match_regexp(self, value):
#         for key, regexp in self.regular_expressions_compiled.items():
#             match = regexp.match(value)
#             if match:
#                 return regexp.pattern, key
# 
#         return None, None
# 
#     def add_regular_expression(self, name, pattern, **kwargs):
#         regexp_dict = dict()
#         regexp_dict['pattern'] = pattern
#         if kwargs.get('strict') is not None:
#             regexp_dict['strict'] = kwargs.get('strict')
#         self.regular_expressions_compiled[name] = self._compile_regular_expression(regexp_dict)
# 
#     def _compile_regular_expression(self, regexp_dict):
#         if (self.strict or regexp_dict.get('strict')) and not regexp_dict['pattern'].startswith('^'):
#             regexp_dict['pattern'] = '^{}'.format(regexp_dict['pattern'])
# 
#         if (self.strict or regexp_dict.get('strict')) and not regexp_dict['pattern'].endswith('$'):
#             regexp_dict['pattern'] = '{}$'.format(regexp_dict['pattern'])
#         return re.compile(regexp_dict['pattern'])
# 
# Path: django_test_tools/utils.py
# @deprecated('Should use django_test_tools.file_utils.create_dated() function')
# def create_output_filename_with_date(filename):
#     """
#     Based on the filename will create a full path filename incluidn the date and time in '%Y%m%d_%H%M' format.
#     The path to the filename will be set in the TEST_OUTPUT_PATH settings variable.
# 
#     :param filename: base filename. my_excel_data.xlsx for example
#     :return: string, full path to file with date and time in the TEST_OUTPUT_PATH folder
#     """
#     if getattr(settings, 'TEST_OUTPUT_PATH', None) is None:
#         msg = 'You need a the variable TEST_OUTPUT_PATH in settings. It should point to a folder' \
#               'for temporary data to be written and reviewed.'
#         raise ValueError(msg)
#     if not os.path.exists(settings.TEST_OUTPUT_PATH):
#         os.makedirs(settings.TEST_OUTPUT_PATH)
#     return add_date(os.path.join(settings.TEST_OUTPUT_PATH, filename))


# Path: django_test_tools/assert_utils.py
import collections
from datetime import datetime, date
from decimal import Decimal
from openpyxl.compat import deprecated
from .re.regexp import CommonRegExp
from .utils import create_output_filename_with_date



class AssertionWriter(object):
    """
    This class generates assertions using Django practice of putting actual value first and then expected value.
    """

    def __init__(self, **kwargs):
        self.excluded_variable_names = ['created', 'modified']
        if kwargs.get('excluded_keys') is not None:
            for key in kwargs.get('excluded_keys'):
                self.excluded_variable_names.append(key)

        self.use_regexp_assertion = kwargs.get('use_regexp_assertion', False)
        if self.use_regexp_assertion:
            self.common_regexp = CommonRegExp(strict=True)
        self.check_for_type_only = kwargs.get('type_only', False)

    def add_regular_expression(self, name, pattern, **kwargs):
        self.common_regexp.add_regular_expression(name, pattern, **kwargs)

    def write_assert_list(self, dictionary_list, variable_name, **kwargs):
        """
        Function to generate assertions for a dictionary or list content.
        :param kwargs:
        :param dictionary_list:
        :param variable_name:
        :return:
        """
        if kwargs.get('filename') is None:

            filename = create_output_filename_with_date('{}.py'.format(variable_name))