[Zodb-checkins] CVS: Packages/ZConfig/tests - test_datatypes.py:1.1.2.3

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 13:40:33 -0500


Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv4405

Modified Files:
      Tag: zconfig-schema-devel-branch
	test_datatypes.py 
Log Message:
Add a test for the float datatype.


=== Packages/ZConfig/tests/test_datatypes.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/tests/test_datatypes.py:1.1.2.2	Fri Dec 20 12:38:24 2002
+++ Packages/ZConfig/tests/test_datatypes.py	Fri Dec 20 13:40:33 2002
@@ -55,6 +55,31 @@
         raises(ValueError, convert, '')
         raises(ValueError, convert, 'junk')
 
+    def test_datatype_float(self):
+        convert = self.types.get("float")
+        eq = self.assertEqual
+        raises = self.assertRaises
+
+        eq(convert("1"), 1.0)
+        self.assert_(type(convert(1)) is type(1.0))
+        eq(convert("1.1"), 1.1)
+        eq(convert("50.50"), 50.50)
+        eq(convert("-50.50"), -50.50)
+        eq(convert(0), 0.0)
+        eq(convert("0"), 0.0)
+        eq(convert("-0"), 0.0)
+        eq(convert("0.0"), 0.0)
+
+        raises(ValueError, convert, "junk")
+        raises(ValueError, convert, "0x234.1.9")
+        raises(ValueError, convert, "0.9-")
+
+        # These are not portable representations; make sure they are
+        # disallowed everywhere for consistency.
+        raises(ValueError, convert, "inf")
+        raises(ValueError, convert, "-inf")
+        raises(ValueError, convert, "nan")
+
     def test_datatype_identifier(self):
         convert = self.types.get("identifier")
         eq = self.assertEqual