-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
47 lines (41 loc) · 1.88 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from django.test import TestCase
from .utils import smart_list
class SmartListTests(TestCase):
def test_smart_list_empty(self):
"Test the smart_list function with empty input."
self.assertEqual(smart_list(""), [])
self.assertEqual(smart_list(" "), [])
self.assertEqual(smart_list(" "), [])
self.assertEqual(smart_list("[]"), [])
self.assertEqual(smart_list(u"[]"), [])
self.assertEqual(smart_list(u"[ ]"), [])
self.assertEqual(smart_list("[ ]"), [])
self.assertEqual(smart_list("[21]"), ["21"])
self.assertEqual(smart_list(None), [])
def test_smart_list_single_values(self):
"Test the smart_list function with valid single value input."
self.assertEqual(smart_list("1"), ["1"])
self.assertEqual(smart_list(u"ß "), [u"ß"])
self.assertEqual(smart_list(1), [1])
self.assertEqual(smart_list((1,)), [1])
self.assertEqual(smart_list([1]), [1])
def test_smart_list_errors(self):
"Test the smart_list function raises expected ValueErrors."
self.assertRaises(ValueError, smart_list, {"1": None})
self.assertRaises(ValueError, smart_list, object())
def test_smart_list_delimiter(self):
"Test the smart_list delimiter works."
self.assertEqual(smart_list("1,2"), ["1", "2"])
self.assertEqual(smart_list("1 2"), ["1 2"])
self.assertEqual(smart_list("1 2", " "), ["1", "2"])
def test_smart_list_func(self):
"Test the smart_list func parameter works."
self.assertEqual(smart_list("1,2", func=lambda x: int(x)), [1, 2])
self.assertEqual(smart_list("1,2", func=lambda x: int(x) * 2), [2, 4])
self.assertEqual(smart_list("[21]", func=lambda x: int(x)), [21])
self.assertRaises(
ValueError,
smart_list,
"1,A",
func=lambda x: int(x) * 2
)