<commit_before># -*- coding: utf-8 -*-
"""Test the tcex.utils package."""

import datetime
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".")))
import utility


def test_date_to_datetime():
    starting_date = datetime.datetime.now()
    tcex_instance = utility.init_tcex(clean_data=False)
    new_date = tcex_instance.utils.date_to_datetime(str(starting_date))
    assert new_date.year == starting_date.year
    assert new_date.month == starting_date.month
    assert new_date.day == starting_date.day
    assert new_date.hour == starting_date.hour

    # try the same thing again with a different timezone
    tcex_instance = utility.init_tcex(clean_data=False)
    new_date = tcex_instance.utils.date_to_datetime(str(datetime.datetime.now()), tz='UTC')
    # make sure the hour is different b/c of the different timezone
    assert new_date.hour != starting_date.hour<commit_msg>Adding test for timedelta function<commit_after># -*- coding: utf-8 -*-
"""Test the tcex.utils package."""

import datetime
import os
import sys

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".")))
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
import utility


def test_date_to_datetime():
    starting_date = datetime.datetime.now()
    tcex_instance = utility.init_tcex(clean_data=False)
    new_date = tcex_instance.utils.date_to_datetime(str(starting_date))
    assert new_date.year == starting_date.year
    assert new_date.month == starting_date.month
    assert new_date.day == starting_date.day
    assert new_date.hour == starting_date.hour

    # try the same thing again with a different timezone
    tcex_instance = utility.init_tcex(clean_data=False)
    new_date = tcex_instance.utils.date_to_datetime(str(datetime.datetime.now()), tz='UTC')
    # make sure the hour is different b/c of the different timezone
    assert new_date.hour != starting_date.hour


def test_timedelta():
    from tcex import tcex_utils
    utils = tcex_utils.TcExUtils()
    delta = utils.timedelta('2018-01-13', '2018-02-14')
    assert delta['days'] == -1
    assert delta['total_days'] == -32
    assert delta['hours'] == 0
    assert delta['total_weeks'] == -4
{'fraction_non_alphanumeric': 0.1219946571682992, 'fraction_numerical': 0.010240427426536063, 'mean_word_length': 4.33729216152019, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6579519', 'n_tokens_mistral': 765, 'n_tokens_neox': 719, 'n_words': 155}