Ignore:
Timestamp:
26 Jun 2009, 12:18:29 (15 years ago)
Author:
uli
Message:

Make course container tests sphinx-aware.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/coursecontainer.txt

    r4261 r4364  
    1 CourseContainer
    2 ****************
     1:mod:`waeup.university.coursecontainer` -- Course containers
     2************************************************************
     3
     4.. module:: waeup.university.coursecontainer
    35
    46Containers for courses.
     
    68:Test-Layer: unit
    79
     10Because this module makes use of components registered with the Zope
     11Component Architecture (ZCA), we first have to grok the `waeup`
     12package if we want to deploy it. This happens automatically in
     13real-world use:
     14
     15    >>> import grok
     16    >>> grok.testing.grok('waeup')
     17
     18Content Classes (models and containers)
     19=======================================
     20
     21:class:`CourseContainer`
     22------------------------
     23
     24.. class:: CourseContainer()
     25
     26   Create a course container instance.
     27
     28   .. attribute:: grok.implements(ICourseContainer)
     29
     30   .. attribute:: grok.require('waeup.manageUniversity')
     31
     32   :class:`CourseContainer` instances are instances of
     33   :class:`grok.Container` that hold and manage instances of
     34   :class:`waeup.university.course.Course`.
     35
     36     >>> from waeup.university.coursecontainer import CourseContainer
     37     >>> mycontainer = CourseContainer()
     38     >>> mycontainer
     39     <waeup.university.coursecontainer.CourseContainer object at 0x...>
     40
     41   Course containers provide `ICourseContainer`:
     42
     43     >>> from waeup.interfaces import ICourseContainer
     44     >>> ICourseContainer.providedBy(mycontainer)
     45     True
     46
     47   We can be sure, that the full interface is supported by the
     48   CourseContainer class:
     49
     50     >>> from zope.interface.verify import verifyClass
     51     >>> verifyClass(ICourseContainer, CourseContainer)
     52     True
     53
     54   As normal ``grok.Container``, :class:`CourseContainer` instances
     55   can be used like dicts:
     56
     57     >>> list(mycontainer.keys())
     58     []
     59
     60   .. method:: addCourse(course)
     61
     62      Add a course.
     63
     64      *course* must be an instance of
     65      :class:`waeup.university.course.Course`:
     66
     67        >>> from waeup.university.coursecontainer import CourseContainer
     68        >>> mycontainer = CourseContainer()
     69        >>> mycontainer.addCourse('blah')
     70        Traceback (most recent call last):
     71        ...
     72        TypeError: CourseContainers contain only ICourse instances
     73
     74      The key of added items is the ``code`` attribute:
     75
     76        >>> from waeup.university.course import Course
     77        >>> mycourse = Course(code='COURSE1')
     78        >>> mycontainer.addCourse(mycourse)
     79        >>> list(mycontainer.keys())
     80        [u'COURSE1']
     81
     82   .. method:: clear()
     83
     84      Remove all contained courses:
     85
     86        >>> len(mycontainer.items())
     87        1
     88
     89        >>> mycontainer.clear()
     90        >>> len(mycontainer.items())
     91        0
     92
     93Utilities
     94=========
     95
     96:class:`CourseContainerFactory`
     97-------------------------------
     98
     99.. class:: CourseContainerFactory()
     100
     101   .. attribute:: grok.name(u'waeup.CourseContainer')
     102
     103   .. attribute:: grok.implements(IFactory)
     104
     105   A named utility to deliver new instances of :class:`CourseContainer`
     106   without the need to import the implementation before:
     107
     108     >>> from zope.component import createObject
     109     >>> mycoursecontainer = createObject(u'waeup.CourseContainer')
     110     >>> mycoursecontainer
     111     <waeup.university.coursecontainer.CourseContainer object at 0x...>
     112
     113   The factory complies with the specifications from the
     114   :class:`IFactory` insterface:
     115
     116     >>> from zope.interface.verify import verifyClass
     117     >>> from zope.component.interfaces import IFactory
     118     >>> from waeup.university.coursecontainer import CourseContainerFactory
     119     >>> verifyClass(IFactory, CourseContainerFactory)
     120     True
     121
     122   This means also, that we can get the interfaces of the created
     123   object from the factory:
     124
     125     >>> coursecontainer_factory = CourseContainerFactory()
     126     >>> coursecontainer_factory.getInterfaces()
     127     <implementedBy waeup.university.coursecontainer.CourseContainer>
     128
     129
     130Examples
     131========
     132
    8133Getting a course container
    9 ===========================
     134--------------------------
    10135
    11136We can easily create `CourseContainers`:
     
    14139    >>> mycontainer = CourseContainer()
    15140
    16 Course containers provide `ICourseContainer`:
    17 
    18     >>> from waeup.interfaces import ICourseContainer
    19     >>> ICourseContainer.providedBy(mycontainer)
    20     True
    21141
    22142Another way to get a course container -- without importing the class
    23143-- is via factories. We registered a factory for course containers
    24 under the name ``waeup.CourseContainer``::
    25 
    26     >>> import grok
    27     >>> grok.testing.grok('waeup')
    28 
    29 Now we can ask for an object by calling the appropriate factory:
     144under the name ``waeup.CourseContainer``. Now we can ask for an object
     145by calling the appropriate factory:
    30146
    31147    >>> from zope.component import createObject
     
    36152imports or similar.
    37153
    38 We can be sure, that the full interface is supported by the
    39 CourseContainer class:
    40 
    41     >>> from zope.interface.verify import verifyClass
    42     >>> verifyClass(ICourseContainer, CourseContainer)
    43     True
    44 
Note: See TracChangeset for help on using the changeset viewer.