-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_parse_cypress_tests.py
More file actions
73 lines (61 loc) · 2.96 KB
/
test_parse_cypress_tests.py
File metadata and controls
73 lines (61 loc) · 2.96 KB
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
import unittest, os, sys, cairo
from CypressTestFile import CypressTestFile
class CypressTestFileTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(CypressTestFileTest, self).__init__(*args, **kwargs)
self.name = os.getenv("name")
self.repository_url = os.getenv("repository_url")
self.cypress_test_folder = os.getenv("cypress_test_folder")
self.htmlpreview = os.getenv("htmlpreview")
self.remote_images_path = os.getenv("remote_images_path")
self.local_images_path = os.getenv("local_images_path")
self.doc_folder_path = os.getenv("doc_folder_path")
self.commands = os.getenv("commands")
self.commands_html = os.getenv("commands_html")
def test_doc_folder_path(self):
self._annotate_screenshots()
# self.promptForUserConfirmation()
for file_path in os.scandir(self.cypress_test_folder):
ctf = CypressTestFile(
self.name,
file_path,
self.remote_images_path,
self.local_images_path,
self.repository_url,
self.htmlpreview,
)
print(ctf.document("python"))
ctf.save_html_document(self.doc_folder_path+ctf.file_name()+".html")
print("See file://"+self.doc_folder_path)
def test_list_commands(self):
CypressTestFile.list_commands(self.commands, self.commands_html)
def promptForUserConfirmation(self, resp=False):
print("Did you run all the Cypress tests in "+self.cypress_test_folder+" ? (y/n)")
answer = input()
if answer != "y":
sys.exit()
def _annotate_screenshots(self):
for file_path in os.scandir(self.local_images_path):
url = self.local_images_path+"/"+file_path.name
comps = os.path.basename(file_path.name).split("__")
if len(comps) > 1:
final_filename = comps[0]+".png"
surroundings_frame_factor = int(comps[1].replace(".png", "")) + 80
screenshot = cairo.ImageSurface.create_from_png(url)
screenshot_height = screenshot.get_height()
screenshot_width = screenshot.get_width()
element_height = screenshot_height - surroundings_frame_factor
element_width = screenshot_width - surroundings_frame_factor
pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0)
pat.add_color_stop_rgba(1, 0.7, 0, 0, 0.3)
ctx = cairo.Context(screenshot)
ctx.rectangle(
surroundings_frame_factor / 2,
surroundings_frame_factor / 2,
element_width,
element_height
)
ctx.set_source(pat)
ctx.fill()
os.remove(url)
screenshot.write_to_png(self.local_images_path+"/"+final_filename)