/usr/share/pyshared/zope/schema/tests/test_date.py is in python-zope.schema 3.7.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Date field tests
"""
from unittest import main, makeSuite
from zope.schema import Date
from zope.schema.interfaces import RequiredMissing, InvalidValue, WrongType
from zope.schema.interfaces import TooSmall, TooBig
from zope.schema.tests.test_field import FieldTestBase
from datetime import datetime, date
class DateTest(FieldTestBase):
"""Test the Date Field."""
_Field_Factory = Date
def testInterface(self):
from zope.interface.verify import verifyObject
from zope.schema.interfaces import IDate
verifyObject(IDate, self._Field_Factory())
def testValidate(self):
field = self._Field_Factory(title=u'Date field', description=u'',
readonly=False, required=False)
field.validate(None)
field.validate(datetime.now().date())
self.assertRaises(WrongType, field.validate, datetime.now())
def testValidateRequired(self):
field = self._Field_Factory(title=u'Date field', description=u'',
readonly=False, required=True)
field.validate(datetime.now().date())
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMin(self):
d1 = date(2000,10,1)
d2 = date(2000,10,2)
field = self._Field_Factory(title=u'Date field', description=u'',
readonly=False, required=False, min=d1)
field.validate(None)
field.validate(d1)
field.validate(d2)
field.validate(datetime.now().date())
self.assertRaises(TooSmall, field.validate, date(2000,9,30))
def testValidateMax(self):
d1 = date(2000,10,1)
d2 = date(2000,10,2)
d3 = date(2000,10,3)
field = self._Field_Factory(title=u'Date field', description=u'',
readonly=False, required=False, max=d2)
field.validate(None)
field.validate(d1)
field.validate(d2)
self.assertRaises(TooBig, field.validate, d3)
def testValidateMinAndMax(self):
d1 = date(2000,10,1)
d2 = date(2000,10,2)
d3 = date(2000,10,3)
d4 = date(2000,10,4)
d5 = date(2000,10,5)
field = self._Field_Factory(title=u'Date field', description=u'',
readonly=False, required=False,
min=d2, max=d4)
field.validate(None)
field.validate(d2)
field.validate(d3)
field.validate(d4)
self.assertRaises(TooSmall, field.validate, d1)
self.assertRaises(TooBig, field.validate, d5)
def test_suite():
suite = makeSuite(DateTest)
return suite
if __name__ == '__main__':
main(defaultTest='test_suite')
|