2021.10 #41

Merged
edraft merged 53 commits from 2021.10 into master 2021-10-04 09:32:42 +02:00
4 changed files with 36 additions and 1 deletions
Showing only changes of commit 94949394de - Show all commits

View File

@ -10,3 +10,9 @@ class List(Iterable):
if values is not None: if values is not None:
self.extend(values) self.extend(values)
def append(self, __object: object) -> None:
if self._type is not None and type(__object) != self._type and not isinstance(type(__object), self._type):
raise Exception(f'Unexpected type: {type(__object)}')
super().append(__object)

View File

@ -0,0 +1,28 @@
import unittest
from cpl_query.extension.list import List
class IterableTest(unittest.TestCase):
def setUp(self) -> None:
self._list = List(int)
def _clear(self):
self._list.clear()
self.assertEqual(self._list, [])
def test_append(self):
self._list.append(1)
self._list.append(2)
self._list.append(3)
self.assertEqual(self._list, [1, 2, 3])
self._clear()
def test_append_wrong_type(self):
self._list.append(1)
self._list.append(2)
self.assertRaises(Exception, lambda v: self._list.append(v), '3')
self._clear()

View File

@ -143,5 +143,4 @@ class QueryTest(unittest.TestCase):
results.append(user) results.append(user)
res = self._tests.where(lambda u: u.address.nr == 5) res = self._tests.where(lambda u: u.address.nr == 5)
# res = self._tests.where('User.address.nr == 5')
self.assertEqual(len(results), len(res)) self.assertEqual(len(results), len(res))

View File

@ -1,5 +1,6 @@
import unittest import unittest
from cpl_query.tests.iterable_test import IterableTest
from cpl_query.tests.query_test import QueryTest from cpl_query.tests.query_test import QueryTest
@ -11,6 +12,7 @@ class Tester:
def create(self): def create(self):
loader = unittest.TestLoader() loader = unittest.TestLoader()
self._suite.addTests(loader.loadTestsFromTestCase(QueryTest)) self._suite.addTests(loader.loadTestsFromTestCase(QueryTest))
self._suite.addTests(loader.loadTestsFromTestCase(IterableTest))
def start(self): def start(self):
runner = unittest.TextTestRunner() runner = unittest.TextTestRunner()