Skip to content

Commit

Permalink
Add tests for parsing timestamps and the UTC flag
Browse files Browse the repository at this point in the history
  • Loading branch information
0x64746b committed May 11, 2014
1 parent 1721b6c commit c601b4c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/test_datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# coding: utf-8

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from datetime import datetime
import unittest

from ctx_parser import date_time


class TestTheDateTimeModule(unittest.TestCase):

def test_can_parse_timestamps(self):
# setup test data
test_timestamp = 1399846525

test_element = '"{}"'.format(test_timestamp)

# test parsing of timestamp
parsed_elements = date_time.TIMESTAMP.parseString(test_element)

# check result
self.assertEqual(
parsed_elements[0],
datetime.fromtimestamp(test_timestamp)
)

def test_can_parse_set_utc_flags(self):
# setup test data
test_bit = 1
test_flag = 'int inUtc="{}"'.format(test_bit)

# test parsing of flag
parsed_elements = date_time.UTC_FLAG.parseString(test_flag)

# check result
self.assertEqual(parsed_elements.inUtc, True)

def test_can_parse_unset_utc_flags(self):
# setup test data
test_bit = 0
test_flag = 'int inUtc="{}"'.format(test_bit)

# test parsing of flag
parsed_elements = date_time.UTC_FLAG.parseString(test_flag)

# check result
self.assertEqual(parsed_elements.inUtc, False)

0 comments on commit c601b4c

Please sign in to comment.