<commit_before>#
# test.py
# CloudKitPy
#
# Created by <NAME> on 30/04/2016.
# Copyright (c) 2016 <NAME> - Pig on a Hill Productions.
#

# !/usr/bin/env python

import unittest
from datetime import datetime
import time
from cloudkitpy.cloudkit import CloudKit
from cloudkitpy.value import CKValue
from cloudkitpy.datatypes import Asset
from cloudkitpy.datatypes import Filter
from cloudkitpy.datatypes import Location
from cloudkitpy.datatypes import NotificationInfo
from cloudkitpy.datatypes import Query
from cloudkitpy.datatypes import Record
from cloudkitpy.datatypes import Reference
from cloudkitpy.datatypes import SortDescriptor
from cloudkitpy.datatypes import Subscription
from cloudkitpy.datatypes import UserInfo
from cloudkitpy.datatypes import Zone
from cloudkitpy.datatypes import ZoneID
from cloudkitpy.datatypes import CloudKitConfig
from cloudkitpy.datatypes import ContainerConfig


class CKValueTests(unittest.TestCase):

    def test_string_value(self):
        string = 'Hello World'
        comp_value = {
            'value': string,
            'type': 'STRING'
        }
        gen_value = CKValue(string)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_int_value(self):
        integer = 1234
        comp_value = {
            'value': integer,
            'type': 'NUMBER_INT64'
        }
        gen_value = CKValue(integer)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_double_value(self):
        double = 1234.56789
        comp_value = {
            'value': double,
            'type': 'NUMBER_DOUBLE'
        }
        gen_value = CKValue(double)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_bool_value(self):
        boolean = False
        comp_value = {
            'value': boolean,
        }
        gen_value = CKValue(boolean)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_datetime_value(self):
        date = datetime.utcnow()
        timestamp = time.mktime(date.timetuple())
        comp_value = {
            'value': timestamp,
        }
        gen_value = CKValue(date)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_list_value(self):
        list_array = ['a', 'b', 'c']
        comp_value = {<commit_msg>Fixed date timestamp tests.<commit_after>#
# test.py
# CloudKitPy
#
# Created by <NAME> on 30/04/2016.
# Copyright (c) 2016 <NAME> - Pig on a Hill Productions.
#

# !/usr/bin/env python

import unittest
from datetime import datetime
import time
from cloudkitpy.cloudkit import CloudKit
from cloudkitpy.value import CKValue
from cloudkitpy.datatypes import Asset
from cloudkitpy.datatypes import Filter
from cloudkitpy.datatypes import Location
from cloudkitpy.datatypes import NotificationInfo
from cloudkitpy.datatypes import Query
from cloudkitpy.datatypes import Record
from cloudkitpy.datatypes import Reference
from cloudkitpy.datatypes import SortDescriptor
from cloudkitpy.datatypes import Subscription
from cloudkitpy.datatypes import UserInfo
from cloudkitpy.datatypes import Zone
from cloudkitpy.datatypes import ZoneID
from cloudkitpy.datatypes import CloudKitConfig
from cloudkitpy.datatypes import ContainerConfig


class CKValueTests(unittest.TestCase):

    def test_string_value(self):
        string = 'Hello World'
        comp_value = {
            'value': string,
            'type': 'STRING'
        }
        gen_value = CKValue(string)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_int_value(self):
        integer = 1234
        comp_value = {
            'value': integer,
            'type': 'NUMBER_INT64'
        }
        gen_value = CKValue(integer)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_double_value(self):
        double = 1234.56789
        comp_value = {
            'value': double,
            'type': 'NUMBER_DOUBLE'
        }
        gen_value = CKValue(double)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_bool_value(self):
        boolean = False
        comp_value = {
            'value': boolean,
        }
        gen_value = CKValue(boolean)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(comp_value == gen_json_value.json())

    def test_datetime_value(self):
        date = datetime.utcnow()
        timestamp = time.mktime(date.timetuple())
        comp_value = {
            'value': int(timestamp * 1000),
            'type': 'TIMESTAMP'
        }
        gen_value = CKValue(date)
        gen_json_value = CKValue(json=comp_value)
        self.failUnless(comp_value == gen_value.json())
        self.failUnless(date.timetuple() == gen_json_value.value.timetuple())

    def test_list_value(self):
        list_array = ['a', 'b', 'c']
        comp_value = {
{'fraction_non_alphanumeric': 0.09325431410144674, 'fraction_numerical': 0.010109813491371798, 'mean_word_length': 2.9274469541409993, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3760285', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1750, 'n_words': 374}