~ubuntu-branches/ubuntu/natty/schooltool.gradebook/natty

« back to all changes in this revision

Viewing changes to src/schooltool/requirement/testing.py

  • Committer: Bazaar Package Importer
  • Author(s): Gediminas Paulauskas
  • Date: 2011-02-24 16:53:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110224165353-hi69ckyal3b8dyns
Tags: upstream-0.9.0~a1
ImportĀ upstreamĀ versionĀ 0.9.0~a1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# SchoolTool - common information systems platform for school administration
 
3
# Copyright (c) 2005 Shuttleworth Foundation
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
#
 
19
"""Testing setup for schooltool.requirement
 
20
 
 
21
$Id$
 
22
"""
 
23
__docformat__ = 'reStructuredText'
 
24
 
 
25
from zope.interface import Interface
 
26
from zope.component import provideAdapter
 
27
from zope.keyreference.interfaces import IKeyReference
 
28
 
 
29
from schooltool.requirement import requirement, interfaces, evaluation
 
30
 
 
31
class KeyReferenceStub(object):
 
32
    """A stub implementation to allow testing of evaluations."""
 
33
 
 
34
    key_type_id = 'tests.path'
 
35
 
 
36
    def __init__(self, context):
 
37
        self.context = context
 
38
 
 
39
    def __call__(self):
 
40
        return self.context
 
41
 
 
42
    def __hash__(self):
 
43
        return id(self.context)
 
44
 
 
45
    def __cmp__(self, ref):
 
46
        return cmp((self.key_type_id, self.__hash__()),
 
47
                   (ref.key_type_id, ref.__hash__()))
 
48
 
 
49
def setUpRequirement(test=None):
 
50
    provideAdapter(requirement.getRequirement,
 
51
                   (Interface,),
 
52
                   interfaces.IRequirement)
 
53
 
 
54
def setUpEvaluation(test=None):
 
55
    provideAdapter(evaluation.getEvaluations,
 
56
                   (Interface,),
 
57
                   interfaces.IEvaluations)
 
58
    provideAdapter(KeyReferenceStub,
 
59
                   (Interface,),
 
60
                   IKeyReference)
 
61
def fixDecimal():
 
62
    """
 
63
    Monkey patch the decimal module to get the same output on python2.6
 
64
    See http://mail.python.org/pipermail/python-dev/2008-July/081420.html
 
65
    """
 
66
    import decimal
 
67
    decimal.Decimal.__repr__ = lambda s: 'Decimal("%s")' % str(s)