aboutsummaryrefslogtreecommitdiff
path: root/python/google/protobuf/internal/text_format_test.py
diff options
context:
space:
mode:
authorkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-23 02:01:01 +0000
committerkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-12-23 02:01:01 +0000
commitd0047c43d955174d79a2df623dbb4007965252b5 (patch)
tree43b2b4dbffe90e2ca7b00da247c6a631484d0bde /python/google/protobuf/internal/text_format_test.py
parenteef5f8396dd527c17ab7e419ca8781052031d05d (diff)
downloadprotobuf-d0047c43d955174d79a2df623dbb4007965252b5.tar.gz
protobuf-d0047c43d955174d79a2df623dbb4007965252b5.tar.bz2
protobuf-d0047c43d955174d79a2df623dbb4007965252b5.zip
In Python, avoid relying on float('inf') and float('nan') as these don't work on Windows with Python pre-2.6.
Diffstat (limited to 'python/google/protobuf/internal/text_format_test.py')
-rwxr-xr-xpython/google/protobuf/internal/text_format_test.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/python/google/protobuf/internal/text_format_test.py b/python/google/protobuf/internal/text_format_test.py
index 6d46f7e4..e0991cb1 100755
--- a/python/google/protobuf/internal/text_format_test.py
+++ b/python/google/protobuf/internal/text_format_test.py
@@ -325,10 +325,10 @@ class TokenizerTest(unittest.TestCase):
'{',
(tokenizer.ConsumeIdentifier, 'A'),
':',
- (tokenizer.ConsumeFloat, float('inf')),
+ (tokenizer.ConsumeFloat, text_format._INFINITY),
(tokenizer.ConsumeIdentifier, 'B'),
':',
- (tokenizer.ConsumeFloat, float('-inf')),
+ (tokenizer.ConsumeFloat, -text_format._INFINITY),
(tokenizer.ConsumeIdentifier, 'C'),
':',
(tokenizer.ConsumeBool, True),
@@ -413,6 +413,16 @@ class TokenizerTest(unittest.TestCase):
tokenizer = text_format._Tokenizer(text)
self.assertRaises(text_format.ParseError, tokenizer.ConsumeBool)
+ def testInfNan(self):
+ # Make sure our infinity and NaN definitions are sound.
+ self.assertEquals(float, type(text_format._INFINITY))
+ self.assertEquals(float, type(text_format._NAN))
+ self.assertTrue(text_format._NAN != text_format._NAN)
+
+ inf_times_zero = text_format._INFINITY * 0
+ self.assertTrue(inf_times_zero != inf_times_zero)
+ self.assertTrue(text_format._INFINITY > 0)
+
if __name__ == '__main__':
unittest.main()