2 from musixmatch
import *
4 class TestBase(unittest.TestCase):
8 self.assertEqual(self.Class.label(), self.Class.__name__.lower())
12 item = {
"item_id":
"9673" }
13 item_str =
"{ 'item_id': '9673'}" 14 item_repr =
"Item({'item_id': '9673'})" 25 item = self.Class.fromDictionary(self.
item)
27 for k
in self.item.keys():
28 self.assertEqual(item[k], self.
item[k])
31 item = self.Class.fromDictionary(self.
item)
32 self.assertEqual(str(item),self.
item_str)
35 item = self.Class.fromDictionary(self.
item)
36 self.assertEqual(repr(item),self.
item_repr)
39 item = self.Class.fromDictionary(self.
item)
45 AllowedContent = base.ItemsCollection.allowedin()
46 item_list =
'item_list' 55 "item_name":
"item_292" 61 "item_name":
"item_8976" 67 "item_name":
"item_9673" 73 "execute_time": 0.14144802093506001,
79 collection = self.
Class()
82 collection.insert(0, item)
84 self.assertEqual(collection[0], item)
87 collection.insert(0, saved)
93 self.assertEqual(collection[1], item)
96 collection = self.
Class()
98 item = self.AllowedContent.fromDictionary(saved)
99 collection.append(item)
101 self.assertEqual(collection[0], item)
104 collection.append(saved)
106 self.assertEqual(collection[1][self.
item_id], saved[self.
item_id])
109 collection.append(saved)
113 self.assertEqual(collection[2][self.
item_id], saved[self.
item_id])
122 collection.extend(typed)
124 self.assertEqual(collection[1], typed[0])
125 self.assertEqual(collection[2], typed[1])
127 row = items[:2] + items[1:3]
128 collection.extend(row)
130 self.assertEqual(
len(collection), 3)
132 collection = self.
Class()
133 collection.extend(row)
134 self.assertEqual(
len(row), 4)
135 self.assertEqual(
len(collection), 3)
161 collection = self.
Class(*items)
162 self.assertEqual(
len(collection), 3)
165 page = collection.page(1,2)
166 self.assertEqual(
len(page), 1)
167 self.assertEqual(type(page), self.
Class)
172 collection = self.
Class(*items)
173 self.assertEqual(
len(collection), 3)
174 pages = collection.pages(2)
175 self.assertEqual(pages, 2)
179 collection = self.
Class(*items)
180 self.assertEqual(
len(collection), 3)
183 paged = collection.paged(2)
184 self.assertEqual(
len(paged), 2)
185 for i,l
in zip(
range(2), (2,1)):
186 self.assertEqual(
len(paged[i]), l)
187 self.assertEqual(type(paged[i]), self.
Class)
188 for p,i
in [(0,0),(0,1),(1,0)]:
189 self.assertEqual(
id(paged[p][i]),
id(collection[(2*p)+i]))
193 collection = self.
Class(*items)
194 self.assertEqual(
len(collection), 3)
198 for page
in collection.pager(2):
199 self.assertEqual(type(page), self.
Class)
202 self.assertEqual(
len(pager), 2)
203 self.assertEqual(
len(pager[0]), 2)
204 self.assertEqual(
len(pager[1]), 1)
208 collection1 = self.
Class(*items[:2])
209 collection2 = self.
Class(*items[1:3])
210 collection3 = collection1 + collection2
212 self.assertEqual(type(collection3), self.
Class)
213 self.assertEqual(
len(collection3), 3)
static int hash(int head, const int add)
Hash function adding character.
def test_fromDictionary(self)