Skip to content

Commit ce9dd62

Browse files
authored
Fix examples and tests (#16)
* add some basic tests * fix requirements
1 parent 5a9d87b commit ce9dd62

11 files changed

Lines changed: 59 additions & 65 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ deploy:
1313

1414
script:
1515
- python setup.py install
16-
- python ./createReqDoc.py
16+
- ./test.sh

createReqDoc.py

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,40 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
from __future__ import absolute_import
33

44
import pyreqif.pyreqif
55
import pyreqif.reqif
6-
import datetime
7-
import uuid
6+
import pyreqif.create
87

9-
def createDocument(id, title="title", comment="created by pyreqif"):
10-
mydoc = pyreqif.pyreqif.doc()
11-
mydoc.addHeader({"identifier":id,"sourceToolId":"pyreqif", "comment": comment, "title":title, "creationTime": str(datetime.date.today())})
12-
return mydoc
138

14-
def addDatatype(id, mydoc, type="document", lastChange=datetime.datetime.today().isoformat(), longName="xhtml"):
15-
mydoc.addDatatype({"identifier":id, "type":type, "lastChange": lastChange, "longName":longName})
9+
xhtmlDatatypeId = "_2"
10+
reqirementTypeId = "_3"
11+
collumn1typeId = "_4"
12+
collumn2typeId = "_5"
1613

17-
def addReqType(specObjId, specObjLongName, specAttribId, collumName, typeRef, mydoc, type="complex", lastChange=datetime.datetime.today().isoformat()):
18-
mydoc.addRequirementType({"identifier":specObjId, "longName": specObjLongName, "lastChange": lastChange, specAttribId : {"identifier":specAttribId, "typeRef":typeRef,"type":type, "lastChange": lastChange, "longName": collumName}})
14+
document_id = "_1"
1915

20-
def addReq(id, specType, content, reqTypeRef, mydoc, lastChange=datetime.datetime.today().isoformat()):
21-
mydoc.addRequirement({"typeRef" : specType, "identifier" : id, "lastChange": lastChange, "values" : {id : {"content" :content, "attributeRef":reqTypeRef, "type": "embeddedDoc"}}})
16+
mydoc = pyreqif.create.createDocument(document_id)
2217

23-
def addRelation(sourceId, targetId, mydoc):
24-
relation = {}
25-
relation ["sourceRef"] = sourceId
26-
relation["targetRef"] = targetId
18+
pyreqif.create.addDatatype(xhtmlDatatypeId,mydoc)
2719

28-
mydoc.addRelation(pyreqif.rif.reqif2py(relation))
2920

30-
def creatUUID(itemId = None):
31-
if itemId is not None:
32-
return str(uuid.uuid1(int(itemId)))
33-
else:
34-
return str(uuid.uuid1())
21+
pyreqif.create.addReqType(reqirementTypeId, "requirement Type",collumn1typeId, "Col1", xhtmlDatatypeId, mydoc)
22+
pyreqif.create.addReqType(reqirementTypeId,"", collumn2typeId, "Col2", xhtmlDatatypeId, mydoc)
3523

36-
def createHierarchHead(longName, id=None, lastChange=datetime.datetime.today().isoformat()):
37-
if id is None:
38-
id = creatUUID()
39-
return pyreqif.pyreqif.hierarchy(**pyreqif.rif.reqif2py({"identifier": id, "longName": longName, "lastChange": lastChange}))
24+
pyreqif.create.addReq("_6", reqirementTypeId, "<div>Hallo</div>", collumn1typeId, mydoc)
25+
pyreqif.create.addReq("_6", reqirementTypeId, "<div>Hallo2</div>", collumn2typeId, mydoc)
4026

41-
def createHierarchElement(reqid, id=None, lastChange=datetime.datetime.today().isoformat()):
42-
if id is None:
43-
id = creatUUID()
44-
return pyreqif.pyreqif.hierarchy(**pyreqif.rif.reqif2py({"identifier": id, "lastChange": lastChange, "objectRef": reqid}))
27+
pyreqif.create.addReq("_7", reqirementTypeId, "<div>Hallo 3</div>", collumn1typeId, mydoc)
28+
pyreqif.create.addReq("_7", reqirementTypeId, "<div>Hallo 4</div>", collumn2typeId, mydoc)
4529

46-
xhtmlDatatypeId = "2"
47-
reqirementTypeId = "3"
48-
collumn1typeId = "4"
49-
collumn2typeId = "5"
5030

51-
mydoc = createDocument("1")
31+
link_type = document_id + "link_type"
32+
pyreqif.create.addRelation("_6","_7", mydoc, id="_self_link", type=link_type)
33+
pyreqif.create.addSpecRelationType(link_type, mydoc, longName="selflink")
5234

53-
addDatatype(xhtmlDatatypeId,mydoc)
54-
55-
56-
addReqType(reqirementTypeId, "requirement Type",collumn1typeId, "Col1", xhtmlDatatypeId, mydoc)
57-
addReqType(reqirementTypeId,"", collumn2typeId, "Col2", xhtmlDatatypeId, mydoc)
58-
59-
addReq("6", reqirementTypeId, "Hallo", collumn1typeId, mydoc)
60-
addReq("6", reqirementTypeId, "Hallo2", collumn2typeId, mydoc)
61-
62-
63-
addRelation("6","12", mydoc)
64-
65-
myHierarch = createHierarchHead("Reqirement Document Name")
66-
myHierarch.addChild(createHierarchElement("6"))
67-
myHierarch.addChild(createHierarchElement("7"))
35+
myHierarch = pyreqif.create.createHierarchHead("Reqirement Document Name")
36+
myHierarch.addChild(pyreqif.create.createHierarchElement("_6"))
37+
myHierarch.addChild(pyreqif.create.createHierarchElement("_7"))
6838

6939
mydoc.hierarchy.append(myHierarch)
7040

example.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
specs = myDoc.asDict()
4141
for spec in specs:
4242
for req in spec:
43-
print (req["ReqIF.ChapterName"], end="")
44-
print (req["ReqIF.Text"])
45-
43+
for key,value in req.items():
44+
print ("{} : {}".format(key, value), end=" ")
45+
print("")
4646

4747

4848
#
@@ -57,8 +57,11 @@
5757
# iterator gives every element and its hierachical depth
5858
# do some ascii printing of Text and Chapter
5959
print(" " * depth, end="")
60-
print (item["ReqIF.ChapterName"], end="")
61-
print (item["ReqIF.Text"])
60+
for key, value in req.items():
61+
print("{} : {}".format(key, value), end=" ")
62+
print("")
63+
# print (item["ReqIF.ChapterName"], end="")
64+
# print (item["ReqIF.Text"])
6265

6366
#
6467
# print some info, if attachement is found

reqif2html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
import pyreqif.rif
33
import pyreqif.html
44
import sys

reqif2xlsx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python2
1+
#!/usr/bin/env python3
22
import pyreqif.rif
33
import pyreqif.xlsx
44
import sys

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
lxml
22
future
33
oletools
4-
xlsxwriter
4+
openpyxl
5+
xlsxwriter
6+
image

src/pyreqif/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def addRelation(sourceId, targetId, mydoc, id, type, longName=None, lastChange=d
4242

4343
def creatUUID(itemId = None):
4444
if itemId is not None:
45-
return str(uuid.uuid1(int(itemId)))
45+
return "_" + str(uuid.uuid1(int(itemId)))
4646
else:
47-
return str(uuid.uuid1())
47+
return "_" + str(uuid.uuid1())
4848

4949
def createHierarchHead(longName, id=None, lastChange=datetime.datetime.today().isoformat()):
5050
if id is None:

src/pyreqif/rif.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def dump(doc, f):
589589
elif value == "typeRef":
590590
typeXml = createSubElement(specXml, "TYPE")
591591
createSubElement(typeXml, "SPEC-OBJECT-TYPE-REF", label)
592-
elif element not in attributesForElements:
592+
elif value not in attributesForElements:
593593
createSubElement(specXml , value , label)
594594

595595

src/pyreqif/xlsx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def dump(myDoc, outfile, basepath = None):
9393
# row = 1
9494

9595
for child in myDoc.hierarchy:
96-
for item, depth in myDoc.hierach_iterator(child, cols):
96+
for item, depth in myDoc.hierach_iterator(child, cols):
9797
row += 1
9898
write_excel_line(worksheet, item, row, cols, depth, basepath, cell_format)
9999
# workbook.save(filename=outfile)

test.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
python3 createReqDoc.py &&
4+
python3 reqif2xlsx.py aa.reqif aa.xlsx &&
5+
python3 reqif2html.py aa.reqif aa.html &&
6+
python3 example.py aa.reqif &&
7+
python3 xlsx2reqif.py aa.xlsx &&
8+
9+
10+
# once again with the reqif created from xlsx:
11+
python3 reqif2xlsx.py aa.reqif aa.xlsx &&
12+
python3 reqif2html.py aa.reqif aa.html &&
13+
python3 example.py aa.reqif
14+

0 commit comments

Comments
 (0)