| 1 |
""" |
|---|
| 2 |
Prepare enviornment. |
|---|
| 3 |
>>> import _path_cheesecake |
|---|
| 4 |
>>> from cheesecake.cheesecake_index import Index |
|---|
| 5 |
|
|---|
| 6 |
***** |
|---|
| 7 |
|
|---|
| 8 |
Default maximum value for an index should be 0. |
|---|
| 9 |
>>> index = Index() |
|---|
| 10 |
>>> index.max_value |
|---|
| 11 |
0 |
|---|
| 12 |
|
|---|
| 13 |
To learn a class name, ask for its representation. |
|---|
| 14 |
>>> Index |
|---|
| 15 |
<Index class: unnamed> |
|---|
| 16 |
>>> class NamedIndex(Index): |
|---|
| 17 |
... pass |
|---|
| 18 |
>>> NamedIndex |
|---|
| 19 |
<Index class: NamedIndex> |
|---|
| 20 |
|
|---|
| 21 |
***** |
|---|
| 22 |
|
|---|
| 23 |
Create two indices. |
|---|
| 24 |
>>> big_index = Index() |
|---|
| 25 |
>>> index = Index() |
|---|
| 26 |
>>> index.name = 'small_index' |
|---|
| 27 |
|
|---|
| 28 |
Add one index to another. |
|---|
| 29 |
>>> big_index.add_subindex(index) |
|---|
| 30 |
>>> index in big_index.subindices |
|---|
| 31 |
True |
|---|
| 32 |
|
|---|
| 33 |
Try to add non-Index object as a subindex. |
|---|
| 34 |
>>> big_index.add_subindex(42) |
|---|
| 35 |
Traceback (most recent call last): |
|---|
| 36 |
... |
|---|
| 37 |
ValueError: subindex have to be instance of Index |
|---|
| 38 |
|
|---|
| 39 |
Now remove subindex. |
|---|
| 40 |
>>> big_index.remove_subindex('small_index') |
|---|
| 41 |
>>> index in big_index.subindices |
|---|
| 42 |
False |
|---|
| 43 |
|
|---|
| 44 |
***** |
|---|
| 45 |
|
|---|
| 46 |
Test passing subindices to index constructor. |
|---|
| 47 |
>>> def create_index(name): |
|---|
| 48 |
... idx = Index() |
|---|
| 49 |
... idx.name = name |
|---|
| 50 |
... return idx |
|---|
| 51 |
|
|---|
| 52 |
>>> index_one = create_index('one') |
|---|
| 53 |
>>> index_two = create_index('two') |
|---|
| 54 |
>>> index_three = create_index('three') |
|---|
| 55 |
>>> index = Index(index_one, index_two, index_three) |
|---|
| 56 |
|
|---|
| 57 |
>>> def get_names(indices): |
|---|
| 58 |
... return map(lambda idx: idx.name, indices) |
|---|
| 59 |
|
|---|
| 60 |
>>> get_names(index.subindices) |
|---|
| 61 |
['one', 'two', 'three'] |
|---|
| 62 |
>>> index.remove_subindex('one') |
|---|
| 63 |
>>> get_names(index.subindices) |
|---|
| 64 |
['two', 'three'] |
|---|
| 65 |
|
|---|
| 66 |
***** |
|---|
| 67 |
|
|---|
| 68 |
Test requirements. |
|---|
| 69 |
>>> class NewIndex(Index): |
|---|
| 70 |
... def compute(self, one, two, three): |
|---|
| 71 |
... pass |
|---|
| 72 |
>>> new = NewIndex() |
|---|
| 73 |
>>> new.requirements |
|---|
| 74 |
['one', 'two', 'three'] |
|---|
| 75 |
|
|---|
| 76 |
Now create other index and add it to the NewIndex. |
|---|
| 77 |
>>> class OtherIndex(Index): |
|---|
| 78 |
... def compute(self, four): |
|---|
| 79 |
... pass |
|---|
| 80 |
>>> other = OtherIndex() |
|---|
| 81 |
>>> other.requirements |
|---|
| 82 |
['four'] |
|---|
| 83 |
>>> new.add_subindex(other) |
|---|
| 84 |
>>> new.requirements |
|---|
| 85 |
['one', 'two', 'three', 'four'] |
|---|
| 86 |
""" |
|---|