[Zope3-checkins] CVS: Packages/ZConfig/tests - test_datatypes.py:1.1.2.1 test_schema.py:1.1.2.30

Fred L. Drake, Jr. fred@zope.com
Fri, 20 Dec 2002 12:08:14 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	test_schema.py 
Added Files:
      Tag: zconfig-schema-devel-branch
	test_datatypes.py 
Log Message:
Separate tests of the provided datatypes in ZConfig.datatypes into a separate
test module, test_datatypes.


=== Added File Packages/ZConfig/tests/test_datatypes.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of standard ZConfig datatypes."""

import sys
import unittest

from socket import AF_INET, AF_UNIX

import ZConfig.datatypes


class DatatypeTestCase(unittest.TestCase):
    types = ZConfig.datatypes.Registry()

    def test_datatype_basickey(self):
        convert = self.types.get("basic-key")
        eq = self.assertEqual
        raises = self.assertRaises

        eq(convert("abc"), "abc")
        eq(convert("ABC_DEF.123"), "abc_def.123")
        eq(convert("Abc-Def-456"), "abc-def-456")
        eq(convert("Abc.Def"), "abc.def")

        raises(ValueError, convert, "_abc")
        raises(ValueError, convert, "-abc")
        raises(ValueError, convert, "123")
        raises(ValueError, convert, "")

    def test_datatype_boolean(self):
        convert = self.types.get("boolean")
        check = self.assert_
        raises = self.assertRaises

        check(convert("on"))
        check(convert("true"))
        check(convert("yes"))
        check(not convert("off"))
        check(not convert("false"))
        check(not convert("no"))
        raises(ValueError, convert, '0')
        raises(ValueError, convert, '1')
        raises(ValueError, convert, '')
        raises(ValueError, convert, 'junk')

    def test_datatype_identifier(self):
        convert = self.types.get("identifier")
        eq = self.assertEqual
        raises = self.assertRaises

        eq(convert("AbcDef"), "AbcDef")
        eq(convert("a________"), "a________")
        eq(convert("abc_def"), "abc_def")
        eq(convert("int123"), "int123")
        eq(convert("_abc"), "_abc")
        eq(convert("_123"), "_123")
        eq(convert("__dict__"), "__dict__")
        raises(ValueError, convert, "2345")
        raises(ValueError, convert, "-abc")
        raises(ValueError, convert, "-123")
        raises(ValueError, convert, "")

    def test_datatype_integer(self):
        convert = self.types.get("integer")
        eq = self.assertEqual
        raises = self.assertRaises

        eq(convert('-100'), -100)
        eq(convert('-1'), -1)
        eq(convert('-0'), 0)
        eq(convert('0'), 0)
        eq(convert('1'), 1)
        eq(convert('100'), 100)
        eq(convert('65535'), 65535)
        eq(convert('65536'), 65536)

        big = sys.maxint + 1L  # Python 2.1 needs the L suffix here
        s = str(big)           # s won't have the suffix
        eq(convert(s), big)
        eq(convert("-" + s), -big)

        raises(ValueError, convert, 'abc')
        raises(ValueError, convert, '-0xabc')
        raises(ValueError, convert, '')
        raises(ValueError, convert, '123 456')
        raises(ValueError, convert, '123-')

    def test_datatype_locale(self):
        convert = self.types.get("locale")
        # Python supports "C" even when the _locale module is not available
        self.assertEqual(convert("C"), "C")
        self.assertRaises(ValueError, convert, "locale-does-not-exist")

    def test_datatype_port(self):
        convert = self.types.get("port-number")
        eq = self.assertEqual
        raises = self.assertRaises

        raises(ValueError, convert, '-1')
        raises(ValueError, convert, '0')
        eq(convert('1'), 1)
        eq(convert('80'), 80)
        eq(convert('1023'), 1023)
        eq(convert('1024'), 1024)
        eq(convert('60000'), 60000)
        eq(convert('65535'), 0xffff)
        raises(ValueError, convert, '65536')


def test_suite():
    return unittest.makeSuite(DatatypeTestCase)

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')


=== Packages/ZConfig/tests/test_schema.py 1.1.2.29 => 1.1.2.30 ===
--- Packages/ZConfig/tests/test_schema.py:1.1.2.29	Fri Dec 20 11:24:51 2002
+++ Packages/ZConfig/tests/test_schema.py	Fri Dec 20 12:08:13 2002
@@ -14,20 +14,15 @@
 """Tests of ZConfig schemas."""
 
 import StringIO
-import sys
 import unittest
 import urlparse
 
 import ZConfig
-import ZConfig.datatypes
 
 from ZConfig.loader import ConfigLoader
 from ZConfig.tests.test_config import CONFIG_BASE
 
 
-types = ZConfig.datatypes.Registry()
-
-
 def uppercase(value):
     return str(value).upper()
 
@@ -385,102 +380,6 @@
                           "  <key name='+' attribute='attr1'/>"
                           "  <key name='+' attribute='attr2'/>"
                           "</schema>")
-
-    # datatype tests
-
-    def test_datatype_basickey(self):
-        convert = types.get("basic-key")
-        eq = self.assertEqual
-        raises = self.assertRaises
-
-        eq(convert("abc"), "abc")
-        eq(convert("ABC_DEF.123"), "abc_def.123")
-        eq(convert("Abc-Def-456"), "abc-def-456")
-        eq(convert("Abc.Def"), "abc.def")
-
-        raises(ValueError, convert, "_abc")
-        raises(ValueError, convert, "-abc")
-        raises(ValueError, convert, "123")
-        raises(ValueError, convert, "")
-
-    def test_datatype_boolean(self):
-        convert = types.get("boolean")
-        check = self.assert_
-        raises = self.assertRaises
-
-        check(convert("on"))
-        check(convert("true"))
-        check(convert("yes"))
-        check(not convert("off"))
-        check(not convert("false"))
-        check(not convert("no"))
-        raises(ValueError, convert, '0')
-        raises(ValueError, convert, '1')
-        raises(ValueError, convert, '')
-        raises(ValueError, convert, 'junk')
-
-    def test_datatype_identifier(self):
-        convert = types.get("identifier")
-        eq = self.assertEqual
-        raises = self.assertRaises
-
-        eq(convert("AbcDef"), "AbcDef")
-        eq(convert("a________"), "a________")
-        eq(convert("abc_def"), "abc_def")
-        eq(convert("int123"), "int123")
-        eq(convert("_abc"), "_abc")
-        eq(convert("_123"), "_123")
-        eq(convert("__dict__"), "__dict__")
-        raises(ValueError, convert, "2345")
-        raises(ValueError, convert, "-abc")
-        raises(ValueError, convert, "-123")
-        raises(ValueError, convert, "")
-
-    def test_datatype_integer(self):
-        convert = types.get("integer")
-        eq = self.assertEqual
-        raises = self.assertRaises
-
-        eq(convert('-100'), -100)
-        eq(convert('-1'), -1)
-        eq(convert('-0'), 0)
-        eq(convert('0'), 0)
-        eq(convert('1'), 1)
-        eq(convert('100'), 100)
-        eq(convert('65535'), 65535)
-        eq(convert('65536'), 65536)
-
-        big = sys.maxint + 1L  # Python 2.1 needs the L suffix here
-        s = str(big)           # s won't have the suffix
-        eq(convert(s), big)
-        eq(convert("-" + s), -big)
-
-        raises(ValueError, convert, 'abc')
-        raises(ValueError, convert, '-0xabc')
-        raises(ValueError, convert, '')
-        raises(ValueError, convert, '123 456')
-        raises(ValueError, convert, '123-')
-
-    def test_datatype_locale(self):
-        convert = types.get("locale")
-        # Python supports "C" even when the _locale module is not available
-        self.assertEqual(convert("C"), "C")
-        self.assertRaises(ValueError, convert, "locale-does-not-exist")
-
-    def test_datatype_port(self):
-        convert = types.get("port-number")
-        eq = self.assertEqual
-        raises = self.assertRaises
-
-        raises(ValueError, convert, '-1')
-        raises(ValueError, convert, '0')
-        eq(convert('1'), 1)
-        eq(convert('80'), 80)
-        eq(convert('1023'), 1023)
-        eq(convert('1024'), 1024)
-        eq(convert('60000'), 60000)
-        eq(convert('65535'), 0xffff)
-        raises(ValueError, convert, '65536')
 
 
 def test_suite():