|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
|
|
3
|
|
|
"""Integration tests for the documentation tutorials.""" |
|
4
|
|
|
|
|
5
|
|
|
import unittest |
|
6
|
|
|
|
|
7
|
|
|
import os |
|
8
|
|
|
import shutil |
|
9
|
|
|
import tempfile |
|
10
|
|
|
import subprocess |
|
11
|
|
|
import logging |
|
12
|
|
|
|
|
13
|
|
|
from doorstop.cli.test import ROOT, FILES |
|
14
|
|
|
|
|
15
|
|
|
ENV = 'TEST_TUTORIAL' # environment variable to enable the tutorial example |
|
16
|
|
|
REASON = "'{0}' variable not set".format(ENV) |
|
17
|
|
|
|
|
18
|
|
|
if os.name == 'nt': |
|
19
|
|
|
PATH = os.path.join(ROOT, 'env', 'Scripts', 'doorstop.exe') |
|
20
|
|
|
DOORSTOP = os.path.normpath(PATH) |
|
21
|
|
|
else: |
|
22
|
|
|
PATH = os.path.join(ROOT, 'env', 'bin', 'doorstop') |
|
23
|
|
|
DOORSTOP = os.path.normpath(PATH) |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
if __name__ == '__main__': |
|
27
|
|
|
os.environ[ENV] = '1' # run the integration tests when called directly |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
@unittest.skipUnless(os.getenv(ENV), REASON) |
|
31
|
|
|
class TestBase(unittest.TestCase): |
|
32
|
|
|
|
|
33
|
|
|
"""Base class for tutorial tests.""" |
|
34
|
|
|
|
|
35
|
|
|
def setUp(self): |
|
36
|
|
|
self.cwd = os.getcwd() |
|
37
|
|
|
self.temp = tempfile.mkdtemp() |
|
38
|
|
|
print("$ cd {}".format(self.temp)) |
|
39
|
|
|
os.chdir(self.temp) |
|
40
|
|
|
os.mkdir('.mockvcs') # simulate a working copy |
|
41
|
|
|
os.environ['EDITOR'] = 'cat' |
|
42
|
|
|
|
|
43
|
|
|
def tearDown(self): |
|
44
|
|
|
os.chdir(self.cwd) |
|
45
|
|
|
shutil.rmtree(self.temp) |
|
46
|
|
|
|
|
47
|
|
|
@staticmethod |
|
48
|
|
|
def doorstop(args=""): |
|
49
|
|
|
"""Call 'doorstop' with a string of arguments.""" |
|
50
|
|
|
print("$ doorstop {}".format(args)) |
|
51
|
|
|
cmd = "{} {} -v".format(DOORSTOP, args) |
|
52
|
|
|
if subprocess.call(cmd, shell=True, stderr=subprocess.PIPE) != 0: |
|
53
|
|
|
raise AssertionError("command failed: doorstop {}".format(args)) |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
@unittest.skipUnless(os.getenv(ENV), REASON) |
|
57
|
|
|
class TestSection1(TestBase): |
|
58
|
|
|
|
|
59
|
|
|
"""Integration tests for section 1.0 of the tutorial.""" |
|
60
|
|
|
|
|
61
|
|
|
def test_tutorial_section_1(self): |
|
62
|
|
|
"""Verify tutorial section 1.0 is working.""" |
|
63
|
|
|
|
|
64
|
|
|
# 1.1 |
|
65
|
|
|
|
|
66
|
|
|
self.doorstop("create REQ ./reqs") |
|
67
|
|
|
|
|
68
|
|
|
self.doorstop("add REQ") |
|
69
|
|
|
self.doorstop("add REQ") |
|
70
|
|
|
self.doorstop("add REQ") |
|
71
|
|
|
|
|
72
|
|
|
self.doorstop("edit REQ1 --tool cat") |
|
73
|
|
|
self.doorstop("edit REQ2 --tool cat") |
|
74
|
|
|
|
|
75
|
|
|
# 1.2 |
|
76
|
|
|
|
|
77
|
|
|
self.doorstop("create TST ./reqs/tests --parent REQ") |
|
78
|
|
|
|
|
79
|
|
|
self.doorstop("add TST") |
|
80
|
|
|
self.doorstop("add TST") |
|
81
|
|
|
|
|
82
|
|
|
self.doorstop("edit TST1 --tool cat") |
|
83
|
|
|
self.doorstop("edit TST2 --tool cat") |
|
84
|
|
|
|
|
85
|
|
|
self.doorstop("link TST1 REQ1") |
|
86
|
|
|
self.doorstop("link TST1 REQ3") |
|
87
|
|
|
self.doorstop("link TST2 REQ1") |
|
88
|
|
|
self.doorstop("link TST2 REQ2") |
|
89
|
|
|
|
|
90
|
|
|
# 1.3 |
|
91
|
|
|
|
|
92
|
|
|
self.doorstop("unlink TST1 REQ3") |
|
93
|
|
|
|
|
94
|
|
|
self.doorstop("remove REQ3") |
|
95
|
|
|
|
|
96
|
|
|
# 1.4 |
|
97
|
|
|
|
|
98
|
|
|
self.doorstop() |
|
99
|
|
|
|
|
100
|
|
|
def test_tutorial_section_2(self): |
|
101
|
|
|
"""Verify tutorial section 2.0 is working.""" |
|
102
|
|
|
|
|
103
|
|
|
# Create a basic document |
|
104
|
|
|
self.doorstop("create REQ ./reqs") |
|
105
|
|
|
self.doorstop("add REQ") |
|
106
|
|
|
self.doorstop("add REQ") |
|
107
|
|
|
self.doorstop("create TST ./reqs/tests --parent REQ") |
|
108
|
|
|
self.doorstop("add TST") |
|
109
|
|
|
self.doorstop("add TST") |
|
110
|
|
|
self.doorstop("link TST1 REQ1") |
|
111
|
|
|
self.doorstop("link TST2 REQ1") |
|
112
|
|
|
self.doorstop("link TST2 REQ2") |
|
113
|
|
|
|
|
114
|
|
|
# 2.1 |
|
115
|
|
|
|
|
116
|
|
|
self.doorstop("publish REQ") |
|
117
|
|
|
self.doorstop("publish TST") |
|
118
|
|
|
|
|
119
|
|
|
# 2.2 |
|
120
|
|
|
|
|
121
|
|
|
self.doorstop("publish all path/to/htmldir") |
|
122
|
|
|
|
|
123
|
|
|
def test_tutorial_section_3(self): |
|
124
|
|
|
"""Verify tutorial section 3.0 is working.""" |
|
125
|
|
|
|
|
126
|
|
|
# 3.2 |
|
127
|
|
|
|
|
128
|
|
|
self.doorstop("import --document HLR reqs/hlr") |
|
129
|
|
|
self.doorstop("import --document LLR reqs/llr --parent HLR") |
|
130
|
|
|
|
|
131
|
|
|
# 3.3 |
|
132
|
|
|
|
|
133
|
|
|
self.doorstop("import --item HLR HLR001") |
|
134
|
|
|
self.doorstop("import --item LLR LLR001 " |
|
135
|
|
|
"--attr \"{'text': 'The item text.'}\"") |
|
136
|
|
|
|
|
137
|
|
|
# 3.1 |
|
138
|
|
|
|
|
139
|
|
|
dirpath = os.path.join(self.temp, 'path', 'to') |
|
140
|
|
|
os.makedirs(dirpath) |
|
141
|
|
|
path = os.path.join(FILES, 'exported.xlsx') |
|
142
|
|
|
shutil.copy(path, dirpath) |
|
143
|
|
|
self.doorstop("import path/to/exported.xlsx HLR") |
|
144
|
|
|
|
|
145
|
|
|
def test_tutorial_section_4(self): |
|
146
|
|
|
"""Verify tutorial section 4.0 is working.""" |
|
147
|
|
|
|
|
148
|
|
|
# Create a basic document |
|
149
|
|
|
self.doorstop("create REQ ./reqs") |
|
150
|
|
|
self.doorstop("add REQ") |
|
151
|
|
|
self.doorstop("add REQ") |
|
152
|
|
|
self.doorstop("create TST ./reqs/tests --parent REQ") |
|
153
|
|
|
self.doorstop("add TST") |
|
154
|
|
|
self.doorstop("add TST") |
|
155
|
|
|
self.doorstop("link TST1 REQ1") |
|
156
|
|
|
self.doorstop("link TST2 REQ1") |
|
157
|
|
|
self.doorstop("link TST2 REQ2") |
|
158
|
|
|
|
|
159
|
|
|
# 4.1 |
|
160
|
|
|
|
|
161
|
|
|
self.doorstop("export TST") |
|
162
|
|
|
self.doorstop("export all dirpath/to/exports") |
|
163
|
|
|
self.doorstop("export REQ path/to/req.xlsx") |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
if __name__ == '__main__': |
|
167
|
|
|
logging.basicConfig(format="%(message)s", level=logging.INFO) |
|
168
|
|
|
unittest.main() |
|
169
|
|
|
|