• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Integrating a Doc Test

How will the example from the previous chapter change in light of doc tests? First of all, you can completely get rid of the TestSample class. Next, you can add the following lines to the doc string of the Sample class:

01 Examples::
02
03   >>> sample = Sample()
04
05   Here you can see how the 'title' attribute works.
06
07   >>> print sample.title
08   None
09   >>> sample.title = 'Title'
10   >>> print sample.title
11   Title
12
13   The description is implemented using a accessor and mutator method
14
15   >>> sample.getDescription()
16   ''
17   >>> sample.setDescription('Hello World')
18   >>> sample.getDescription()
19   'Hello World'
20   >>> sample.setDescription(u'Hello World')
21   >>> sample.getDescription()
22   u'Hello World'
23
24   'setDescription()' only accepts regular and unicode strings
25
26   >>> sample.setDescription(None)
27   Traceback (most recent call last):
28     File "<stdin>", line 1, in ?
29     File "test_sample.py", line 31, in setDescription
30       assert isinstance(value, (str, unicode)) 
31   AssertionError


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint