33import unittest2
44
55from domain_models import collections
6- from domain_models import errors
6+
7+
8+ class TestCollection (collections .Collection ):
9+ """Test collection of ints."""
10+
11+ value_type = int
712
813
914class CollectionTests (unittest2 .TestCase ):
1015 """Collection tests."""
1116
1217 def test_init_empty (self ):
1318 """Test creation of collection."""
14- collection = collections . Collection ( int )
19+ collection = TestCollection ( )
1520
1621 self .assertIsInstance (collection , collections .Collection )
1722 self .assertIsInstance (collection , list )
1823
1924 def test_init_with_correct_values (self ):
2025 """Test creation of collection."""
21- collection = collections . Collection ( int , (1 , 2 , 3 ))
26+ collection = TestCollection ( (1 , 2 , 3 ))
2227
2328 self .assertEqual (collection , [1 , 2 , 3 ])
2429
2530 def test_init_with_incorrect_values (self ):
2631 """Test creation of collection."""
2732 with self .assertRaises (TypeError ):
28- collections .Collection (int , ('1' , '2' , '3' ))
29-
30- def test_init_without_value_type (self ):
31- """Test creation of collection."""
32- with self .assertRaises (errors .Error ):
33- collections .Collection (None )
34-
35- with self .assertRaises (errors .Error ):
36- collections .Collection (1 )
37-
38- with self .assertRaises (errors .Error ):
39- collections .Collection (object ())
33+ TestCollection (('1' , '2' , '3' ))
4034
4135 def test_append_valid_type (self ):
4236 """Test append."""
43- collection = collections . Collection ( int )
37+ collection = TestCollection ( )
4438
4539 collection .append (1 )
4640
4741 self .assertEqual (collection , [1 ])
4842
4943 def test_append_invalid_type (self ):
5044 """Test append."""
51- collection = collections . Collection ( int )
45+ collection = TestCollection ( )
5246
5347 with self .assertRaises (TypeError ):
5448 collection .append ('1' )
5549
5650 def test_extend_valid_type (self ):
5751 """Test extend."""
58- collection = collections . Collection ( int )
52+ collection = TestCollection ( )
5953
6054 collection .extend ([1 ])
6155
6256 self .assertEqual (collection , [1 ])
6357
6458 def test_extend_invalid_type (self ):
6559 """Test extend."""
66- collection = collections . Collection ( int )
60+ collection = TestCollection ( )
6761
6862 with self .assertRaises (TypeError ):
6963 collection .extend (['1' ])
7064
7165 def test_insert_valid_type (self ):
7266 """Test insert."""
73- collection = collections . Collection ( int )
67+ collection = TestCollection ( )
7468
7569 collection .insert (0 , 1 )
7670
7771 self .assertEqual (collection , [1 ])
7872
7973 def test_insert_invalid_type (self ):
8074 """Test insert."""
81- collection = collections . Collection ( int )
75+ collection = TestCollection ( )
8276
8377 with self .assertRaises (TypeError ):
8478 collection .insert (0 , '1' )
8579
8680 def test_set_valid_type (self ):
8781 """Test set."""
88- collection = collections . Collection ( int , [0 ])
82+ collection = TestCollection ( [0 ])
8983
9084 collection [0 ] = 1
9185
9286 self .assertEqual (collection , [1 ])
9387
9488 def test_set_invalid_type (self ):
9589 """Test set."""
96- collection = collections . Collection ( int , [0 ])
90+ collection = TestCollection ( [0 ])
9791
9892 with self .assertRaises (TypeError ):
9993 collection [0 ] = '1'
10094
10195 def test_set_valid_slice (self ):
10296 """Test set slice."""
103- collection = collections . Collection ( int , [1 , 2 , 3 ])
97+ collection = TestCollection ( [1 , 2 , 3 ])
10498
10599 collection [0 :3 ] = [7 , 7 , 7 ]
106100
107101 self .assertEqual (collection , [7 , 7 , 7 ])
108102
109103 def test_set_invalid_slice (self ):
110104 """Test set slice."""
111- collection = collections . Collection ( int , [1 , 2 , 3 ])
105+ collection = TestCollection ( [1 , 2 , 3 ])
112106
113107 with self .assertRaises (TypeError ):
114108 collection [0 :3 ] = [7 , '7' , 7 ]
@@ -117,15 +111,15 @@ def test_set_invalid_slice(self):
117111
118112 def test_set_valid_slice_setitem (self ):
119113 """Test set slice."""
120- collection = collections . Collection ( int , [1 , 2 , 3 ])
114+ collection = TestCollection ( [1 , 2 , 3 ])
121115
122116 collection .__setitem__ (slice (0 , 3 ), [7 , 7 , 7 ])
123117
124118 self .assertEqual (collection , [7 , 7 , 7 ])
125119
126120 def test_set_invalid_slice_setitem (self ):
127121 """Test set slice."""
128- collection = collections . Collection ( int , [1 , 2 , 3 ])
122+ collection = TestCollection ( [1 , 2 , 3 ])
129123
130124 with self .assertRaises (TypeError ):
131125 collection .__setitem__ (slice (0 , 3 ), [7 , '7' , 7 ])
@@ -134,28 +128,26 @@ def test_set_invalid_slice_setitem(self):
134128
135129 def test_get_item (self ):
136130 """Test getting of item."""
137- collection = collections . Collection ( int , [1 , 2 , 3 ])
131+ collection = TestCollection ( [1 , 2 , 3 ])
138132
139133 self .assertEqual (collection [0 ], 1 )
140134 self .assertEqual (collection [1 ], 2 )
141135 self .assertEqual (collection [2 ], 3 )
142136
143137 def test_get_slice (self ):
144138 """Test getting of slice."""
145- collection = collections . Collection ( int , [1 , 2 , 3 ])
139+ collection = TestCollection ( [1 , 2 , 3 ])
146140
147141 collection_slice = collection [0 :2 ]
148142
149143 self .assertEqual (collection_slice , [1 , 2 ])
150- self .assertIsInstance (collection_slice , collections .Collection )
151- self .assertIs (collection .value_type , collection_slice .value_type )
144+ self .assertIsInstance (collection_slice , TestCollection )
152145
153146 def test_getitem_slice (self ):
154147 """Test getting of slice."""
155- collection = collections . Collection ( int , [1 , 2 , 3 ])
148+ collection = TestCollection ( [1 , 2 , 3 ])
156149
157150 collection_slice = collection .__getitem__ (slice (0 , 2 ))
158151
159152 self .assertEqual (collection_slice , [1 , 2 ])
160- self .assertIsInstance (collection_slice , collections .Collection )
161- self .assertIs (collection .value_type , collection_slice .value_type )
153+ self .assertIsInstance (collection_slice , TestCollection )
0 commit comments