This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
putting doctests in a different package
- Loading branch information
1 parent
0d4879d
commit 8e3580b
Showing
8 changed files
with
267 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env python | ||
# -*- encoding: utf-8 -*- | ||
|
||
""" | ||
---------------------- | ||
Object-document mapper | ||
---------------------- | ||
>>> def text_validator(node, value): | ||
... if value.startswith('Banana'): | ||
... raise BaseException, "You can't start a text with 'Banana'" | ||
... | ||
>>> def colon_validator(node, value): | ||
... for author in value: | ||
... if ',' not in author: | ||
... raise BaseException, "Authors's name must be in 'LastName, FirstName' format" | ||
>>> class Book(Document): | ||
... title = TextProperty(required=True, validator=text_validator) | ||
... authors = MultiTextProperty(required=False, validator=colon_validator) | ||
... pages = TextProperty() | ||
... | ||
>>> class Book2(Document): | ||
... title = TextProperty(required=True, validator=text_validator) | ||
... authors = comp = CompositeTextProperty(required=False, subkeys='fl') | ||
... | ||
Instantiating a Book object:: | ||
>>> book1 = Book(title='Godel, Escher, Bach', | ||
... authors=(u'Hofstadter, Douglas',), | ||
... pages='777') | ||
... | ||
>>> book2 = Book2(title='Godel, Escher, Bach', | ||
... authors=u'^lHofstadter^fDouglas') | ||
... | ||
Manipulating its attributes:: | ||
>>> book1.title | ||
u'Godel, Escher, Bach' | ||
>>> book1.authors[0] | ||
u'Hofstadter, Douglas' | ||
>>> book1.authors = (u'Hofstadter Douglas',) | ||
Traceback (most recent call last): | ||
... | ||
BaseException: Authors's name must be in 'LastName, FirstName' format | ||
>>> book1.authors[0] | ||
u'Hofstadter, Douglas' | ||
>>> book1.authors += (u'Daiana Rose',) | ||
Traceback (most recent call last): | ||
... | ||
BaseException: Authors's name must be in 'LastName, FirstName' format | ||
>>> book1.authors += (u'Rose, Daiana',) | ||
>>> book1.authors | ||
(u'Hofstadter, Douglas', u'Rose, Daiana') | ||
>>> print book2.authors | ||
^lHofstadter^fDouglas | ||
>>> book2.authors['f'] | ||
u'Douglas' | ||
>>> book2.authors['j'] | ||
Traceback (most recent call last): | ||
... | ||
KeyError: 'j' | ||
""" | ||
from isis.model.mapper import Document | ||
from isis.model.mapper import TextProperty, MultiTextProperty, CompositeTextProperty | ||
|
||
def test(): | ||
import doctest | ||
doctest.testmod() | ||
|
||
if __name__=='__main__': | ||
test() |
Oops, something went wrong.