<commit_before>""" Tests of the utils module.
"""
try:
    # Try importing from unittest2 first. This is primarily for Py2.6 support.
    import unittest2 as unittest
except ImportError:
    import unittest

import datetime
import xero.utils


class UtilsTest(unittest.TestCase):
    """ Test of the utils module.
    """
    def test_json_hook(self):
        """ Tests the json hook used in Manager._parse_api_response, and the
            call it makes to parse_date.
        """
        example_input = {
            'data': {
                'Status': 'OK',
            },
        }

        self.assertEqual(
            xero.utils.json_load_object_hook(example_input),
            example_input
        )

        # The hook parses dates
        example_input = {
            'data': {
                'Status': 'OK',
            },
            'date': '/Date(1426849200000+1300)/',
        }

        excepted_output = {
            'data': {
                'Status': 'OK',
            },
            'date': datetime.datetime(2015, 3, 21, 0, 0),
        }

        self.assertEqual(
            xero.utils.json_load_object_hook(example_input),
            excepted_output
        )<commit_msg>Further testing of date parsing #5<commit_after>""" Tests of the utils module.
"""
try:
    # Try importing from unittest2 first. This is primarily for Py2.6 support.
    import unittest2 as unittest
except ImportError:
    import unittest

import datetime
import xero.utils


class UtilsTest(unittest.TestCase):
    """ Test of the utils module.
    """
    def test_json_hook(self):
        """ Tests the json hook used in Manager._parse_api_response, and the
            call it makes to parse_date.
        """
        example_input = {
            'data': {
                'Status': 'OK',
            },
        }

        self.assertEqual(
            xero.utils.json_load_object_hook(example_input),
            example_input
        )

        # The hook parses dates
        example_input = {
            'data': {
                'Status': 'OK',
            },
            'date': '/Date(1426849200000+1300)/',
        }

        excepted_output = {
            'data': {
                'Status': 'OK',
            },
            'date': datetime.datetime(2015, 3, 21, 0, 0),
        }

        self.assertEqual(
            xero.utils.json_load_object_hook(example_input),
            excepted_output
        )

    def test_parse_date(self):
        """ Tests of the parse_date input formats.
        """
        # 07/05/2015 00:00:00 +12 (06/05/2015 12:00:00 GMT/UTC)
        self.assertEqual(
            xero.utils.parse_date('/Date(1430913600000+1200)/'),
            datetime.datetime(2015, 5, 7, 0, 0)
        )

        # 16/09/2008 10:28:51.5 +12 (15/09/2008 22:25:51.5 GMT/UTC)
        self.assertEqual(
            xero.utils.parse_date('/Date(1221517731500+1200)/'),
            datetime.datetime(2008, 9, 16, 10, 28, 51, 500000)
        )

        # 10/08/2015 10:55:33 GMT/UTC
        self.assertEqual(
            xero.utils.parse_date('/Date(1439204133355)/'),
            datetime.datetime(2015, 8, 10, 10, 55, 33, 355000)
        )
{'fraction_non_alphanumeric': 0.11441213653603034, 'fraction_numerical': 0.07269279393173199, 'mean_word_length': 1.661900756938604, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4373347', 'n_tokens_mistral': 1108, 'n_tokens_neox': 926, 'n_words': 219}