Skip to content

Commit

Permalink
Add 3 tests for simple elements
Browse files Browse the repository at this point in the history
Test parsing of string and int values as well as timestamps.
  • Loading branch information
0x64746b committed May 8, 2014
1 parent 06792c0 commit f2d49a4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,39 @@ def test_can_parse_composed_elements_containing_simple_elements(self):
# check result
self.assertEqual(parsed_element.testElement.aValue, test_value_1)
self.assertEqual(parsed_element.testElement.anotherValue, test_value_2)

def test_can_parse_simple_elements_containing_strings(self):
# setup test data
test_value = 'test_value'
test_element = 'char testString="{}"'.format(test_value)

# test parsing of simple string value
parsed_element = parser.SIMPLE_ELEMENT.parseString(test_element)

# check result
self.assertEqual(parsed_element.testString, test_value)

def test_can_parse_simple_elements_containing_integers(self):
# setup test data
test_value = 2342
test_element = 'int testInteger="{}"'.format(test_value)

# test parsing of simple integer value
parsed_element = parser.SIMPLE_ELEMENT.parseString(test_element)

# check result
self.assertEqual(parsed_element.testInteger, test_value)

def test_can_parse_simple_elements_containing_timestamps(self):
# setup test data
test_timestamp = 1399585500
test_element = 'int time="{}"'.format(test_timestamp)

# test parsing of timestamp
parsed_element = parser.SIMPLE_ELEMENT.parseString(test_element)

# check result
self.assertEqual(
parsed_element.time,
datetime.fromtimestamp(test_timestamp)
)

0 comments on commit f2d49a4

Please sign in to comment.