robotframework-xmlvalidator 1.0.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: robotframework-xmlvalidator
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Summary: A Robot Framework test library for validating XML files against XSD schemas
5
5
  License: Apache-2.0
6
6
  Keywords: robotframework,xml,xsd,validation,test-library,test,testing,test-automation
@@ -25,9 +25,14 @@ Project-URL: Homepage, https://github.com/MichaelHallik/robotframework-xmlvalida
25
25
  Project-URL: Repository, https://github.com/MichaelHallik/robotframework-xmlvalidator
26
26
  Description-Content-Type: text/markdown
27
27
 
28
- [![PyPI version](https://img.shields.io/pypi/v/robotframework-xmlvalidator.svg)](https://pypi.org/project/robotframework-xmlvalidator/)
29
- [![License](https://img.shields.io/pypi/l/robotframework-xmlvalidator)](LICENSE)
30
- [![Tests](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml/badge.svg)](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml)
28
+ | Version | License | Tests |
29
+ |---------|---------|-------|
30
+ | [![PyPI version](https://img.shields.io/pypi/v/robotframework-xmlvalidator.svg)](https://pypi.org/project/robotframework-xmlvalidator/) | [![License](https://img.shields.io/pypi/l/robotframework-xmlvalidator?cacheSeconds=600)](LICENSE) | [![Tests](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml/badge.svg)](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/test.yml) |
31
+
32
+ | Downloads | Update Badge |
33
+ |-----------|---------------|
34
+ | [![Total Downloads](https://github.com/MichaelHallik/robotframework-xmlvalidator/raw/main/badge_pepy_downloads.svg)](https://pepy.tech/project/robotframework-xmlvalidator) | [![Run Badge Update](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/update_pepy_badge.yml/badge.svg)](https://github.com/MichaelHallik/robotframework-xmlvalidator/actions/workflows/update_pepy_badge.yml) |
35
+
31
36
 
32
37
  <details>
33
38
  <summary><strong>📚 Table of Contents</strong></summary>
@@ -46,14 +51,26 @@ Description-Content-Type: text/markdown
46
51
  - [Examples](#examples)
47
52
  - [Using a preloaded schema](#using-a-preloaded-schema)
48
53
  - [Defer schema loading to the test case(s)](#defer-schema-loading-to-the-test-cases)
49
- - [Importing with preloaded XSD that requires a base\_url](#importing-with-preloaded-xsd-that-requires-a-base_url)
50
- - [Importing with custom error\_facets](#importing-with-custom-error_facets)
54
+ - [Importing with preloaded XSD that requires a `base_url`](#importing-with-preloaded-xsd-that-requires-a-base_url)
55
+ - [Importing with custom `error_facets`](#importing-with-custom-error_facets)
56
+ - [Importing with \`fail\_on\_errors=True](#importing-with-fail_on_errorstrue)
51
57
  - [Further examples](#further-examples)
52
58
  - [Using the library](#using-the-library)
53
59
  - [Keyword overview](#keyword-overview)
60
+ - [Error collection](#error-collection)
61
+ - [Batch mode](#batch-mode)
62
+ - [Single file mode](#single-file-mode)
63
+ - [Test case status - fail\_on\_error](#test-case-status---fail_on_error)
64
+ - [Dyanmic XSD resolution](#dyanmic-xsd-resolution)
65
+ - [Error collection](#error-collection-1)
66
+ - [XSD Schema violations.](#xsd-schema-violations)
67
+ - [Malformed XML](#malformed-xml)
68
+ - [File-level issues](#file-level-issues)
69
+ - [Final note on error collection](#final-note-on-error-collection)
54
70
  - [Keyword documentation](#keyword-documentation)
55
71
  - [Keyword example usage](#keyword-example-usage)
56
72
  - [A few basic examples](#a-few-basic-examples)
73
+ - [Demo test suite file as examples](#demo-test-suite-file-as-examples)
57
74
  - [Integration tests as examples](#integration-tests-as-examples)
58
75
  - [Example console output](#example-console-output)
59
76
  - [Example CSV output](#example-csv-output)
@@ -75,6 +92,8 @@ Description-Content-Type: text/markdown
75
92
  - [Continuous Integration \& GitHub templates](#continuous-integration--github-templates)
76
93
  - [Class architecture (Simplified)](#class-architecture-simplified)
77
94
  - [Project Structure](#project-structure)
95
+ - [Changelog](#changelog)
96
+ - [Roadmap](#roadmap)
78
97
  - [License](#license)
79
98
  - [Author](#author)
80
99
 
@@ -99,7 +118,7 @@ It provides structured and detailed reporting of XML parse errors (malformed XML
99
118
  - Customizable error attributes (`path`, `reason`, `message`, etc.)
100
119
  - Batch validation and per-file error tracking
101
120
  - Export collected errors to CSV (with optional file name timestamping).
102
- - And more (see below and the keyword documentation).
121
+ - And more.
103
122
 
104
123
  ---
105
124
 
@@ -147,11 +166,12 @@ See the [Robot Framework Library Scope docs](https://robotframework.org/robotfra
147
166
 
148
167
  ### Library arguments
149
168
 
150
- | Argument | Type | Required? | Description |
151
- |----------------|-------------|-----------|------------------------------------------------------------------------------------|
152
- | `xsd_path` | `str` | No | Path to an XSD file or folder to preload during initialization. In case of a folder, the folder must hold one file only. |
153
- | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. |
154
- | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) |
169
+ | Argument | Type | Required? | Description | Default |
170
+ |-----------------|-------------|-----------|------------------------------------------------------------------------------------------------------------------------|-----------------|
171
+ | `xsd_path` | `str` | No | Path to an XSD file/folder to preload during initialization. In case of a folder, the folder must hold one file only. | None |
172
+ | `base_url` | `str` | No | Base path used to resolve includes/imports within the provided XSD schema. | None |
173
+ | `error_facets` | `list[str]` | No | The attributes of validation errors to collect and report (e.g., `path`, `reason`) | [path, reason] |
174
+ | `fail_on_error` | `bool` | No | Whether to fail the test case if one or more XML validation errors are found. Can be overridden per keyword call. | True |
155
175
 
156
176
  ### Examples
157
177
 
@@ -168,7 +188,7 @@ Library xmlvalidator xsd_path=path/to/schema.xsd
168
188
  Library xmlvalidator
169
189
  ```
170
190
 
171
- #### Importing with preloaded XSD that requires a base_url
191
+ #### Importing with preloaded XSD that requires a `base_url`
172
192
 
173
193
  ```robotframework
174
194
  Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
@@ -177,7 +197,7 @@ Library xmlvalidator xsd_path=path/to/schema_with_include.xsd
177
197
 
178
198
  Use `base_url` when your XSD uses `<xs:include>` or `<xs:import>` with relative paths.
179
199
 
180
- #### Importing with custom error_facets
200
+ #### Importing with custom `error_facets`
181
201
 
182
202
  Use the `error_facets` argument to control which attributes of detected errors will be collected and reported.
183
203
 
@@ -196,6 +216,21 @@ Library xmlvalidator xsd_path=schemas/schema.xsd
196
216
  ... error_facets=value, namespaces
197
217
  ```
198
218
 
219
+ #### Importing with `fail_on_errors=True
220
+
221
+ The fail_on_errors argument controls whether a test case should fail if XML validation errors are detected.
222
+
223
+ It defaults to True.
224
+
225
+ The library's batch validation behavior remains unchanged. That is, `fail_on_errors=True` does *not* short-circuit the validation process in any way.
226
+
227
+ Set `fail_on_errors=False` to log validation issues without failing the test. This is useful for:
228
+
229
+ - Non-blocking checks in dashboards or QA reports.
230
+ - Legacy or transitional systems where some invalid files are expected.
231
+ - Schema discovery or diagnostics, where conformance isn’t yet enforced.
232
+ - Soft rollout of stricter validation rules, allowing time to adapt.
233
+
199
234
  #### Further examples
200
235
 
201
236
  See also the [library initialization Robot test file](test/integration/01_library_initialization.robot).
@@ -206,43 +241,154 @@ See also the [library initialization Robot test file](test/integration/01_librar
206
241
 
207
242
  ### Keyword overview
208
243
 
209
- | Keyword | Description |
210
- |--------------------------|-------------|
244
+ Thi section merely provides a short summary of the library's capabilities.
245
+
246
+ For more details, please see the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
247
+
248
+ | Keyword | Description |
249
+ |--------------------------|---------------------------------------------------------------------|
211
250
  | `Validate Xml Files` | Validate one or more XML files against one or more XSD schema files |
212
- | `Reset Schema` | Clear the currently loaded XSD schema |
213
- | `Reset Errors` | Clear the set of collected errors |
214
- | `Get Schema` | Get the current schema name or object |
215
- | `Log Schema` | Log the currently loaded schema |
216
- | `Get Error Facets` | Returns a list of the currently active error facets |
217
- | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
251
+ | `Reset Schema` | Clear the currently loaded XSD schema |
252
+ | `Reset Errors` | Clear the set of collected errors |
253
+ | `Get Schema` | Get the current schema name or object |
254
+ | `Log Schema` | Log the currently loaded schema |
255
+ | `Get Error Facets` | Returns a list of the currently active error facets |
256
+ | `Reset Error Facets` | Reset the error facets to default (`path`, `reason`) |
218
257
 
219
258
  The main keyword is `Validate Xml Files`. The other keywords are convenience/helper functions, e.g. 'Reset Error Facets'.
220
259
 
260
+ #### Error collection
261
+
221
262
  The `Validate Xml Files` validates one or more XML files against one or more XSD schema files and collects and reports all encountered errors.
222
263
 
223
- The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files (e.g. parse errors), empty files, unmatched XML files (no XSD match found), etc.
264
+ The type of error that the keyword can detect is not limited to XSD violations, but may also pertain to malformed XML files, empty files, unmatched XML files (no XSD match found), etc.
224
265
 
225
266
  Errors that result from malformed XML files or from XSD violations support detailed error reporting. Using the `error_facets` argument you may specify the details the keyword should collect and report about captured errors.
226
267
 
227
- When operating in batch mode, the `Validate Xml Files` keyword always validates the entire set of passed XML files.
268
+ #### Batch mode
269
+
270
+ The `Validate Xml Files` keyword always validates the entire set of passed XML files.
228
271
 
229
- That is, when it encounters an error in a file, it does not fail. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
272
+ That is, when it encounters an error in a file, it does not fail and stop execution. Rather, it collects the error details (as determined by the `error_facets` arg) and then continues validating the current file as well as any subsequent file(s).
230
273
 
231
274
  In that fashion the keyword works through the entire set of files.
232
275
 
233
- When having finished checking the last file, it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
276
+ Once *all* files are processed it will log a summary of the test run and then proceed to report all collected errors in the console, in the RF log and, optionally, in the form of a CSV file.
234
277
 
235
- However, in case you want your test case to fail when one or more errors have been detected, you can use the ``fail_on_errors`` (bool) argument to make it so. It defaults to False. When setting it to True, then the keyword will still check each XML file (and collect possible errors), but after it has thus processed the batch, it will fail if one or more errors will have been detected.
278
+ For example:
279
+ - If you validate fifteen XML files and five of them contain schema violations or other errors, all files will still be processed.
280
+ - Errors are simply collected throughout the run and reported collectively, only after the final file has been (fully) processed.
281
+ - The test case will fail (assuming `fail_on_errors=True`) only after all files have been checked, ensuring comprehensive diagnostics.
236
282
 
237
- The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
283
+ #### Single file mode
238
284
 
239
285
  Of course, you may also refer to specific XML/XSD files (instead of to folders). In that case, no matching will be attempted, but the keyword will simply try to validate the specified XML file against the specified XSD file.
240
286
 
241
- See for more details the keyword documentation.
287
+ Actually, almost anything goes:
288
+
289
+ - one folder with: one or more XML files and one or more XSD files
290
+ - one folder with one or more XML files and another folder with one or more XSD files
291
+ - one folder with one or more XML files and a single XSD file
292
+ - a single XML file and a sigle XSD file
293
+
294
+ #### Test case status - fail_on_error
295
+
296
+ A test case that has resulted in the collection of one or more errors (of whatever type) will receive a status of FAIL. You can use the ``fail_on_errors`` (bool) argument to change this default behaviour. When set to `False`, the test cases's status will always be PASS, regardless whether errors were collected or not.
297
+
298
+ #### Dyanmic XSD resolution
299
+
300
+ The keyword further supports the dynamic matching (i.e. pairing) of XML and XSD files, using either a 'by filename' or a 'by namespace' strategy. That means you can simply pass the paths to a folder containing XML files and to a folder containing XSD files and the keyword will determine which XSD schema file to use for each XML file. If the XML and XSD files reside in the same folder, you only have to pass one folder path. When no matching XSD schema could be identified for an XML file, this will be integrated into the mentioned summary and error reporting (the keyword will not fail).
301
+
302
+ ### Error collection
303
+
304
+ Errors that are collected and reported can be categorized as follows:
305
+
306
+ #### XSD Schema violations.
307
+
308
+ - Missing or extra elements that violate cardinality rules, e.g.:
309
+ - Verifies that all mandatory elements (minOccurs > 0) are present in the XML.
310
+ - Ensures that optional elements (minOccurs = 0) do not exceed their maximum allowed occurrences (maxOccurs).
311
+
312
+ - Sequence and order violations:
313
+ - Validates the order of child elements within a parent element if the schema specifies a sequence model (`<xsd:sequence>`).
314
+ - Detects elements that are out of order or missing in a sequence.
315
+
316
+ - Datatype violations:
317
+ - Ensures that element and attribute values conform to their specified datatypes (e.g., xs:string, xs:integer, xs:dateTime).
318
+ - Identifies invalid formats, such as incorrect date or time formats for xs:date and xs:dateTime.
319
+
320
+ - Pattern and enumeration violations:
321
+ - Checks that values conform to patterns defined using `<xsd:pattern>`.
322
+ - Ensures that values fall within allowed enumerations specified in the schema.
323
+
324
+ - Attribute validation:
325
+ - Verifies that required attributes are present.
326
+ - Ensures that attribute values adhere to their declared datatypes and constraints.
327
+
328
+ - Namespace compliance:
329
+ - Validates that elements and attributes belong to the correct namespaces as defined in the schema.
330
+ - Detects namespace mismatches or missing namespace declarations.
331
+
332
+ - Group model violations:
333
+ - Validates conformance with `<xsd:choice>` and `<xsd:all>` group models, ensuring correct usage of child elements as per the schema.
334
+
335
+ - Referential constraints:
336
+ - Checks for violations in `<xsd:key>`, `<xsd:keyref>`, and `<xsd:unique>` constraints.
337
+
338
+ - Document structure and completeness:
339
+ - Ensures that the XML document adheres to the hierarchical structure defined by the schema.
340
+ - Detects incomplete or improperly nested elements.
341
+
342
+ - General schema violations:
343
+ - Detects schema-level issues, such as invalid imports or includes, during schema compilation if they affect validation.
344
+
345
+ #### Malformed XML
346
+
347
+ Malformed XML errors arise from issues that prevent the XML file from being parsed at all, before schema validation can even occur. These errors typically reflect syntactic problems in the structure or encoding of the XML content.
348
+
349
+ Typical cases include:
350
+
351
+ - Mismatched tags
352
+ - Opening and closing tags do not match.
353
+ - Example: `<Title>My Book</title>`
354
+
355
+ - Unclosed elements
356
+ - Elements are left unclosed or self-closing syntax is incorrect.
357
+ - Example: `<Price>12.99`
358
+
359
+ - Premature end-of-file
360
+ - The file ends abruptly before all tags are closed, often due to truncation or corruption.
361
+ - Example: `<Product><ID>123`
362
+
363
+ - Invalid characters or encoding
364
+ - The XML includes characters that are not valid in the declared encoding or in XML itself.
365
+ - Example: Control characters or non-UTF-8 bytes.
366
+
367
+ - Misused namespaces
368
+ - Prefixes declared but not bound, or invalid namespace URIs used.
369
+
370
+ - Declaration errors
371
+ - Malformed or duplicate `<?xml ... ?>` declarations.
372
+
373
+ #### File-level issues
374
+
375
+ General errors that do not pertain to syntax or schema issues:
376
+
377
+ | Error Type | Description |
378
+ |--------------|-------------------------------------------|
379
+ | Missing File | The specified XML file could not be found |
380
+ | Empty File | The file exists but is completely empty |
381
+ | Wrong Format | The file is not `.xml` or `.xsd` |
382
+
383
+ #### Final note on error collection
384
+
385
+ On account of the purpose of this library, all encountered errors (regardless the involved types) are collected and reported. The validator analyzes all files, collects encountered errors (if any) and, finally, reports the results of the run in the console and in the Robot Framework log.
386
+
387
+ Every test case in which one or more errors have been collected, will receive status FAIL unless `fail_on_errors=True` (see earlier explanations).
242
388
 
243
389
  ### Keyword documentation
244
390
 
245
- See [keyword documention](docs/XmlValidator.html).
391
+ See the [keyword documentation](https://michaelhallik.github.io/robotframework-xmlvalidator/XmlValidator.html).
246
392
 
247
393
  The keyword documentation provides detailed descriptions of all functionalities, features and the various ways in which the library and its keywords can be employed.
248
394
 
@@ -287,6 +433,10 @@ Validate Folder With Multiple Schemas By File Name
287
433
  Validate Xml Files ${FOLDER_MULTIPLE_XML_XSD_FN} xsd_search_strategy=by_file_name
288
434
  ```
289
435
 
436
+ #### Demo test suite file as examples
437
+
438
+ See the [demo test suite](test/demo/demo.robot) for a demo test suite that demonstrates the most important features of the library in a concise fashion.
439
+
290
440
  #### Integration tests as examples
291
441
 
292
442
  Note that the [integration test](test/integration) folder contains seven Robot Framework test suite files.
@@ -403,7 +553,7 @@ These are the facets (or attributes) that can be collected and reported for each
403
553
  | `severity` | The severity level of the error (not always present). |
404
554
  | `args` | The arguments passed to the error message formatting.
405
555
 
406
- Use the `error_facets` arg to set which error details to collect.
556
+ Use the `error_facets` argument to set which error details to collect.
407
557
 
408
558
  For each error that is encountered, the selected error facet(s) will be collected and reported.
409
559
 
@@ -413,7 +563,7 @@ You can customize which error facet(s) should be collected, by passing a list of
413
563
 
414
564
  Error facets passed during library initialization will be overruled by error facets that are passed at the test case level, when calling the `Validate Xml Files` keyword.
415
565
 
416
- The values you can pass through the `error_facets` argument are based on the attributes of the error objects as returned by the XMLSchema.iter_errors() method, that is provided by the xmlschema library and the the xmlvalidator library leverages. Said method yields instances of xmlschema.validators.exceptions.XMLSchemaValidationError (or its subclasses), each representing a specific validation issue encountered in an XML file. These error objects expose various attributes that describe the nature, location, and cause of the problem.
566
+ The values you can pass through the `error_facets` argument are based on the attributes of the error objects as returned by the XMLSchema.iter_errors() method, that is provided by the xmlschema library and the xmlvalidator library leverages. Said method yields instances of xmlschema.validators.exceptions.XMLSchemaValidationError (or its subclasses), each representing a specific validation issue encountered in an XML file. These error objects expose various attributes that describe the nature, location, and cause of the problem.
417
567
 
418
568
  The table lists the most commonly available attributes, though additional fields may be available depending on the type of validation error.
419
569
 
@@ -427,7 +577,7 @@ The table lists the most commonly available attributes, though additional fields
427
577
  | [CHANGELOG](CHANGELOG.md) | User / Dev | Version history, features |
428
578
  | [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) | Dev | Community guidelines |
429
579
  | [CONTRIBUTING](CONTRIBUTING.md) | Dev | Contribute |
430
- | [Mermaid diagram of GitHub Actions](github_actions.md) | Dev | CI, GitHub Actions |
580
+ | [Mermaid diagram of GitHub Actions](docs/images/github_actions.md) | Dev | CI, GitHub Actions |
431
581
  | [License](LICENSE) | All | Legal usage terms |
432
582
  | [Make file](Makefile) | Dev | Automation, commands |
433
583
  | [Project Structure](project_structure.txt) | Dev | Project layout |
@@ -450,7 +600,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
450
600
 
451
601
  The overall process:
452
602
 
453
- ![Contributing to the project](./docs/images/contributing.JPG)
603
+ ![Contributing to robotframework-xmlvalidator](./docs/images/contributing.JPG)
454
604
 
455
605
  This project uses Poetry for dependency and packaging management.
456
606
 
@@ -475,7 +625,7 @@ poetry install
475
625
  poetry shell
476
626
  ```
477
627
 
478
- Or, if you use a different virt env, activate that.
628
+ Or, if you use a different virt environment, activate that.
479
629
 
480
630
  ### Running tests
481
631
 
@@ -535,7 +685,7 @@ GitHub Actions CI is defined under [github/workflows/](.github/workflows/), in p
535
685
 
536
686
  The test workflow:
537
687
 
538
- ![Test workflow diagram](./docs/images/test_workflow.JPG)
688
+ ![Workflow diagram for the robotframework-xmlvalidator project](./docs/images/test_workflow.JPG)
539
689
 
540
690
  In [.github/](.github/) you’ll also find the various contribution templates:
541
691
 
@@ -675,6 +825,18 @@ requirements.txt # Requirements file for users (pip)
675
825
 
676
826
  ---
677
827
 
828
+ ## Changelog
829
+
830
+ For a list of changes across versions, including recent behavioral changes in validation logic, see the [CHANGELOG](https://github.com/MichaelHallik/robotframework-xmlvalidator/blob/main/CHANGELOG.md).
831
+
832
+ ---
833
+
834
+ ## Roadmap
835
+
836
+ See the [project roadmap](ROADMAP.md) for upcoming features and ideas.
837
+
838
+ ---
839
+
678
840
  ## License
679
841
 
680
842
  Licensed under the Apache License 2.0. See [LICENSE](LICENSE).