Permalink
Browse files

Rewrite test_encoding to call the top-level API rather than something…

… deeper down.

This way, I can refactor the JSON encoding stuff without changing the tests.

Change 12.2 to 12.25 in the test data so it can be exactly represented in IEEE floating point. Otherwise, it comes out as 12.19999999 in py26, and I'd have to put more logic in the tests.
  • Loading branch information...
1 parent 89f4a46 commit c4f0a8b6c39d65324c267a454dcb1e0f122b63e2 @erikrose erikrose committed Mar 20, 2013
Showing with 14 additions and 10 deletions.
  1. +14 −10 pyelasticsearch/tests.py
View
@@ -672,16 +672,20 @@ def test_tuple_encoding(self):
def test_encoding(self):
"""Test encoding a zillion other types."""
- self.assertEqual(self.conn.from_python('abc'), u'abc')
- self.assertEqual(self.conn.from_python(u''), u'')
- self.assertEqual(self.conn.from_python(123), 123)
- self.assertEqual(self.conn.from_python(12.2), 12.2)
- self.assertEqual(self.conn.from_python(True), True)
- self.assertEqual(self.conn.from_python(False), False)
- self.assertEqual(self.conn.from_python(date(2011, 12, 30)), '2011-12-30T00:00:00')
- self.assertEqual(self.conn.from_python(datetime(2011, 12, 30, 11, 59, 32)), '2011-12-30T11:59:32')
- self.assertEqual(self.conn.from_python([1, 2, 3]), [1, 2, 3])
- self.assertEqual(self.conn.from_python({'a': 1, 'b': 3, 'c': 2}), {'a': 1, 'b': 3, 'c': 2})
+ self.assertEqual(self.conn._encode_json('abc'), u'"abc"')
+ self.assertEqual(self.conn._encode_json(u''), r'"\u2603"')
+ self.assertEqual(self.conn._encode_json(123), '123')
+ self.assertEqual(self.conn._encode_json(12.25), '12.25')
+ self.assertEqual(self.conn._encode_json(True), 'true')
+ self.assertEqual(self.conn._encode_json(False), 'false')
+ self.assertEqual(self.conn._encode_json(
+ date(2011, 12, 30)),
+ '"2011-12-30T00:00:00"')
+ self.assertEqual(self.conn._encode_json(
+ datetime(2011, 12, 30, 11, 59, 32)),
+ '"2011-12-30T11:59:32"')
+ self.assertEqual(self.conn._encode_json([1, 2, 3]), '[1, 2, 3]')
+ self.assertEqual(self.conn._encode_json({'a': 1}), '{"a": 1}')
if __name__ == '__main__':

0 comments on commit c4f0a8b

Please sign in to comment.