-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstress_tests.py
executable file
·104 lines (81 loc) · 3.16 KB
/
stress_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2008 Konstantin Merenkov <kmerenkov@gmail.com>
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
__author__ = "Konstantin Merenkov <kmerenkov@gmail.com>"
import unittest
from validol import validate, Many, Optional
class DictTestCase(unittest.TestCase):
def test_good_001(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = dict(map(lambda x: (str(x), int), xrange(1000)))
self.assertTrue(validate(s, x))
def test_bad_001(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = dict(map(lambda x: (str(x), int), xrange(1000)))
s['999'] = str
self.assertFalse(validate(s, x))
def test_good_002(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = dict(map(lambda x: (Optional(str(x)), int), xrange(1000)))
self.assertTrue(validate(s, x))
def test_bad_002(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = dict(map(lambda x: (Optional(str(x)), int), xrange(1000)))
s['999'] = str
self.assertFalse(validate(s, x))
def test_good_003(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = {Many(str): int}
self.assertTrue(validate(s, x))
def test_bad_003(self):
x = dict(map(lambda x: (str(x), x), xrange(1000)))
s = {Many(str): int, 'foo': 'bar'}
self.assertFalse(validate(s, x))
def test_good_004(self):
x = dict(map(lambda x: (str(x), x), xrange(1, 1000)))
s = {Many(str): lambda x: x > 0}
self.assertTrue(validate(s, x))
def test_bad_004(self):
x = dict(map(lambda x: (str(x), x), xrange(1, 1000)))
x['1000'] = 0
s = {Many(str): lambda x: x > 0}
self.assertFalse(validate(s, x))
class ListTestCase(unittest.TestCase):
def test_good_001(self):
x = [ str(x) for x in xrange(1000) ]
s = [str]
self.assertTrue(validate(s, x))
def test_good_002(self):
x = [ x for x in xrange(1, 1000) ]
s = [lambda x: x > 0]
self.assertTrue(validate(s, x))
def test_bad_001(self):
x = [ str(x) for x in xrange(1000) ]
s = [int]
self.assertFalse(validate(s, x))
def test_bad_002(self):
x = [ x for x in xrange(1, 1000) ]
x.append(0)
s = [lambda x: x > 0]
self.assertFalse(validate(s, x))
class TupleTestCase(unittest.TestCase):
def test_good_001(self):
x = tuple(map(str, xrange(10000)))
s = tuple(map(str, xrange(10000)))
self.assertTrue(validate(s, x))
def test_bad_001(self):
x = tuple(map(str, xrange(10000)))
s = tuple(map(str, xrange(9999)) + [10000])
self.assertFalse(validate(s, x))
if __name__ == '__main__':
unittest.main()