Skip to content

Commit

Permalink
Fix examples and tests (#16)
Browse files Browse the repository at this point in the history
* add some basic tests
* fix requirements
  • Loading branch information
ebroecker authored Nov 4, 2019
1 parent 5a9d87b commit ce9dd62
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ deploy:

script:
- python setup.py install
- python ./createReqDoc.py
- ./test.sh
72 changes: 21 additions & 51 deletions createReqDoc.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,40 @@
#!/usr/bin/env python
#!/usr/bin/env python3
from __future__ import absolute_import

import pyreqif.pyreqif
import pyreqif.reqif
import datetime
import uuid
import pyreqif.create

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

def addDatatype(id, mydoc, type="document", lastChange=datetime.datetime.today().isoformat(), longName="xhtml"):
mydoc.addDatatype({"identifier":id, "type":type, "lastChange": lastChange, "longName":longName})
xhtmlDatatypeId = "_2"
reqirementTypeId = "_3"
collumn1typeId = "_4"
collumn2typeId = "_5"

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

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

def addRelation(sourceId, targetId, mydoc):
relation = {}
relation ["sourceRef"] = sourceId
relation["targetRef"] = targetId
pyreqif.create.addDatatype(xhtmlDatatypeId,mydoc)

mydoc.addRelation(pyreqif.rif.reqif2py(relation))

def creatUUID(itemId = None):
if itemId is not None:
return str(uuid.uuid1(int(itemId)))
else:
return str(uuid.uuid1())
pyreqif.create.addReqType(reqirementTypeId, "requirement Type",collumn1typeId, "Col1", xhtmlDatatypeId, mydoc)
pyreqif.create.addReqType(reqirementTypeId,"", collumn2typeId, "Col2", xhtmlDatatypeId, mydoc)

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

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

xhtmlDatatypeId = "2"
reqirementTypeId = "3"
collumn1typeId = "4"
collumn2typeId = "5"

mydoc = createDocument("1")
link_type = document_id + "link_type"
pyreqif.create.addRelation("_6","_7", mydoc, id="_self_link", type=link_type)
pyreqif.create.addSpecRelationType(link_type, mydoc, longName="selflink")

addDatatype(xhtmlDatatypeId,mydoc)


addReqType(reqirementTypeId, "requirement Type",collumn1typeId, "Col1", xhtmlDatatypeId, mydoc)
addReqType(reqirementTypeId,"", collumn2typeId, "Col2", xhtmlDatatypeId, mydoc)

addReq("6", reqirementTypeId, "Hallo", collumn1typeId, mydoc)
addReq("6", reqirementTypeId, "Hallo2", collumn2typeId, mydoc)


addRelation("6","12", mydoc)

myHierarch = createHierarchHead("Reqirement Document Name")
myHierarch.addChild(createHierarchElement("6"))
myHierarch.addChild(createHierarchElement("7"))
myHierarch = pyreqif.create.createHierarchHead("Reqirement Document Name")
myHierarch.addChild(pyreqif.create.createHierarchElement("_6"))
myHierarch.addChild(pyreqif.create.createHierarchElement("_7"))

mydoc.hierarchy.append(myHierarch)

Expand Down
13 changes: 8 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
specs = myDoc.asDict()
for spec in specs:
for req in spec:
print (req["ReqIF.ChapterName"], end="")
print (req["ReqIF.Text"])

for key,value in req.items():
print ("{} : {}".format(key, value), end=" ")
print("")


#
Expand All @@ -57,8 +57,11 @@
# iterator gives every element and its hierachical depth
# do some ascii printing of Text and Chapter
print(" " * depth, end="")
print (item["ReqIF.ChapterName"], end="")
print (item["ReqIF.Text"])
for key, value in req.items():
print("{} : {}".format(key, value), end=" ")
print("")
# print (item["ReqIF.ChapterName"], end="")
# print (item["ReqIF.Text"])

#
# print some info, if attachement is found
Expand Down
2 changes: 1 addition & 1 deletion reqif2html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import pyreqif.rif
import pyreqif.html
import sys
Expand Down
2 changes: 1 addition & 1 deletion reqif2xlsx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import pyreqif.rif
import pyreqif.xlsx
import sys
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
lxml
future
oletools
xlsxwriter
openpyxl
xlsxwriter
image
4 changes: 2 additions & 2 deletions src/pyreqif/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def addRelation(sourceId, targetId, mydoc, id, type, longName=None, lastChange=d

def creatUUID(itemId = None):
if itemId is not None:
return str(uuid.uuid1(int(itemId)))
return "_" + str(uuid.uuid1(int(itemId)))
else:
return str(uuid.uuid1())
return "_" + str(uuid.uuid1())

def createHierarchHead(longName, id=None, lastChange=datetime.datetime.today().isoformat()):
if id is None:
Expand Down
2 changes: 1 addition & 1 deletion src/pyreqif/rif.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def dump(doc, f):
elif value == "typeRef":
typeXml = createSubElement(specXml, "TYPE")
createSubElement(typeXml, "SPEC-OBJECT-TYPE-REF", label)
elif element not in attributesForElements:
elif value not in attributesForElements:
createSubElement(specXml , value , label)


Expand Down
2 changes: 1 addition & 1 deletion src/pyreqif/xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def dump(myDoc, outfile, basepath = None):
# row = 1

for child in myDoc.hierarchy:
for item, depth in myDoc.hierach_iterator(child, cols):
for item, depth in myDoc.hierach_iterator(child, cols):
row += 1
write_excel_line(worksheet, item, row, cols, depth, basepath, cell_format)
# workbook.save(filename=outfile)
Expand Down
14 changes: 14 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

python3 createReqDoc.py &&
python3 reqif2xlsx.py aa.reqif aa.xlsx &&
python3 reqif2html.py aa.reqif aa.html &&
python3 example.py aa.reqif &&
python3 xlsx2reqif.py aa.xlsx &&


# once again with the reqif created from xlsx:
python3 reqif2xlsx.py aa.reqif aa.xlsx &&
python3 reqif2html.py aa.reqif aa.html &&
python3 example.py aa.reqif

7 changes: 6 additions & 1 deletion xlsx2reqif.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import zipfile
import xml.etree.ElementTree
Expand All @@ -11,7 +11,12 @@
def get_images_from_excel(excel_file, output_file):
out_zip = zipfile.ZipFile(document_title + ".reqifz", 'w', zipfile.ZIP_DEFLATED)


in_excel = zipfile.ZipFile(excel_file)

if "xl/drawings/drawing1.xml" not in in_excel.namelist():
return []

ns = "{http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing}"
a_ns = "{http://schemas.openxmlformats.org/drawingml/2006/main}"

Expand Down

0 comments on commit ce9dd62

Please sign in to comment.