Skip to content

Commit 774410f

Browse files
authored
Merge pull request #200 from strictdoc-project/stanislaw/reqif_schema_validation
fix(validate): enable calling the validate command with relative input paths
2 parents 6dece0f + 6599ee4 commit 774410f

5 files changed

Lines changed: 122 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ development = [
5757

5858
# Linters & static analysis
5959
"flake8 >= 3.9.2",
60-
"mypy >= 0.910",
60+
"mypy == 1.16",
6161
"pylint >= 2.11.1",
6262
"ruff >= 0.0.243",
6363

reqif/commands/validate/validate.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,17 @@ def _validate(
8181
) -> ReqIFErrorBundle:
8282
semantic_warnings: List[ReqIFSemanticError] = []
8383

84+
input_file = passthrough_config.input_file
85+
86+
# It is important to convert the input path to an absolute path because
87+
# of the following workaround with os.chdir when calling the
88+
# xmlschema library. See below.
89+
if not os.path.isabs(input_file):
90+
input_file = os.path.abspath(input_file)
91+
8492
if passthrough_config.use_reqif_schema:
8593
old_cwd = os.getcwd()
94+
8695
try:
8796
os.chdir(PATH_TO_REQIF_ROOT)
8897
schema = xmlschema.XMLSchema(
@@ -94,7 +103,7 @@ def _validate(
94103
# we do os.chdir.
95104
base_url=os.path.join(PATH_TO_REQIF_ROOT),
96105
)
97-
schema.validate(passthrough_config.input_file)
106+
schema.validate(input_file)
98107
except XMLSchemaValidationError as xml_schema_validation_error_:
99108
xml_schema_validation_error = ReqIFXMLSchemaValidationError(
100109
xml_schema_validation_error_
@@ -108,7 +117,7 @@ def _validate(
108117
os.chdir(old_cwd)
109118

110119
try:
111-
reqif_bundle = ReqIFParser.parse(passthrough_config.input_file)
120+
reqif_bundle = ReqIFParser.parse(input_file)
112121
except ReqIFXMLParsingError as exception:
113122
return ReqIFErrorBundle(
114123
xml_errors=[exception],

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def release(context, username=None, password=None):
173173
# tokens set up on a local machine.
174174
assert username is None or password is not None
175175

176-
repository_argument_or_none = "" if username else ("--repository reqif_release")
176+
repository_argument_or_none = "" if username else "--repository reqif_release"
177177
user_password = f"-u{username} -p{password}" if username is not None else ""
178178
command = f"""
179179
rm -rfv dist/ &&
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<REQ-IF xmlns="http://www.omg.org/spec/ReqIF/20110401/reqif.xsd" xmlns:configuration="http://eclipse.org/rmf/pror/toolextensions/1.0" xmlns:xhtml="http://www.w3.org/1999/xhtml">
3+
<THE-HEADER>
4+
<REQ-IF-HEADER IDENTIFIER="EF5AEFF3-C695-488A-9955-EDAAEACFE359">
5+
<COMMENT>Author: Mathilda Musterfrau</COMMENT>
6+
<CREATION-TIME>2018-05-08T11:24:18+02:00</CREATION-TIME>
7+
<REPOSITORY-ID>A4123EB9-CC82-4B62-95E1-31CB3203E39C</REPOSITORY-ID>
8+
<REQ-IF-TOOL-ID>microTOOL in-STEP BLUE</REQ-IF-TOOL-ID>
9+
<REQ-IF-VERSION>1.2</REQ-IF-VERSION>
10+
<SOURCE-TOOL-ID>microTOOL objectiF RPM</SOURCE-TOOL-ID>
11+
<TITLE>Beispiel einer ReqIF-Datei</TITLE>
12+
</REQ-IF-HEADER>
13+
</THE-HEADER>
14+
<CORE-CONTENT>
15+
<REQ-IF-CONTENT>
16+
<DATATYPES>
17+
<DATATYPE-DEFINITION-STRING MAX-LENGTH="1000" IDENTIFIER="Text" LAST-CHANGE="2018-04-13T01:00:00+02:00"/>
18+
</DATATYPES>
19+
<SPEC-TYPES>
20+
<SPEC-OBJECT-TYPE DESC="Eine funktionale Anforderung beschreibt eine Systemfunktion, d.h. sie beschreibt, was das System tun muss bzw. welche Funktionalit&#228;t das System den Anwendern bereitstellt." IDENTIFIER="FUNC-REQ" LAST-CHANGE="2018-04-13T11:24:18+02:00" LONG-NAME="Funktionale Anforderung">
21+
<SPEC-ATTRIBUTES>
22+
<ATTRIBUTE-DEFINITION-STRING DESC="Der Beschreibungstext der Anforderung." IDENTIFIER="FUNC-REQ-TXT" LAST-CHANGE="2018-04-13T11:24:18+02:00">
23+
<TYPE>
24+
<DATATYPE-DEFINITION-STRING-REF>Text</DATATYPE-DEFINITION-STRING-REF>
25+
</TYPE>
26+
<IS-EDITABLE>False</IS-EDITABLE>
27+
</ATTRIBUTE-DEFINITION-STRING>
28+
</SPEC-ATTRIBUTES>
29+
</SPEC-OBJECT-TYPE>
30+
<SPEC-RELATION-TYPE DESC="Die Ableitungsbeziehung wird genutzt, um zu spezifizieren, dass eine Anforderung von einer anderen abgeleitet ist." IDENTIFIER="Ableitungsbeziehung" LAST-CHANGE="2018-04-13T11:24:18+02:00" LONG-NAME="Ableitungsbeziehung Anforderung"/>
31+
<SPECIFICATION-TYPE DESC="Ein Kundenanforderungsdokument (oder auch: User Requirements Specification (URS) beschreibt die Anforderungen,die Anwender an das zu entwickelnde System stellen. Kundenanforderungen sind die obersten Anforderungen. Sie dokumentieren die Bef&#252;rfnisse der Anwender, Kunden und anderer Anforderungsquellen wie z.B. rechtliche Vorgaben oder Anforderungen, die intern vom Unternehmen kommen." IDENTIFIER="URS" LAST-CHANGE="2018-04-13T01:00:00+02:00" LONG-NAME="User Requirements Specification"/>
32+
</SPEC-TYPES>
33+
<SPEC-OBJECTS>
34+
<SPEC-OBJECT IDENTIFIER="&#252;berwachungBodentemperatur" LAST-CHANGE="2018-04-13T11:24:18+02:00" LONG-NAME="&#220;berwachung der Bodentemperatur">
35+
<TYPE>
36+
<SPEC-OBJECT-TYPE-REF>FUNC-REQ</SPEC-OBJECT-TYPE-REF>
37+
</TYPE>
38+
<VALUES>
39+
<ATTRIBUTE-VALUE-STRING THE-VALUE="Das System soll die Bodentemperatur &#252;berwachen.">
40+
<DEFINITION>
41+
<ATTRIBUTE-DEFINITION-STRING-REF>FUNC-REQ-TXT</ATTRIBUTE-DEFINITION-STRING-REF>
42+
</DEFINITION>
43+
</ATTRIBUTE-VALUE-STRING>
44+
</VALUES>
45+
</SPEC-OBJECT>
46+
<SPEC-OBJECT IDENTIFIER="erkennungFeuer" LAST-CHANGE="2018-04-13T11:24:18+02:00" LONG-NAME="Erkennung von Feuer">
47+
<TYPE>
48+
<SPEC-OBJECT-TYPE-REF>FUNC-REQ</SPEC-OBJECT-TYPE-REF>
49+
</TYPE>
50+
<VALUES>
51+
<ATTRIBUTE-VALUE-STRING THE-VALUE="Das System soll den Ausbruch von Feuer melden.">
52+
<DEFINITION>
53+
<ATTRIBUTE-DEFINITION-STRING-REF>FUNC-REQ-TXT</ATTRIBUTE-DEFINITION-STRING-REF>
54+
</DEFINITION>
55+
</ATTRIBUTE-VALUE-STRING>
56+
</VALUES>
57+
</SPEC-OBJECT>
58+
</SPEC-OBJECTS>
59+
<SPECIFICATIONS>
60+
<SPECIFICATION DESC="Im Folgenden sind die Kundenanforderungen f&#252;r das System zur Erkennung von Waldbr&#228;nden von Kunde X zusammengestellt" IDENTIFIER="specification_0" LAST-CHANGE="2018-04-13T11:24:18+02:00" LONG-NAME="System zur Erkennung von Waldbr&#228;nden">
61+
<TYPE>
62+
<SPECIFICATION-TYPE-REF>URS</SPECIFICATION-TYPE-REF>
63+
</TYPE>
64+
<CHILDREN>
65+
<SPEC-HIERARCHY IDENTIFIER="anforderungshierarchie_0" LAST-CHANGE="2018-04-13T11:24:18+02:00">
66+
<IS-TABLE-INTERNAL>False</IS-TABLE-INTERNAL>
67+
<OBJECT>
68+
<SPEC-OBJECT-REF>&#252;berwachungBodentemperatur</SPEC-OBJECT-REF>
69+
</OBJECT>
70+
<CHILDREN>
71+
<SPEC-HIERARCHY IDENTIFIER="anforderungshierarchie_1" LAST-CHANGE="2018-04-13T11:24:18+02:00">
72+
<IS-TABLE-INTERNAL>False</IS-TABLE-INTERNAL>
73+
<OBJECT>
74+
<SPEC-OBJECT-REF>erkennungFeuer</SPEC-OBJECT-REF>
75+
</OBJECT>
76+
<IS-EDITABLE>False</IS-EDITABLE>
77+
</SPEC-HIERARCHY>
78+
</CHILDREN>
79+
<IS-EDITABLE>False</IS-EDITABLE>
80+
</SPEC-HIERARCHY>
81+
</CHILDREN>
82+
</SPECIFICATION>
83+
</SPECIFICATIONS>
84+
<SPEC-RELATIONS>
85+
<SPEC-RELATION IDENTIFIER="beziehungAnforderungen_0" LAST-CHANGE="2018-04-13T11:24:18+02:00">
86+
<TARGET>
87+
<SPEC-OBJECT-REF>erkennungFeuer</SPEC-OBJECT-REF>
88+
</TARGET>
89+
<SOURCE>
90+
<SPEC-OBJECT-REF>&#252;berwachungBodentemperatur</SPEC-OBJECT-REF>
91+
</SOURCE>
92+
<TYPE>
93+
<SPEC-RELATION-TYPE-REF>Ableitungsbeziehung</SPEC-RELATION-TYPE-REF>
94+
</TYPE>
95+
</SPEC-RELATION>
96+
</SPEC-RELATIONS>
97+
</REQ-IF-CONTENT>
98+
</CORE-CONTENT>
99+
</REQ-IF>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This test verifies that the relative paths are interpreted correctly by the
2+
# validation command.
3+
#
4+
# Ths issue was reported here:
5+
# Validate against official schema does not work as expected #198,
6+
# https://github.com/strictdoc-project/reqif/issues/198
7+
#
8+
9+
RUN: %expect_exit 1 %reqif validate --use-reqif-schema sample.reqif | filecheck %s --dump-input=fail
10+
CHECK: Reason: must have the fixed value '1.0'

0 commit comments

Comments
 (0)