• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 31. Vocabularies and Related Fie... > Step 2: Testing the Vocabulary

Step 2: Testing the Vocabulary

The tests are as straightforward as the vocabulary code itself. You are going to test only the vocabulary because the implementation of the term is trivial and will be tested through the vocabulary anyway. In the docstring of the ItemVocabulary class, you need to add the following example and test code:

01 Example:
02
03 >>> data = {'a': 'Anton', 'b': 'Berta', 'c': 'Charlie'}
04 >>> vocab = ItemVocabulary(data)
05 >>> iterator = iter(vocab)
06 >>> iterator.next().token
07 'a'
08 >>> len(vocab)
09 3
10 >>> 'c' in vocab
11 True
12 >>> vocab.getQuery() is None
13 True
14 >>> vocab.getTerm('b').value
15 'b'
16 >>> vocab.getTerm('d')
17 Traceback (most recent call last):
18 ...
19 LookupError: d
20 >>> vocab.getTermByToken('b').token
21 'b'
22 >>> vocab.getTermByToken('d')
23 Traceback (most recent call last):
24 ...
25 LookupError: d


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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