# Path: django_test_tools/file_utils.py
# class TemporaryFolder:
#     def __init__(self, base_name, delete_on_exit=True):
#         self.new_path = create_dated(base_name)
#         self.delete_on_exit = delete_on_exit
# 
#     def __enter__(self):
#         os.mkdir(self.new_path)
#         self.saved_path = os.getcwd()
#         os.chdir(self.new_path)
# 
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         os.chdir(self.saved_path)
#         if self.delete_on_exit:
#             shutil.rmtree(self.new_path)
# 
#     def write(self, filename, content):
#         with open(filename, 'w', encoding='utf-8') as file:
#             if isinstance(content, str):
#                 file.writelines(content)
#             elif isinstance(content, list):
#                 for line in content:
#                     file.write(line)
#                     file.write('\n')
#             else:
#                 file.writelines(str(content))
#         return os.path.join(self.new_path, filename)
# 
# def hash_file(filename, algorithm='sha1', block_size=BLOCKSIZE):
#     """
#     Creates a unique hash for a file.
# 
#     :param filename: String with the full path to the file
#     :param algorithm: String Algorithm to create the hash
#     :param block_size: int for the size of the block while reading the file
#     :return: string the hash for the file
#     """
#     try:
#         hasher = getattr(hashlib, algorithm)()
#     except AttributeError:
#         raise ValueError('{} is not a valid hashing algorithm'.format(algorithm))
# 
#     with open(filename, 'rb') as afile:
#         buf = afile.read(block_size)
#         while len(buf) > 0:
#             hasher.update(buf)
#             buf = afile.read(block_size)
#     return hasher.hexdigest()
# 
# Path: django_test_tools/utils.py
# def versiontuple(v):
# def dict_compare(d1, d2):
# def convert_to_snake_case(camel_case):
# def create_output_filename_with_date(filename):
# def add_date_to_filename(filename, **kwargs):
# def deprecated(func):
#     def new_func(*args, **kwargs):
# def daterange(start_date, end_date):
# def weekdays(start_date, end_date):
#     def __init__(self, newPath):
#     def __enter__(self):
#     def __exit__(self, etype, value, traceback):
# def force_date_to_datetime(unconverted_date, tzinfo=pytz.UTC):
#     def __init__(self):
#     def start(self):
#     def stop(self):
#     def reset(self):
#     def get_elapsed_time(self):
#     def get_elapsed_time_str(self):
#     def running(self):
#     def __enter__(self):
#     def __exit__(self, *args):
# def load_json_file(filename):
# def datetime_to_local_time(date_time):
#     def __init__(self):
#     def _get_date_parts(self, match, input_lang='es'):
#     def parse(self, str_date):
#     def to_string(self, m_date):
# def parse_spanish_date(str_date):
# class cd:
# class Timer:
# class SpanishDate(object):


import datetime
import logging
import os
import pytz
from unittest import mock
from django.test import TestCase, SimpleTestCase
from django.test import override_settings
from django_test_tools.file_utils import TemporaryFolder, hash_file
from django_test_tools.utils import Timer, add_date_to_filename, daterange, parse_spanish_date, spanish_date_util, \
    create_output_filename_with_date, dict_compare, convert_to_snake_case, datetime_to_local_time
    def test_daterange_one_day(self):
        start_date = datetime.date(2016, 10, 3)  # Monday
        end_date = start_date
        days = list(daterange(start_date, end_date))
        self.assertEqual(1, len(days))

    def test_parse_spanish_date(self):
        start_date = datetime.date(2016, 12, 3)  # Monday
        result = parse_spanish_date('03-Dic-16')
        self.assertTrue(result, start_date)

    def test_parse_spanish_date_datetime(self):
        start_date = datetime.datetime(2016, 12, 3, 13, 50)  # Monday
        result = parse_spanish_date('03-Dic-16 13:50')
        self.assertTrue(result, start_date)


class TestSpanishDate(TestCase):
    def test_to_string(self):
        start_date = datetime.date(2016, 12, 3)
        str_date = spanish_date_util.to_string(start_date)
        self.assertEqual('03-Dic-16', str_date)

    def test_to_string_datetime(self):
        start_date = datetime.datetime(2016, 12, 3, 16, 15)
        str_date = spanish_date_util.to_string(start_date)
        self.assertEqual('03-Dic-16 16:15', str_date)

    def test_parse(self):
        start_date = datetime.datetime(2016, 12, 3, 13, 50)

# Path: django_test_tools/file_utils.py
# class TemporaryFolder:
#     def __init__(self, base_name, delete_on_exit=True):
#         self.new_path = create_dated(base_name)
#         self.delete_on_exit = delete_on_exit
# 
#     def __enter__(self):
#         os.mkdir(self.new_path)
#         self.saved_path = os.getcwd()
#         os.chdir(self.new_path)
# 
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         os.chdir(self.saved_path)
#         if self.delete_on_exit:
#             shutil.rmtree(self.new_path)
# 
#     def write(self, filename, content):
#         with open(filename, 'w', encoding='utf-8') as file:
#             if isinstance(content, str):
#                 file.writelines(content)
#             elif isinstance(content, list):
#                 for line in content:
#                     file.write(line)
#                     file.write('\n')
#             else:
#                 file.writelines(str(content))
#         return os.path.join(self.new_path, filename)
# 
# def hash_file(filename, algorithm='sha1', block_size=BLOCKSIZE):
#     """
#     Creates a unique hash for a file.
# 
#     :param filename: String with the full path to the file
#     :param algorithm: String Algorithm to create the hash
#     :param block_size: int for the size of the block while reading the file
#     :return: string the hash for the file
#     """
#     try:
#         hasher = getattr(hashlib, algorithm)()
#     except AttributeError:
#         raise ValueError('{} is not a valid hashing algorithm'.format(algorithm))
# 
#     with open(filename, 'rb') as afile:
#         buf = afile.read(block_size)
#         while len(buf) > 0:
#             hasher.update(buf)
#             buf = afile.read(block_size)
#     return hasher.hexdigest()
# 
# Path: django_test_tools/utils.py
# def versiontuple(v):
# def dict_compare(d1, d2):
# def convert_to_snake_case(camel_case):
# def create_output_filename_with_date(filename):
# def add_date_to_filename(filename, **kwargs):
# def deprecated(func):
#     def new_func(*args, **kwargs):
# def daterange(start_date, end_date):
# def weekdays(start_date, end_date):
#     def __init__(self, newPath):
#     def __enter__(self):
#     def __exit__(self, etype, value, traceback):
# def force_date_to_datetime(unconverted_date, tzinfo=pytz.UTC):
#     def __init__(self):
#     def start(self):
#     def stop(self):
#     def reset(self):
#     def get_elapsed_time(self):
#     def get_elapsed_time_str(self):
#     def running(self):
#     def __enter__(self):
#     def __exit__(self, *args):
# def load_json_file(filename):
# def datetime_to_local_time(date_time):
#     def __init__(self):
#     def _get_date_parts(self, match, input_lang='es'):
#     def parse(self, str_date):
#     def to_string(self, m_date):
# def parse_spanish_date(str_date):
# class cd:
# class Timer:
# class SpanishDate(object):


# Path: tests/test_utils.py
import datetime
import logging
import os
import pytz
from unittest import mock
from django.test import TestCase, SimpleTestCase
from django.test import override_settings
from django_test_tools.file_utils import TemporaryFolder, hash_file
from django_test_tools.utils import Timer, add_date_to_filename, daterange, parse_spanish_date, spanish_date_util, \
    create_output_filename_with_date, dict_compare, convert_to_snake_case, datetime_to_local_time

    def test_daterange_one_day(self):
        start_date = datetime.date(2016, 10, 3)  # Monday
        end_date = start_date
        days = list(daterange(start_date, end_date))
        self.assertEqual(1, len(days))

    def test_parse_spanish_date(self):
        start_date = datetime.date(2016, 12, 3)  # Monday
        result = parse_spanish_date('03-Dic-16')
        self.assertTrue(result, start_date)

    def test_parse_spanish_date_datetime(self):
        start_date = datetime.datetime(2016, 12, 3, 13, 50)  # Monday
        result = parse_spanish_date('03-Dic-16 13:50')
        self.assertTrue(result, start_date)


class TestSpanishDate(TestCase):
    def test_to_string(self):
        start_date = datetime.date(2016, 12, 3)
        str_date = spanish_date_util.to_string(start_date)
        self.assertEqual('03-Dic-16', str_date)

    def test_to_string_datetime(self):
        start_date = datetime.datetime(2016, 12, 3, 16, 15)
        str_date = spanish_date_util.to_string(start_date)
        self.assertEqual('03-Dic-16 16:15', str_date)

    def test_parse(self):
        start_date = datetime.datetime(2016, 12, 3, 13, 50)

        result = spanish_date_util.parse('03-Dic-16 13:50')