Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2fc7278

Browse files
committed
Validate output.xml schema as part of acceptance tests.
This isn't done for all outputs by default because it slows down execution a bit too much. That can be enabled by setting ATEST_VALIDATE_OUTPUT environment varibale to TRUE. Part of schema update issue robotframework#3726.
1 parent b302b0a commit 2fc7278

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

atest/README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ documentation from Java source files. In addition to setting ``CLASSPATH``
228228
explicitly, it is possible to put ``tools.jar`` into the ``ext-lib``
229229
directory in the project root and ``CLASSPATH`` is set automatically.
230230

231+
Schema validation
232+
-----------------
233+
234+
Created output.xml has `<../doc/schema>`_ that can be tested as part of acceptance
235+
test run. The schema is always used to validate selected outputs in
236+
`<robot/rebot/compatibility.robot>`_, but validating all outputs would slow down
237+
execution a bit too much.
238+
239+
It is, however, possible to enable validating all outputs by setting
240+
`ATEST_VALIDATE_OUTPUT` environment variable to `TRUE` (case-insensitive).
241+
This is recommended especially if the schema is updated or output.xml changed.
242+
231243
Telnet tests
232244
------------
233245

atest/resources/TestCheckerLibrary.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import re
33

4+
from xmlschema import XMLSchema
5+
46
from robot import utils
57
from robot.api import logger
68
from robot.utils.asserts import assert_equal
@@ -60,14 +62,22 @@ class NoSlotsTestSuite(TestSuite):
6062

6163

6264
class TestCheckerLibrary:
65+
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
66+
67+
def __init__(self):
68+
self.schema = XMLSchema('doc/schema/robot.02.xsd')
6369

64-
def process_output(self, path):
70+
def process_output(self, path, validate=None):
6571
set_suite_variable = BuiltIn().set_suite_variable
6672
if not path or path.upper() == 'NONE':
6773
set_suite_variable('$SUITE', None)
6874
logger.info("Not processing output.")
6975
return
7076
path = path.replace('/', os.sep)
77+
if validate is None:
78+
validate = os.getenv('ATEST_VALIDATE_OUTPUT', False)
79+
if utils.is_truthy(validate):
80+
self.schema.validate(path)
7181
try:
7282
logger.info("Processing output '%s'." % path)
7383
result = Result(root_suite=NoSlotsTestSuite())

atest/resources/atest_resource.robot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ Run Tests Without Processing Output
5252
[Return] ${result}
5353

5454
Run Rebot
55-
[Arguments] ${options}= ${sources}= ${default options}=${COMMON DEFAULTS} ${output}=${OUTFILE}
55+
[Arguments] ${options}= ${sources}= ${default options}=${COMMON DEFAULTS} ${output}=${OUTFILE} ${validate output}=True
5656
[Documentation] *OUTDIR:* file://${OUTDIR} (regenerated for every run)
5757
${result} = Execute ${INTERPRETER.rebot} ${options} ${sources} ${default options}
5858
Log Many RC: ${result.rc} STDERR:\n${result.stderr} STDOUT:\n${result.stdout}
59-
Process Output ${output}
59+
Process Output ${output} validate=${validate output}
6060
[Return] ${result}
6161

6262
Run Rebot Without Processing Output

atest/robot/rebot/compatibility.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Resource rebot_resource.robot
77

88
*** Test Cases ***
99
RF 3.2 compatibility
10-
Run Rebot And Validate Statistics rebot/output-3.2.2.xml 172 10
10+
Run Rebot And Validate Statistics rebot/output-3.2.2.xml 172 10 validate=False
1111

1212
RF 4.0 compatibility
1313
Run Rebot And Validate Statistics rebot/output-4.0.xml 172 10
@@ -21,8 +21,8 @@ Message directly under test
2121

2222
*** Keywords ***
2323
Run Rebot And Validate Statistics
24-
[Arguments] ${path} ${passed} ${failed}
25-
Run Rebot ${EMPTY} ${path}
24+
[Arguments] ${path} ${passed} ${failed} ${validate}=True
25+
Run Rebot ${EMPTY} ${path} validate output=${validate}
2626
${total} ${passed} ${failed} = Evaluate ${passed} + ${failed}, ${passed}, ${failed}
2727
Should Be Equal ${SUITE.statistics.total} ${total}
2828
Should Be Equal ${SUITE.statistics.passed} ${passed}

0 commit comments

Comments
 (0)