HookTest 1.3.0__tar.gz → 2.0.0rc0__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.
Files changed (46) hide show
  1. hooktest-2.0.0rc0/PKG-INFO +73 -0
  2. hooktest-2.0.0rc0/README.md +45 -0
  3. hooktest-2.0.0rc0/hooktest/cli.py +200 -0
  4. hooktest-2.0.0rc0/hooktest/resources/collection-schema.rng +195 -0
  5. hooktest-2.0.0rc0/hooktest/tester.py +626 -0
  6. hooktest-2.0.0rc0/hooktest.egg-info/PKG-INFO +73 -0
  7. hooktest-2.0.0rc0/hooktest.egg-info/SOURCES.txt +14 -0
  8. hooktest-2.0.0rc0/hooktest.egg-info/entry_points.txt +2 -0
  9. hooktest-2.0.0rc0/hooktest.egg-info/requires.txt +10 -0
  10. hooktest-2.0.0rc0/hooktest.egg-info/top_level.txt +2 -0
  11. hooktest-2.0.0rc0/pyproject.toml +45 -0
  12. hooktest-2.0.0rc0/tests/test_cli.py +235 -0
  13. hooktest-2.0.0rc0/tests/test_milestone_repeated_parent.py +26 -0
  14. HookTest-1.3.0/CHANGES.txt +0 -135
  15. HookTest-1.3.0/HookTest/build.py +0 -175
  16. HookTest-1.3.0/HookTest/capitains_units/__init__.py +0 -0
  17. HookTest-1.3.0/HookTest/capitains_units/cts.py +0 -756
  18. HookTest-1.3.0/HookTest/cmd.py +0 -166
  19. HookTest-1.3.0/HookTest/resources/epidoc.rng +0 -12585
  20. HookTest-1.3.0/HookTest/resources/tei.rng +0 -19429
  21. HookTest-1.3.0/HookTest/test.py +0 -882
  22. HookTest-1.3.0/HookTest/units.py +0 -102
  23. HookTest-1.3.0/HookTest.egg-info/PKG-INFO +0 -254
  24. HookTest-1.3.0/HookTest.egg-info/SOURCES.txt +0 -31
  25. HookTest-1.3.0/HookTest.egg-info/entry_points.txt +0 -4
  26. HookTest-1.3.0/HookTest.egg-info/not-zip-safe +0 -1
  27. HookTest-1.3.0/HookTest.egg-info/requires.txt +0 -6
  28. HookTest-1.3.0/HookTest.egg-info/top_level.txt +0 -2
  29. HookTest-1.3.0/MANIFEST.in +0 -3
  30. HookTest-1.3.0/PKG-INFO +0 -254
  31. HookTest-1.3.0/README.rst +0 -237
  32. HookTest-1.3.0/requirements.txt +0 -9
  33. HookTest-1.3.0/setup.py +0 -59
  34. HookTest-1.3.0/tests/__init__.py +0 -0
  35. HookTest-1.3.0/tests/test_build.py +0 -319
  36. HookTest-1.3.0/tests/test_cts/__init__.py +0 -0
  37. HookTest-1.3.0/tests/test_cts/mocks/__init__.py +0 -0
  38. HookTest-1.3.0/tests/test_cts/mocks/xmllang_data.py +0 -81
  39. HookTest-1.3.0/tests/test_cts/test_single_text_methods.py +0 -42
  40. HookTest-1.3.0/tests/test_finder.py +0 -166
  41. HookTest-1.3.0/tests/test_run.py +0 -597
  42. HookTest-1.3.0/tests/test_test.py +0 -1209
  43. HookTest-1.3.0/tests/test_units.py +0 -615
  44. {HookTest-1.3.0/HookTest → hooktest-2.0.0rc0/hooktest}/__init__.py +0 -0
  45. {HookTest-1.3.0/HookTest.egg-info → hooktest-2.0.0rc0/hooktest.egg-info}/dependency_links.txt +0 -0
  46. {HookTest-1.3.0 → hooktest-2.0.0rc0}/setup.cfg +0 -0
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: hooktest
3
+ Version: 2.0.0rc0
4
+ Summary: Library for testing CiteStructure data, using Dapitains library
5
+ Author-email: Thibault Clérice <leponteineptique@gmail.com>
6
+ License-Expression: MPL-2.0
7
+ Project-URL: Homepage, http://github.com/cllg/hooktest
8
+ Classifier: Topic :: Software Development :: Quality Assurance
9
+ Classifier: Topic :: Software Development :: Testing
10
+ Classifier: Topic :: Software Development :: Version Control
11
+ Classifier: Topic :: Text Processing :: Markup :: XML
12
+ Classifier: Topic :: Text Processing :: General
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Python: >=3.12
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: dapytains>=1.0.0rc5
20
+ Requires-Dist: click<9.0.0,>=8.1.8
21
+ Requires-Dist: colorama~=0.4.6
22
+ Requires-Dist: tabulate~=0.9.0
23
+ Requires-Dist: tqdm
24
+ Provides-Extra: test
25
+ Requires-Dist: pytest; extra == "test"
26
+ Requires-Dist: pytest-cov; extra == "test"
27
+ Requires-Dist: requests-mock; extra == "test"
28
+
29
+ ![Header for HookTest](images/header.png)
30
+
31
+ [![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
32
+ [![Software Test](https://github.com/cllg-project/hooktest/actions/workflows/test.yml/badge.svg)](https://github.com/cllg-project/hooktest/actions/workflows/test.yml)
33
+
34
+ Dapytains provides a server-side or client-side library to deal with
35
+ [Distributed Text Services APIs](https://distributed-text-services.github.io/) as well as
36
+ TEI XML files using the [CiteStructure](https://tei-c.org/release/doc/tei-p5-doc/en/html/ref-citeStructure.html)
37
+ encoding of their machine actionable architecture, allowing to split and retrieve reference in a file
38
+ "without human intervention".
39
+
40
+ HookTestv2, which replaces the original [HookTest](https://hal.science/hal-01709868/), allows for testing those file,
41
+ including tests for catalog registry.
42
+
43
+ **This software is still quite in alpha mode, feel free to report bugs**
44
+
45
+ ## How to install
46
+
47
+ ```sh
48
+ pip install --pre hooktest
49
+ ```
50
+
51
+ Or from source:
52
+
53
+ ```sh
54
+ git clone https://github.com/cllg-project/hooktest.git
55
+ cd hooktest
56
+ pip install .
57
+ ```
58
+
59
+ ## How to run
60
+
61
+ If you want to test a system where you have a root catalog file, you can run `hooktest path/to/your/catalog.xml`
62
+ where catalog are using [`hooktest/resources/collection-schema.rng`](hooktest/resources/collection-schema.rng).
63
+
64
+ Otherwise, run `hooktest --no-catalog /path/to/your/tei/files.xml`.
65
+
66
+
67
+ ## Support
68
+
69
+ Funded via the CLLG Project.
70
+
71
+ Ce travail a bénéficié d’une aide de l’État gérée par l’Agence Nationale de la
72
+ Recherche au titre de France 2030 portant la référence « ANR-24-RRII- 0002 » et opéré par
73
+ le Programme Inria Quadrant.
@@ -0,0 +1,45 @@
1
+ ![Header for HookTest](images/header.png)
2
+
3
+ [![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
4
+ [![Software Test](https://github.com/cllg-project/hooktest/actions/workflows/test.yml/badge.svg)](https://github.com/cllg-project/hooktest/actions/workflows/test.yml)
5
+
6
+ Dapytains provides a server-side or client-side library to deal with
7
+ [Distributed Text Services APIs](https://distributed-text-services.github.io/) as well as
8
+ TEI XML files using the [CiteStructure](https://tei-c.org/release/doc/tei-p5-doc/en/html/ref-citeStructure.html)
9
+ encoding of their machine actionable architecture, allowing to split and retrieve reference in a file
10
+ "without human intervention".
11
+
12
+ HookTestv2, which replaces the original [HookTest](https://hal.science/hal-01709868/), allows for testing those file,
13
+ including tests for catalog registry.
14
+
15
+ **This software is still quite in alpha mode, feel free to report bugs**
16
+
17
+ ## How to install
18
+
19
+ ```sh
20
+ pip install --pre hooktest
21
+ ```
22
+
23
+ Or from source:
24
+
25
+ ```sh
26
+ git clone https://github.com/cllg-project/hooktest.git
27
+ cd hooktest
28
+ pip install .
29
+ ```
30
+
31
+ ## How to run
32
+
33
+ If you want to test a system where you have a root catalog file, you can run `hooktest path/to/your/catalog.xml`
34
+ where catalog are using [`hooktest/resources/collection-schema.rng`](hooktest/resources/collection-schema.rng).
35
+
36
+ Otherwise, run `hooktest --no-catalog /path/to/your/tei/files.xml`.
37
+
38
+
39
+ ## Support
40
+
41
+ Funded via the CLLG Project.
42
+
43
+ Ce travail a bénéficié d’une aide de l’État gérée par l’Agence Nationale de la
44
+ Recherche au titre de France 2030 portant la référence « ANR-24-RRII- 0002 » et opéré par
45
+ le Programme Inria Quadrant.
@@ -0,0 +1,200 @@
1
+ import os.path
2
+ import sys
3
+ from typing import List
4
+ import click
5
+ import tabulate
6
+ import textwrap
7
+ from .tester import Tester, Log
8
+ from tqdm import tqdm
9
+
10
+ def to_small_caps(text):
11
+ small_caps_map = str.maketrans(
12
+ "abcdefghijklmnopqrstuvwxyz",
13
+ "ᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘǫʀsᴛᴜᴠᴡxʏᴢ"
14
+ )
15
+ return text.translate(small_caps_map)
16
+
17
+
18
+ class CustomLogger:
19
+ def __init__(self, level: str = "minimal"):
20
+ """
21
+
22
+ minimal
23
+ verbose
24
+
25
+ """
26
+ self._eq = {
27
+ "minimal": 10, # Only bugs and necessary info is shown
28
+ "details": 5, # Some information is kept
29
+ "verbose": 0 # Everything is shown
30
+ }
31
+ self.level = self._eq[level]
32
+ self.width = 88
33
+ self._table_indent = "\n "
34
+
35
+ def _print(self, string, level: str = "minimal", indent: int = 0, color : str = None, **kwargs):
36
+ if self._eq[level] >= self.level:
37
+ click.echo(click.style(indent*"\t"+string, fg=color, **kwargs))
38
+
39
+ def header(self, string, level: str = "minimal"):
40
+ self._print(f"\n==== {to_small_caps(string.title())} ====", level=level, bold=True)
41
+
42
+ def info(self, string, level: str = "minimal", indent: int = 0):
43
+ self._print(f"INFO: {string}", level=level, indent=indent, color="cyan")
44
+
45
+ def filter_logs(self, content: List[Log]):
46
+ return [
47
+ (
48
+ f"{log.name}: " + self.green_red(log.details or "✔", log.status) if log.status else (
49
+ f"{log.name}: " + self.green_red(
50
+ self._table_indent.join(textwrap.wrap(log.details, width=self.width)),
51
+ log.status
52
+ )
53
+ )
54
+ )
55
+ for log in content
56
+ if log.status == False or self.level <= 0
57
+ ]
58
+
59
+ def filter_append(self, haystack: List, hay, level: str = "minimal"):
60
+ if self._eq[level] >= self.level:
61
+ haystack.append(hay)
62
+
63
+ def green_red(self, string: str, status: bool):
64
+ if not status:
65
+ if self._table_indent in string:
66
+ return (click.style(" ", fg="reset")+self._table_indent).join(
67
+ click.style(substring, fg="red")
68
+ for substring in string.split(self._table_indent)
69
+ )
70
+ return click.style(string, fg="red")
71
+ elif status and self.level <= 5: # Only show green in details / verbose
72
+ return click.style(string, fg="green")
73
+ return string
74
+
75
+ def checkmark(self, status):
76
+ if status:
77
+ return self.green_red("✔", status)
78
+ return self.green_red("✗", status)
79
+
80
+ @click.command
81
+ @click.argument("files", nargs=-1, type=click.Path(file_okay=True, dir_okay=False, exists=True))
82
+ @click.option("-m", "--include-metadata-report", is_flag=True, default=False)
83
+ @click.option("-v", "--verbosity", default="minimal", type=click.Choice(["minimal", "details", "verbose"]))
84
+ @click.option("-f", "--failures-only", default=False, is_flag=True, help="Show failures only")
85
+ @click.option("-p", "--progress", default=False, is_flag=True, help="Enable progress bar")
86
+ @click.option("--catalog/--no-catalog", default=True, is_flag=True,
87
+ help="Use --no-catalog when you only one to test single files")
88
+ @click.option("-o", "--manifest", default=None, type=click.Path(dir_okay=False),
89
+ help="Write a manifest of files that passed all tests to this path")
90
+ @click.option("-s", "--schema", default=None, type=click.Path(exists=True, dir_okay=False),
91
+ help="Validate each TEI resource file against this RelaxNG (.rng) schema")
92
+ def cli(files, include_metadata_report: bool, verbosity: str, catalog: bool, progress: bool, failures_only: bool, manifest: str, schema: str):
93
+ tester = Tester(resource_schema=schema)
94
+ printer = CustomLogger(verbosity)
95
+ if catalog:
96
+ count_collections, count_resources = tester.ingest(files)
97
+ else:
98
+ count_resources = tester.ingest_tei_only(files)
99
+ count_collections = 0
100
+
101
+ catalog_results = dict(tester.results) if catalog else {}
102
+ if catalog:
103
+ printer.info(f"Found {count_collections} collection(s)")
104
+ printer.info(f"Found {count_resources} resource(s)")
105
+
106
+ #
107
+ # Collection files
108
+ #
109
+ if catalog:
110
+ printer.header("Report: Catalog files")
111
+ table = [["File", "Status", "Tests"]]
112
+ for file, result in tester.results.items():
113
+ if failures_only and result.status:
114
+ continue
115
+ printer.filter_append(
116
+ haystack=table,
117
+ hay=[
118
+ file,
119
+ printer.checkmark(result.status),
120
+ "\n".join(printer.filter_logs(result.statuses))
121
+ ],
122
+ level="minimal"
123
+ )
124
+ if failures_only and len(table) == 1:
125
+ click.echo("No error to report")
126
+ else:
127
+ click.echo(tabulate.tabulate(table, tablefmt="grid"))
128
+
129
+ #
130
+ # Metadata
131
+ #
132
+ if catalog and include_metadata_report:
133
+ printer.header("Report: Metadata")
134
+ table = [["Identifier", "Key", "Language", "Metadata"]]
135
+ for identifier, collection in tester.catalog.objects.items():
136
+ table.append([identifier, "title", "", collection.title])
137
+ if collection.description:
138
+ table.append([identifier, "description", "", collection.description])
139
+ for dc in collection.dublin_core:
140
+ table.append([identifier, f"dc:{dc.term}", dc.language or "", dc.value])
141
+ for ex in collection.extensions:
142
+ table.append([identifier, f"{ex.term}", ex.language or "", ex.value])
143
+ click.echo(tabulate.tabulate(table))
144
+
145
+ #
146
+ # Texts
147
+ #
148
+ printer.header("Report: TEI files")
149
+ table = [["File", "Status", "Tests"]]
150
+ global_status = []
151
+ for test, status in tester.tests(pbar=tqdm() if progress else None) .items():
152
+ global_status.append(status)
153
+ if (failures_only and status is False) or failures_only is False:
154
+ result = tester.results[test]
155
+ printer.filter_append(
156
+ haystack=table,
157
+ hay=[
158
+ os.path.relpath(test),
159
+ printer.checkmark(result.status),
160
+ "\n".join(printer.filter_logs(result.statuses))
161
+ ],
162
+ level="minimal"
163
+ )
164
+ if failures_only and len(table) == 1:
165
+ click.echo("No error to report")
166
+ else:
167
+ click.echo(tabulate.tabulate(table, tablefmt="grid"))
168
+
169
+ if manifest:
170
+ passing_files = [
171
+ os.path.relpath(file)
172
+ for file, result in tester.results.items()
173
+ if result.status
174
+ ]
175
+ with open(manifest, "w") as f:
176
+ f.write("\n".join(passing_files))
177
+ printer.info(f"Wrote {len(passing_files)} passing file(s) to manifest {manifest}")
178
+
179
+ printer.header("Summary")
180
+ rows = []
181
+ if catalog:
182
+ rows.append(["Collections found", count_collections])
183
+ rows.append(["Catalog files tested", len(catalog_results)])
184
+ rows.append(["Catalog files failed", sum(1 for r in catalog_results.values() if not r.status)])
185
+ rows.append(["Resources found", count_resources])
186
+ rows.append(["TEI files tested", len(global_status)])
187
+ rows.append(["TEI files passed", global_status.count(True)])
188
+ rows.append(["TEI files failed", global_status.count(False)])
189
+ click.echo(tabulate.tabulate(rows, tablefmt="simple"))
190
+
191
+ if False not in global_status:
192
+ click.echo("All tests passed")
193
+ else:
194
+ click.echo(f"{global_status.count(False)/len(global_status)*100:.2f}% of the files "
195
+ f"failed (Abs: {global_status.count(False)}/{len(global_status)})")
196
+ sys.exit(1)
197
+ return tester
198
+
199
+ if __name__ == "__main__":
200
+ cli()
@@ -0,0 +1,195 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <grammar
3
+ xmlns="http://relaxng.org/ns/structure/1.0"
4
+ xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
5
+ datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
6
+ <start>
7
+ <choice>
8
+ <ref name="resource"/>
9
+ <ref name="collection"/>
10
+ </choice>
11
+ </start>
12
+
13
+ <define name="identifier-and-path">
14
+ <choice>
15
+ <group>
16
+ <attribute name="identifier">
17
+ <a:documentation>Identifier of the Collection or Resource</a:documentation>
18
+ <data type="anyURI"/>
19
+ </attribute>
20
+ <optional>
21
+ <attribute name="filepath">
22
+ <a:documentation>Path to the relevant Collection or Resource</a:documentation>
23
+ <data type="anyURI"/>
24
+ </attribute>
25
+ </optional>
26
+ </group>
27
+ <!-- Link stub: the identifier lives in the linked catalog file -->
28
+ <attribute name="filepath">
29
+ <a:documentation>Path to the relevant Collection or Resource</a:documentation>
30
+ <data type="anyURI"/>
31
+ </attribute>
32
+ </choice>
33
+ </define>
34
+ <define name="parent">
35
+ <optional>
36
+ <element name="parent">
37
+ <a:documentation xml:lang="eng">Identifier of the parent if required by a parent
38
+ collection</a:documentation>
39
+ <data type="anyURI"/>
40
+ </element>
41
+ </optional>
42
+ </define>
43
+ <define name="baseDetails">
44
+ <element name="title">
45
+ <a:documentation>Title / name of a Collection or Resource</a:documentation>
46
+ <data type="string"/>
47
+ </element>
48
+ <optional>
49
+ <element name="description">
50
+ <a:documentation>Description of a Collection or Resource</a:documentation>
51
+ <data type="string"/>
52
+ </element>
53
+ </optional>
54
+ </define>
55
+ <define name="dublinCore">
56
+ <element name="dublinCore">
57
+ <interleave>
58
+ <zeroOrMore>
59
+ <element ns="http://purl.org/dc/terms/">
60
+ <a:documentation>Something</a:documentation>
61
+ <choice>
62
+ <name>abstract</name>
63
+ <name>accessRights</name>
64
+ <name>accrualMethod</name>
65
+ <name>accrualPeriodicity</name>
66
+ <name>accrualPolicy</name>
67
+ <name>alternative</name>
68
+ <name>audience</name>
69
+ <name>available</name>
70
+ <name>bibliographicCitation</name>
71
+ <name>conformsTo</name>
72
+ <name>contributor</name>
73
+ <name>coverage</name>
74
+ <name>created</name>
75
+ <name>creator</name>
76
+ <name>date</name>
77
+ <name>dateAccepted</name>
78
+ <name>dateCopyrighted</name>
79
+ <name>dateSubmitted</name>
80
+ <name>description</name>
81
+ <name>educationLevel</name>
82
+ <name>extent</name>
83
+ <name>format</name>
84
+ <name>hasFormat</name>
85
+ <name>hasPart</name>
86
+ <name>hasVersion</name>
87
+ <name>identifier</name>
88
+ <name>instructionalMethod</name>
89
+ <name>isFormatOf</name>
90
+ <name>isPartOf</name>
91
+ <name>isReferencedBy</name>
92
+ <name>isReplacedBy</name>
93
+ <name>isRequiredBy</name>
94
+ <name>issued</name>
95
+ <name>isVersionOf</name>
96
+ <name>language</name>
97
+ <name>license</name>
98
+ <name>mediator</name>
99
+ <name>medium</name>
100
+ <name>modified</name>
101
+ <name>provenance</name>
102
+ <name>publisher</name>
103
+ <name>references</name>
104
+ <name>relation</name>
105
+ <name>replaces</name>
106
+ <name>requires</name>
107
+ <name>rights</name>
108
+ <name>rightsHolder</name>
109
+ <name>source</name>
110
+ <name>spatial</name>
111
+ <name>subject</name>
112
+ <name>tableOfContents</name>
113
+ <name>temporal</name>
114
+ <name>title</name>
115
+ <name>type</name>
116
+ <name>valid</name>
117
+ </choice>
118
+ <optional>
119
+ <attribute name="xml:lang">
120
+ <data type="language"/>
121
+ </attribute>
122
+ </optional>
123
+ <data type="string"/>
124
+ </element>
125
+ </zeroOrMore>
126
+ </interleave>
127
+ </element>
128
+
129
+ </define>
130
+ <define name="extension">
131
+ <element>
132
+ <a:documentation>Structured metadata contains any other optional metadata that are not part of
133
+ DublinCore Terms namespace</a:documentation>
134
+ <name>extensions</name>
135
+ <zeroOrMore>
136
+ <element>
137
+ <anyName>
138
+ <except>
139
+ <nsName ns="http://purl.org/dc/terms/"/>
140
+ </except>
141
+ </anyName>
142
+ <optional>
143
+ <attribute name="xml:lang">
144
+ <data type="language"/>
145
+ </attribute>
146
+ </optional>
147
+ <text/>
148
+ </element>
149
+ </zeroOrMore>
150
+ </element>
151
+ </define>
152
+ <define name="members">
153
+ <a:documentation>Children member of a collection or ressource</a:documentation>
154
+ <element>
155
+ <name>members</name>
156
+ <interleave>
157
+ <oneOrMore>
158
+ <choice>
159
+ <ref name="collection"/>
160
+ <ref name="resource"/>
161
+ </choice>
162
+ </oneOrMore>
163
+ </interleave>
164
+ </element>
165
+ </define>
166
+ <define name="collection-pattern">
167
+ <ref name="identifier-and-path"/>
168
+ <ref name="parent"/>
169
+ <optional>
170
+ <ref name="baseDetails"/>
171
+ </optional>
172
+ <optional>
173
+ <ref name="dublinCore"/>
174
+ </optional>
175
+ <optional>
176
+ <ref name="extension"/>
177
+ </optional>
178
+ <optional>
179
+ <ref name="members"/>
180
+ </optional>
181
+ <optional>
182
+ <ref name="parent"/>
183
+ </optional>
184
+ </define>
185
+ <define name="resource">
186
+ <element name="resource">
187
+ <ref name="collection-pattern"/>
188
+ </element>
189
+ </define>
190
+ <define name="collection">
191
+ <element name="collection">
192
+ <ref name="collection-pattern"/>
193
+ </element>
194
+ </define>
195
+ </grammar>