forked from hyperskill/intro-to-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
132 lines (118 loc) · 5.57 KB
/
test.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import unittest
import tokenizator
from tokenizator import Tokenizator
from collections import Generator
class TestMyCode(unittest.TestCase):
# making a unit of Tokenizator class
def setUp(self):
self.x = Tokenizator()
# the test itself
def test_isgenerator(self):
result= self.x.tokens_generator(' Ф 12 !!! @ # Alina is a student)))')
self.assertIsInstance(result, Generator)
def test_begins_with_no_alpha(self):
result=list(self.x.tokens_generator(' ф 12 !!! @ # Alina is a student)))'))
self.assertIsInstance(result, list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 1)
self.assertEqual(result[1].s,'Alina')
self.assertEqual(result[1].position,14)
def test_begins_with_alpha(self):
result=list(self.x.tokens_generator('ф 12 !!! @ # Alina is a student)))'))
self.assertIsInstance(result, list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[1].s,'Alina')
self.assertEqual(result[1].position,13)
def test_ends_with_alpha(self):
result=list(self.x.tokens_generator('ф 12 !!! @ # Alina is a student)))abc'))
self.assertIsInstance(result, list)
self.assertEqual(len(result), 6)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[5].s,'abc')
self.assertEqual(result[5].position,34)
def test_ends_with_no_alpha(self):
result=list(self.x.tokens_generator('ф 12 !!! @ # Alina is a student)))'))
self.assertIsInstance(result,list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[4].s,'student')
self.assertEqual(result[4].position,24)
def test_MyError_number(self):
with self.assertRaises(ValueError):
list(self.x.tokens_generator(12))
def test_MyError_notList(self):
s=[1, 2, 3, 'this is my string']
with self.assertRaises(ValueError):
list(self.x.tokens_generator(s))
def test_Function_begins_with_no_alpha(self):
result=self.x.tokenize(' ф 12 !!! @ # Alina is a student)))')
self.assertIsInstance(result, list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 1)
self.assertEqual(result[1].s,'Alina')
self.assertEqual(result[1].position,14)
def test_function_begins_with_alpha(self):
result=self.x.tokenize('ф 12 !!! @ # Alina is a student)))')
self.assertIsInstance(result, list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[1].s,'Alina')
self.assertEqual(result[1].position,13)
def test_function_ends_with_alpha(self):
result=self.x.tokenize('ф 12 !!! @ # Alina is a student)))abc')
self.assertIsInstance(result, list)
self.assertEqual(len(result), 6)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[5].s,'abc')
self.assertEqual(result[5].position,34)
def test_function_ends_with_no_alpha(self):
result=self.x.tokenize('ф 12 !!! @ # Alina is a student)))')
self.assertIsInstance(result, list)
self.assertEqual(len(result), 5)
self.assertEqual(result[0].s, 'ф')
self.assertEqual(result[0].position, 0)
self.assertEqual(result[4].s,'student')
self.assertEqual(result[4].position,24)
def test_MyError_function_number(self):
with self.assertRaises(ValueError):
self.x.tokenize(12)
def test_MyError_function_notList(self):
s=[1, 2, 3, 'this is my string']
with self.assertRaises(ValueError):
self.x.tokenize(s)
def test_isgenerator_for_token_gen(self):
result = self.x.token_gen(' Ф 12 !!! @ # Alina is a student)))')
self.assertIsInstance(result, Generator)
def test_my_token_gen(self):
result = list(self.x.token_gen(' Ф 12 !!! @ # Alina is a student)))'))
self.assertIsInstance(result, list)
self.assertEqual(len(result), 6)
self.assertEqual(result[0].s, 'Ф')
self.assertEqual(result[0].tp, 'alpha')
self.assertEqual(result[0].position,1)
self.assertEqual(result[1].s, '12')
self.assertEqual(result[1].tp, 'digit')
self.assertEqual(result[1].position,3)
self.assertEqual(result[5].s,'student')
self.assertEqual(result[5].tp, 'alpha')
self.assertEqual(result[5].position,25)
def test_MyError_token_gen_number(self):
with self.assertRaises(ValueError):
list(self.x.token_gen(12))
def test_MyError_token_gen_notList(self):
s=[1, 2, 3, 'this is my string']
with self.assertRaises(ValueError):
list(self.x.token_gen(s))
def test_empty_string(self):
result = ''
self.assertEqual(len(result), 0)
if __name__ == '__main__':
unittest.main()# общий способ вынести модуль чтобы запустить как прогу без импорта