Skip to content
This repository was archived by the owner on Jan 22, 2020. It is now read-only.

Commit d4d177e

Browse files
committed
test: added DocsMaker unittests
1 parent dacaa02 commit d4d177e

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

tests/test_maker.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
from mock import Mock
2+
from docsmaker import DocsMaker
3+
import unittest
4+
import shutil
5+
import os
6+
7+
class TestDocsMaker(unittest.TestCase):
8+
9+
@classmethod
10+
def setUpClass(cls):
11+
path = 'tmp'
12+
os.makedirs(path)
13+
os.chdir(path)
14+
15+
@classmethod
16+
def tearDownClass(cls):
17+
os.chdir(os.pardir)
18+
shutil.rmtree('tmp', ignore_errors=True)
19+
20+
@classmethod
21+
def setUp(cls):
22+
cls.section = 'feature'
23+
cls.maker = DocsMaker(cls.section)
24+
25+
@classmethod
26+
def tearDown(cls):
27+
shutil.rmtree('livingdocs/content/feature', ignore_errors=True)
28+
29+
def test_init(self):
30+
self.assertEqual(self.maker.section, self.section)
31+
self.assertIn(self.section, self.maker.output_dir)
32+
33+
def test_fix_filename(self):
34+
filename = 'foo/bar.md'
35+
result = self.maker.fix_filename(filename)
36+
self.assertEquals(result, 'feature/bar')
37+
38+
def test_start_feature(self):
39+
feature = Mock()
40+
feature.filename = 'foo/bar.md'
41+
feature.description = u'This is an example.'
42+
feature.tags = []
43+
context = Mock()
44+
self.maker.start_feature(context,feature)
45+
self.assertIn('This is an example.',self.maker.doc.getcontents())
46+
dir_name = self.maker.output_dir + '/' + self.maker.doc.path
47+
assert os.path.isdir(dir_name)
48+
49+
def test_end_feature(self):
50+
feature = Mock()
51+
feature.filename = 'foo/bar.md'
52+
feature.description = u'This is an example.'
53+
feature.tags = []
54+
feature.scenarios = []
55+
scenario = Mock()
56+
scenario.name = 'Scenario 1'
57+
scenario.status = 'passed'
58+
feature.scenarios.append(scenario)
59+
context = Mock()
60+
self.maker.start_feature(context,feature)
61+
self.maker.end_feature(context, feature)
62+
num_scenarios = 'num_scenarios = "1"'
63+
num_scenarios_passing = 'num_scenarios_passing = "1"'
64+
self.assertIn(num_scenarios, self.maker.doc.header())
65+
self.assertIn(num_scenarios_passing, self.maker.doc.header())
66+
67+
def test_start_scenario(self):
68+
feature = Mock()
69+
feature.filename = 'foo/bar.md'
70+
feature.description = u'This is an example.'
71+
feature.tags = []
72+
feature.scenarios = []
73+
scenario = Mock()
74+
scenario.name = 'Scenario 1'
75+
scenario.status = 'passed'
76+
feature.scenarios.append(scenario)
77+
context = Mock()
78+
self.maker.start_feature(context,feature)
79+
self.maker.start_scenario(context,scenario)
80+
scenario_line = '### %s' % scenario.name
81+
self.assertIn(scenario_line, self.maker.doc.getcontents())
82+
83+
def test_end_step(self):
84+
feature = Mock()
85+
feature.filename = 'foo/bar.md'
86+
feature.description = u'This is an example.'
87+
feature.tags = []
88+
feature.scenarios = []
89+
scenario = Mock()
90+
scenario.name = 'Scenario 1'
91+
scenario.status = 'passed'
92+
feature.scenarios.append(scenario)
93+
context = Mock()
94+
95+
def side_effect(arg):
96+
raise Exception('No browser')
97+
98+
context.browser.driver.get_screenshot_as_file = side_effect
99+
100+
self.maker.start_feature(context,feature)
101+
self.maker.start_scenario(context,scenario)
102+
step = Mock()
103+
step.keyword = u'foo'
104+
step.name = u'bar'
105+
step.status = u'passed'
106+
step.duration = 1.01
107+
self.maker.end_step(context, step)
108+
step_line = 'foo bar | passed | 1.01 | error capturing'
109+
self.assertIn(step_line, self.maker.doc.getcontents())
110+

0 commit comments

Comments
 (0)