This repository was archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaker.py
More file actions
91 lines (70 loc) · 3.02 KB
/
maker.py
File metadata and controls
91 lines (70 loc) · 3.02 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from .hugo_doc import HugoDoc
from slugify import UniqueSlugify
import os
slugger = UniqueSlugify()
class DocsMaker(object):
"""A documentation site maker."""
def __init__(self, section):
self.section = section
self.output_dir = '%s/livingdocs/content/%s' % (
os.getcwd(), self.section)
def fix_filename(self, s):
parts = s.split('/')
for p in parts:
if '.' in p:
return 'feature/%s' % p.split('.')[0]
def start_feature(self, context, feature):
# beginning a feature. we should begine a file for this
tags = [t.encode('ascii') for t in feature.tags]
self.doc = HugoDoc(title=feature.name, tags=tags)
# record the file path for later writing
self.doc.path = self.fix_filename(feature.filename)
# create the directory we will need later
os.makedirs('%s/%s' % (self.output_dir, self.doc.path))
self.doc.writeline(feature.description)
self.doc.writeline(u'<!--more-->')
def end_feature(self, context, feature):
# calculate the number of scenarios
self.doc.meta['num_scenarios'] = len(feature.scenarios)
self.doc.meta['num_scenarios_passing'] = len(
[s for s in feature.scenarios if s.status == 'passed'])
# write an index.md file for all the info we've accumulated about
# this feature
f = open('%s/%s/index.mmark' % (self.output_dir, self.doc.path), 'w')
f.write(self.doc.getcontents())
f.close()
def start_scenario(self, context, scenario):
# scenario header
self.doc.writeline(u'\n### %s' % scenario.name)
self.doc.writeline()
# begin table header for the steps
self.doc.writeline(u'{.table .table-hover}')
self.doc.writeline(u' Step | Status | Time | ')
self.doc.writeline(u'------|--------|------|---')
def end_scenario(self, context, scenario):
pass
def start_step(self, context, step):
pass
def end_step(self, context, step):
slug = slugger(step.name)
shot_name = '%s.png' % slug
thumb_name = '%s_tm.png' % slug
# get the screenshot
try:
from PIL import Image
context.browser.driver.get_screenshot_as_file(
'%s/%s/%s' % (self.output_dir, self.doc.path, shot_name))
except:
shot_name = None
image_code = 'error capturing'
# make a thumbnail of it
if shot_name:
im = Image.open('%s/%s/%s' %
(self.output_dir, self.doc.path, shot_name))
im.thumbnail((100, 100))
im.save('%s/%s/%s' % (self.output_dir, self.doc.path, thumb_name))
image_code = '<a href="%s"><img class="img-thumbnail" src="%s" width="100" /></a>' % (
shot_name, thumb_name)
# write the step information to file
self.doc.writeline(u'%s %s | %s | %0.2f | %s' % (
step.keyword, step.name, step.status, step.duration, image_code))