Skip to content

Commit

Permalink
Extensions item references hash and validator per folder example
Browse files Browse the repository at this point in the history
And updated tests to reflect this change
  • Loading branch information
lbiaggi committed Mar 13, 2024
1 parent 8c70327 commit d067d83
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doorstop/cli/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from doorstop.core.document import Document

REQ_COUNT = 23
ALL_COUNT = 55
ALL_COUNT = 57


class TempTestCase(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions doorstop/core/publishers/tests/test_publisher_html_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def setUp(self):
traceability.csv
traceability.html
documents/
EXT.html
HLT.html
LLT.html
REQ.html
Expand Down
2 changes: 2 additions & 0 deletions doorstop/core/publishers/tests/test_publisher_latex_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ def setUp(self):
self.dirpath = os.path.abspath(os.path.join("mock_%s" % __name__, self.hex))
os.makedirs(self.dirpath)
self.expected_walk = """{n}/
EXT.tex
HLT.tex
LLT.tex
REQ.tex
Requirements.tex
TUT.tex
Tutorial.tex
compile.sh
doc-EXT.tex
doc-HLT.tex
doc-LLT.tex
traceability.tex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def setUp(self):
self.dirpath = os.path.abspath(os.path.join("mock_%s" % __name__, self.hex))
os.makedirs(self.dirpath)
self.expected_walk = """{n}/
EXT.md
HLT.md
LLT.md
REQ.md
Expand Down
9 changes: 9 additions & 0 deletions reqs/ext/.doorstop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
settings:
digits: 3
itemformat: yaml
parent: REQ
prefix: EXT
sep: ""
extensions:
item_validator: .req_sha_item_validator.py
item_sha_required: true
27 changes: 27 additions & 0 deletions reqs/ext/.req_sha_item_validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from doorstop import DoorstopInfo, DoorstopWarning, DoorstopError
from subprocess import check_output
from copy import copy
from random import random


def item_validator(item):
if getattr(item, "references") == None:
return []

for ref in item.references:
if ref['sha'] != item._hash_reference(ref['path']):
yield DoorstopWarning("Hash has changed and it was not reviewed properly")

if 'modified' in ref['path']:
temp_item = copy(item)
current_value = item.is_reviewed()
check_output(
"echo '1111' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)
temp_item.review()
next_value = item.is_reviewed()
check_output(
"echo '0000' > $(git rev-parse --show-toplevel)/reqs/ext/test-modified.file", shell=True)

yield DoorstopWarning(f"""This is a demonstration of a validator per folder identifying a external ref modified
without a proper review current SHA {current_value} modified SHA {next_value }.
Result: { next_value == current_value} """)
14 changes: 14 additions & 0 deletions reqs/ext/EXT001.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
active: true
derived: false
header: ''
level: 1.0
links: []
normative: true
ref: ''
references:
- path: reqs/ext/test.file
sha: 24d9b35c727e6c78676c2ad378a8c3c47cfb539f3583d3cd9e1eafee51d5679d
type: file
reviewed: n0xxAj0z-SqNcebKEu8p9HDE8jAs5I8Vz4kX-5ZieA4=
text: |
Test where we calculate the SHA
14 changes: 14 additions & 0 deletions reqs/ext/EXT002.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
active: true
derived: false
header: ''
level: 2.0
links: []
normative: true
ref: ''
references:
- path: reqs/ext/test-modified.file
sha: 49ca5d81054fdd20572294b9350b605d05e0df91da09a46fb8bde7fd6c1c172d
type: file
reviewed: arLWz1tqET94t2j7FG0ncvKpwGe5twDi-jPbBnikxho=
text: |
Test where we calculate the SHA, file modified during evaluation
1 change: 1 addition & 0 deletions reqs/ext/test-modified.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0000
1 change: 1 addition & 0 deletions reqs/ext/test.file
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001

0 comments on commit d067d83

Please sign in to comment.