generated from marcizhu/readme-chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmockGithub.py
60 lines (49 loc) · 1.95 KB
/
mockGithub.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
import re
class Issue:
def __init__(self, title=''):
self.__title = title
self.__closed = False
self.__expected_labels = []
self.__expected_comments = []
self.__unexpected_labels = []
self.__unexpected_comments = []
@property
def title(self):
return self.__title
def create_comment(self, text):
if len(self.__expected_comments) == 0:
self.__unexpected_comments += [text]
elif re.match(self.__expected_comments[0], text) == None:
self.__unexpected_comments += [text]
else:
self.__expected_comments.pop(0)
def edit(self, state='opened', labels=[]):
if state == 'closed':
self.__closed = True
for label in labels:
try:
self.__expected_labels.remove(label)
except ValueError:
self.__unexpected_labels += [label]
def add_to_labels(self, label):
try:
self.__expected_labels.remove(label)
except ValueError:
self.__unexpected_labels += [label]
####################### Testing functions #######################
def expect_labels(self, labels):
self.__expected_labels = labels
def expect_comments(self, regex_list):
self.__expected_comments = regex_list
def expectations_fulfilled(self, ):
if len(self.__expected_labels) != 0:
return False, f'Missing expected labels: {self.__expected_labels}'
if len(self.__expected_comments) != 0:
return False, f'Missing expected comments: {self.__expected_comments}'
if len(self.__unexpected_labels) != 0:
return False, f'Unexpected labels: {self.__unexpected_labels}'
if len(self.__unexpected_comments) != 0:
return False, f'Unexpected comments: {self.__unexpected_comments}'
if self.__closed == False:
return False, 'Issue not closed'
return True, None