ui-coverage-tool 0.1.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.
Files changed (39) hide show
  1. ui_coverage_tool-0.1.0/LICENSE +201 -0
  2. ui_coverage_tool-0.1.0/MANIFEST.in +3 -0
  3. ui_coverage_tool-0.1.0/PKG-INFO +31 -0
  4. ui_coverage_tool-0.1.0/README.md +1 -0
  5. ui_coverage_tool-0.1.0/setup.cfg +4 -0
  6. ui_coverage_tool-0.1.0/setup.py +34 -0
  7. ui_coverage_tool-0.1.0/ui_coverage_tool/__init__.py +0 -0
  8. ui_coverage_tool-0.1.0/ui_coverage_tool/cli/__init__.py +0 -0
  9. ui_coverage_tool-0.1.0/ui_coverage_tool/cli/commands/__init__.py +0 -0
  10. ui_coverage_tool-0.1.0/ui_coverage_tool/cli/commands/save_report.py +41 -0
  11. ui_coverage_tool-0.1.0/ui_coverage_tool/cli/main.py +22 -0
  12. ui_coverage_tool-0.1.0/ui_coverage_tool/config.py +80 -0
  13. ui_coverage_tool-0.1.0/ui_coverage_tool/src/__init__.py +0 -0
  14. ui_coverage_tool-0.1.0/ui_coverage_tool/src/coverage/__init__.py +0 -0
  15. ui_coverage_tool-0.1.0/ui_coverage_tool/src/coverage/builder.py +53 -0
  16. ui_coverage_tool-0.1.0/ui_coverage_tool/src/coverage/models.py +25 -0
  17. ui_coverage_tool-0.1.0/ui_coverage_tool/src/history/__init__.py +0 -0
  18. ui_coverage_tool-0.1.0/ui_coverage_tool/src/history/builder.py +71 -0
  19. ui_coverage_tool-0.1.0/ui_coverage_tool/src/history/models.py +36 -0
  20. ui_coverage_tool-0.1.0/ui_coverage_tool/src/history/selector.py +6 -0
  21. ui_coverage_tool-0.1.0/ui_coverage_tool/src/history/storage.py +55 -0
  22. ui_coverage_tool-0.1.0/ui_coverage_tool/src/reports/__init__.py +0 -0
  23. ui_coverage_tool-0.1.0/ui_coverage_tool/src/reports/models.py +33 -0
  24. ui_coverage_tool-0.1.0/ui_coverage_tool/src/reports/storage.py +52 -0
  25. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tools/__init__.py +0 -0
  26. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tools/actions.py +13 -0
  27. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tools/logger.py +16 -0
  28. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tools/selector.py +9 -0
  29. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tools/types.py +7 -0
  30. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tracker/__init__.py +0 -0
  31. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tracker/core.py +30 -0
  32. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tracker/models.py +71 -0
  33. ui_coverage_tool-0.1.0/ui_coverage_tool/src/tracker/storage.py +42 -0
  34. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/PKG-INFO +31 -0
  35. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/SOURCES.txt +37 -0
  36. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/dependency_links.txt +1 -0
  37. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/entry_points.txt +2 -0
  38. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/requires.txt +4 -0
  39. ui_coverage_tool-0.1.0/ui_coverage_tool.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ include swagger_coverage_tool/config.py
2
+ recursive-include swagger_coverage_tool/cli/*
3
+ recursive-include swagger_coverage_tool/src *
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: ui-coverage-tool
3
+ Version: 0.1.0
4
+ Summary: TODO
5
+ Home-page: https://github.com/Nikita-Filonov/ui-coverage-tool
6
+ Author: Nikita Filonov
7
+ Author-email: filonov.nikitkaa@gmail.com
8
+ Project-URL: Bug Tracker, https://github.com/Nikita-Filonov/ui-coverage-tool/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: click
16
+ Requires-Dist: pyyaml>=6.0.2
17
+ Requires-Dist: pydantic>=2.0.0
18
+ Requires-Dist: pydantic-settings>=2.8.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license-file
26
+ Dynamic: project-url
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
30
+
31
+ TODO
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,34 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="ui-coverage-tool",
5
+ version="0.1.0",
6
+ packages=find_packages(),
7
+ include_package_data=True,
8
+ install_requires=[
9
+ "click",
10
+ "pyyaml>=6.0.2",
11
+ "pydantic>=2.0.0",
12
+ "pydantic-settings>=2.8.0",
13
+ ],
14
+ entry_points={
15
+ 'console_scripts': [
16
+ 'ui-coverage-tool = ui_coverage_tool.cli.main:cli',
17
+ ],
18
+ },
19
+ author="Nikita Filonov",
20
+ author_email="filonov.nikitkaa@gmail.com",
21
+ description="TODO",
22
+ long_description=open('README.md').read(),
23
+ long_description_content_type="text/markdown",
24
+ url="https://github.com/Nikita-Filonov/ui-coverage-tool",
25
+ project_urls={
26
+ "Bug Tracker": "https://github.com/Nikita-Filonov/ui-coverage-tool/issues",
27
+ },
28
+ classifiers=[
29
+ "Programming Language :: Python :: 3",
30
+ "License :: OSI Approved :: MIT License",
31
+ "Operating System :: OS Independent",
32
+ ],
33
+ python_requires='>=3.11',
34
+ )
File without changes
@@ -0,0 +1,41 @@
1
+ from ui_coverage_tool.config import get_settings
2
+ from ui_coverage_tool.src.coverage.builder import UICoverageBuilder
3
+ from ui_coverage_tool.src.history.builder import UICoverageHistoryBuilder
4
+ from ui_coverage_tool.src.history.storage import UICoverageHistoryStorage
5
+ from ui_coverage_tool.src.reports.models import CoverageReportState
6
+ from ui_coverage_tool.src.reports.storage import UIReportsStorage
7
+ from ui_coverage_tool.src.tools.logger import get_logger
8
+ from ui_coverage_tool.src.tracker.storage import UICoverageTrackerStorage
9
+
10
+ logger = get_logger("SAVE_REPORT")
11
+
12
+
13
+ def save_report_command():
14
+ logger.info("Starting to save the report")
15
+
16
+ settings = get_settings()
17
+
18
+ reports_storage = UIReportsStorage(settings=settings)
19
+ tracker_storage = UICoverageTrackerStorage(settings=settings)
20
+ history_storage = UICoverageHistoryStorage(settings=settings)
21
+
22
+ report_state = CoverageReportState.init(settings)
23
+ history_state = history_storage.load()
24
+ tracker_state = tracker_storage.load()
25
+ for app in settings.apps:
26
+ results_list = tracker_state.filter(app=app.key)
27
+
28
+ coverage_builder = UICoverageBuilder(
29
+ results_list=results_list,
30
+ history_builder=UICoverageHistoryBuilder(
31
+ history=history_state.apps[app.key],
32
+ settings=settings
33
+ )
34
+ )
35
+ report_state.services_coverage[app.key] = coverage_builder.build()
36
+
37
+ history_storage.save_from_report(report_state)
38
+ reports_storage.save_json_report(report_state)
39
+ reports_storage.save_html_report(report_state)
40
+
41
+ logger.info("Report saving process completed")
@@ -0,0 +1,22 @@
1
+ import click
2
+
3
+ from ui_coverage_tool.cli.commands.save_report import save_report_command
4
+
5
+
6
+ @click.command(
7
+ name="save-report",
8
+ help="Generate a coverage report based on collected result files."
9
+ )
10
+ def save_report():
11
+ save_report_command()
12
+
13
+
14
+ @click.group()
15
+ def cli():
16
+ pass
17
+
18
+
19
+ cli.add_command(save_report)
20
+
21
+ if __name__ == '__main__':
22
+ cli()
@@ -0,0 +1,80 @@
1
+ import importlib.metadata
2
+ import importlib.resources
3
+ import os
4
+ from functools import lru_cache
5
+ from pathlib import Path
6
+
7
+ from pydantic import BaseModel, HttpUrl
8
+ from pydantic_settings import (
9
+ BaseSettings,
10
+ SettingsConfigDict,
11
+ YamlConfigSettingsSource,
12
+ JsonConfigSettingsSource,
13
+ PydanticBaseSettingsSource,
14
+ )
15
+
16
+ from ui_coverage_tool.src.tools.types import AppKey, AppName
17
+
18
+
19
+ class AppConfig(BaseModel):
20
+ key: AppKey
21
+ url: HttpUrl
22
+ name: AppName
23
+ tags: list[str] | None = None
24
+ repository: HttpUrl | None = None
25
+
26
+
27
+ class Settings(BaseSettings):
28
+ model_config = SettingsConfigDict(
29
+ extra='allow',
30
+
31
+ env_file=os.path.join(os.getcwd(), ".env"),
32
+ env_prefix="UI_COVERAGE_",
33
+ env_file_encoding="utf-8",
34
+ env_nested_delimiter=".",
35
+
36
+ yaml_file=os.path.join(os.getcwd(), "ui_coverage_config.yaml"),
37
+ yaml_file_encoding="utf-8",
38
+
39
+ json_file=os.path.join(os.getcwd(), "ui_coverage_config.json"),
40
+ json_file_encoding="utf-8"
41
+ )
42
+
43
+ apps: list[AppConfig]
44
+
45
+ results_dir: Path = Path(os.path.join(os.getcwd(), "coverage-results"))
46
+
47
+ history_file: Path | None = Path(os.path.join(os.getcwd(), "coverage-history.json"))
48
+ history_retention_limit: int = 30
49
+
50
+ html_report_file: Path | None = Path(os.path.join(os.getcwd(), "index.html"))
51
+ json_report_file: Path | None = Path(os.path.join(os.getcwd(), "coverage-report.json"))
52
+
53
+ @property
54
+ def html_report_template_file(self):
55
+ try:
56
+ return importlib.resources.files("swagger_coverage_tool.src.reports.templates") / "index.html"
57
+ except importlib.metadata.PackageNotFoundError:
58
+ return Path(os.path.join(os.getcwd(), "swagger_coverage_tool/src/reports/templates/index.html"))
59
+
60
+ @classmethod
61
+ def settings_customise_sources(
62
+ cls,
63
+ settings_cls: type[BaseSettings],
64
+ init_settings: PydanticBaseSettingsSource,
65
+ env_settings: PydanticBaseSettingsSource,
66
+ dotenv_settings: PydanticBaseSettingsSource,
67
+ file_secret_settings: PydanticBaseSettingsSource,
68
+ ) -> tuple[PydanticBaseSettingsSource, ...]:
69
+ return (
70
+ YamlConfigSettingsSource(cls),
71
+ JsonConfigSettingsSource(cls),
72
+ env_settings,
73
+ dotenv_settings,
74
+ init_settings,
75
+ )
76
+
77
+
78
+ @lru_cache(maxsize=None)
79
+ def get_settings() -> Settings:
80
+ return Settings()
@@ -0,0 +1,53 @@
1
+ from ui_coverage_tool.src.coverage.models import AppCoverage, ElementCoverage, ActionCoverage
2
+ from ui_coverage_tool.src.history.builder import UICoverageHistoryBuilder
3
+ from ui_coverage_tool.src.history.models import ActionHistory
4
+ from ui_coverage_tool.src.tools.actions import ActionType
5
+ from ui_coverage_tool.src.tools.selector import SelectorType
6
+ from ui_coverage_tool.src.tools.types import Selector
7
+ from ui_coverage_tool.src.tracker.models import CoverageResultList
8
+
9
+
10
+ class UICoverageBuilder:
11
+ def __init__(self, results_list: CoverageResultList, history_builder: UICoverageHistoryBuilder):
12
+ self.results_list = results_list
13
+ self.history_builder = history_builder
14
+
15
+ def build_element_coverage(
16
+ self,
17
+ results: CoverageResultList,
18
+ selector: Selector,
19
+ selector_type: SelectorType
20
+ ) -> ElementCoverage:
21
+ actions = [
22
+ ActionCoverage(type=action, count=results.count_action(action))
23
+ for action in ActionType.to_list()
24
+ if results.count_action(action) > 0
25
+ ]
26
+
27
+ return ElementCoverage(
28
+ history=self.history_builder.get_element_history(
29
+ actions=[ActionHistory(type=action.type, count=action.count) for action in actions],
30
+ selector=selector,
31
+ selector_type=selector_type
32
+ ),
33
+ actions=actions,
34
+ selector=selector,
35
+ selector_type=selector_type,
36
+ )
37
+
38
+ def build(self) -> AppCoverage:
39
+ return AppCoverage(
40
+ history=self.history_builder.get_total_app_history(
41
+ actions=[
42
+ ActionHistory(type=action, count=results.total_actions)
43
+ for action, results in self.results_list.grouped_by_action.items()
44
+ if results.total_actions > 0
45
+ ],
46
+ total_actions=self.results_list.total_actions,
47
+ total_elements=self.results_list.total_selectors
48
+ ),
49
+ elements=[
50
+ self.build_element_coverage(results, selector, selector_type)
51
+ for (selector, selector_type), results in self.results_list.grouped_by_selector.items()
52
+ ],
53
+ )
@@ -0,0 +1,25 @@
1
+ from pydantic import BaseModel, Field, ConfigDict
2
+
3
+ from ui_coverage_tool.src.history.models import ElementHistory, TotalAppHistory
4
+ from ui_coverage_tool.src.tools.actions import ActionType
5
+ from ui_coverage_tool.src.tools.selector import SelectorType
6
+ from ui_coverage_tool.src.tools.types import Selector
7
+
8
+
9
+ class ActionCoverage(BaseModel):
10
+ type: ActionType
11
+ count: int
12
+
13
+
14
+ class ElementCoverage(BaseModel):
15
+ model_config = ConfigDict(populate_by_name=True)
16
+
17
+ history: list[ElementHistory]
18
+ actions: list[ActionCoverage]
19
+ selector: Selector
20
+ selector_type: SelectorType = Field(alias="selectorType")
21
+
22
+
23
+ class AppCoverage(BaseModel):
24
+ history: list[TotalAppHistory]
25
+ elements: list[ElementCoverage]
@@ -0,0 +1,71 @@
1
+ from dataclasses import dataclass
2
+ from datetime import datetime
3
+ from typing import TypeVar, Callable
4
+
5
+ from ui_coverage_tool.config import Settings
6
+ from ui_coverage_tool.src.history.models import ElementHistory, TotalAppHistory, AppHistory, ActionHistory
7
+ from ui_coverage_tool.src.history.selector import build_selector_key
8
+ from ui_coverage_tool.src.tools.selector import SelectorType
9
+ from ui_coverage_tool.src.tools.types import Selector
10
+
11
+ T = TypeVar('T')
12
+
13
+
14
+ class UICoverageHistoryBuilder:
15
+ def __init__(self, history: AppHistory, settings: Settings):
16
+ self.history = history
17
+ self.settings = settings
18
+ self.created_at = datetime.now()
19
+
20
+ def build_element_history(self, actions: list[ActionHistory]) -> ElementHistory:
21
+ return ElementHistory(created_at=self.created_at, actions=actions)
22
+
23
+ def build_total_app_history(
24
+ self,
25
+ actions: list[ActionHistory],
26
+ total_actions: int,
27
+ total_elements: int
28
+ ) -> TotalAppHistory:
29
+ return TotalAppHistory(
30
+ actions=actions,
31
+ created_at=self.created_at,
32
+ total_actions=total_actions,
33
+ total_elements=total_elements
34
+ )
35
+
36
+ def append_history(self, history: list[T], build_func: Callable[[], T]) -> list[T]:
37
+ if not self.settings.history_file:
38
+ return []
39
+
40
+ new_item = build_func()
41
+ if not new_item.actions:
42
+ return history
43
+
44
+ combined = [*history, new_item]
45
+ combined.sort(key=lambda r: r.created_at)
46
+ return combined[-self.settings.history_retention_limit:]
47
+
48
+ def get_element_history(
49
+ self,
50
+ actions: list[ActionHistory],
51
+ selector: Selector,
52
+ selector_type: SelectorType
53
+ ) -> list[ElementHistory]:
54
+ key = build_selector_key(selector, selector_type)
55
+ history = self.history.elements.get(key, [])
56
+ return self.append_history(history, lambda: self.build_element_history(actions))
57
+
58
+ def get_total_app_history(
59
+ self,
60
+ actions: list[ActionHistory],
61
+ total_actions: int,
62
+ total_elements: int
63
+ ) -> list[TotalAppHistory]:
64
+ return self.append_history(
65
+ self.history.total,
66
+ lambda: self.build_total_app_history(
67
+ actions=actions,
68
+ total_actions=total_actions,
69
+ total_elements=total_elements
70
+ )
71
+ )
@@ -0,0 +1,36 @@
1
+ from datetime import datetime
2
+
3
+ from pydantic import BaseModel, Field, ConfigDict
4
+
5
+ from ui_coverage_tool.src.tools.actions import ActionType
6
+ from ui_coverage_tool.src.tools.types import AppKey
7
+
8
+
9
+ class ActionHistory(BaseModel):
10
+ type: ActionType
11
+ count: int
12
+
13
+
14
+ class ElementHistory(BaseModel):
15
+ model_config = ConfigDict(populate_by_name=True)
16
+
17
+ actions: list[ActionHistory]
18
+ created_at: datetime = Field(alias="createdAt")
19
+
20
+
21
+ class TotalAppHistory(BaseModel):
22
+ model_config = ConfigDict(populate_by_name=True)
23
+
24
+ actions: list[ActionHistory]
25
+ created_at: datetime = Field(alias="createdAt")
26
+ total_actions: int = Field(alias="totalActions")
27
+ total_elements: int = Field(alias="totalElements")
28
+
29
+
30
+ class AppHistory(BaseModel):
31
+ total: list[TotalAppHistory]
32
+ elements: dict[str, list[ElementHistory]]
33
+
34
+
35
+ class CoverageHistoryState(BaseModel):
36
+ apps: dict[AppKey, AppHistory] = Field(default_factory=dict)
@@ -0,0 +1,6 @@
1
+ from ui_coverage_tool.src.tools.selector import SelectorType
2
+ from ui_coverage_tool.src.tools.types import Selector, SelectorKey
3
+
4
+
5
+ def build_selector_key(selector: Selector, selector_type: SelectorType) -> SelectorKey:
6
+ return SelectorKey(f'{selector_type}_{selector}')
@@ -0,0 +1,55 @@
1
+ from ui_coverage_tool.config import Settings
2
+ from ui_coverage_tool.src.history.models import CoverageHistoryState, AppHistory
3
+ from ui_coverage_tool.src.history.selector import build_selector_key
4
+ from ui_coverage_tool.src.reports.models import CoverageReportState
5
+ from ui_coverage_tool.src.tools.logger import get_logger
6
+
7
+ logger = get_logger("UI_COVERAGE_HISTORY_STORAGE")
8
+
9
+
10
+ class UICoverageHistoryStorage:
11
+ def __init__(self, settings: Settings):
12
+ self.settings = settings
13
+
14
+ def load(self):
15
+ history_file = self.settings.history_file
16
+
17
+ if not history_file:
18
+ logger.debug("No history file path provided, returning empty history state")
19
+ return CoverageHistoryState()
20
+
21
+ if not history_file.exists():
22
+ logger.debug("History file not found, returning empty history state")
23
+ return CoverageHistoryState()
24
+
25
+ try:
26
+ logger.info(f"Loading history from file: {history_file}")
27
+ return CoverageHistoryState.model_validate_json(history_file.read_text())
28
+ except Exception as error:
29
+ logger.error(f"Error loading history from file {history_file}: {error}")
30
+ return CoverageHistoryState()
31
+
32
+ def save(self, state: CoverageHistoryState):
33
+ history_file = self.settings.history_file
34
+
35
+ try:
36
+ history_file.touch(exist_ok=True)
37
+ history_file.write_text(state.model_dump_json(by_alias=True))
38
+ logger.info(f"History state saved to file: {history_file}")
39
+ except Exception as error:
40
+ logger.error(f"Error saving history to file {history_file}: {error}")
41
+
42
+ def save_from_report(self, report: CoverageReportState):
43
+ state = CoverageHistoryState(
44
+ apps={
45
+ app.key: AppHistory(
46
+ total=report.apps_coverage[app.key].history,
47
+ elements={
48
+ build_selector_key(element.selector, element.selector_type): element.history
49
+ for element in report.apps_coverage[app.key].elements
50
+ }
51
+ )
52
+ for app in self.settings.apps
53
+ }
54
+ )
55
+ self.save(state)
@@ -0,0 +1,33 @@
1
+ from datetime import datetime
2
+
3
+ from pydantic import BaseModel, Field, ConfigDict, FilePath, HttpUrl
4
+ from swagger_coverage_tool.config import ServiceConfig, Settings
5
+
6
+ from ui_coverage_tool.config import AppConfig
7
+ from ui_coverage_tool.src.coverage.models import AppCoverage
8
+ from ui_coverage_tool.src.tools.types import AppKey
9
+
10
+
11
+ class CoverageReportServiceConfig(ServiceConfig):
12
+ model_config = ConfigDict(populate_by_name=True)
13
+
14
+ swagger_url: HttpUrl | None = Field(alias="swaggerUrl", default=None)
15
+ swagger_file: FilePath | None = Field(alias="swaggerFile", default=None)
16
+
17
+
18
+ class CoverageReportConfig(BaseModel):
19
+ apps: list[AppConfig]
20
+
21
+
22
+ class CoverageReportState(BaseModel):
23
+ model_config = ConfigDict(populate_by_name=True)
24
+
25
+ config: CoverageReportConfig
26
+ created_at: datetime = Field(alias="createdAt", default_factory=datetime.now)
27
+ apps_coverage: dict[AppKey, AppCoverage] = Field(alias="appsCoverage", default_factory=dict)
28
+
29
+ @classmethod
30
+ def init(cls, settings: Settings):
31
+ return CoverageReportState(
32
+ config=CoverageReportConfig(apps=settings.apps)
33
+ )
@@ -0,0 +1,52 @@
1
+ import re
2
+
3
+ from ui_coverage_tool.config import Settings
4
+ from ui_coverage_tool.src.reports.models import CoverageReportState
5
+ from ui_coverage_tool.src.tools.logger import get_logger
6
+
7
+ logger = get_logger("UI_REPORTS_STORAGE")
8
+
9
+
10
+ class UIReportsStorage:
11
+ def __init__(self, settings: Settings):
12
+ self.settings = settings
13
+
14
+ def inject_state_into_html(self, state: CoverageReportState) -> str:
15
+ state_json = state.model_dump_json(by_alias=True)
16
+ html_report_template_file = self.settings.html_report_template_file
17
+
18
+ script_regex = re.compile(
19
+ r'<script id="state" type="application/json">[\s\S]*?</script>',
20
+ re.IGNORECASE
21
+ )
22
+ script_tag = f'<script id="state" type="application/json">{state_json}</script>'
23
+
24
+ return script_regex.sub(script_tag, html_report_template_file.read_text(encoding='utf-8'))
25
+
26
+ def save_json_report(self, state: CoverageReportState):
27
+ json_report_file = self.settings.json_report_file
28
+
29
+ if not json_report_file:
30
+ logger.info("JSON report file is not configured — skipping JSON report generation.")
31
+ return
32
+
33
+ try:
34
+ json_report_file.touch(exist_ok=True)
35
+ json_report_file.write_text(state.model_dump_json(by_alias=True))
36
+ logger.info(f'JSON report saved to {json_report_file}')
37
+ except Exception as error:
38
+ logger.error(f'Failed to write JSON report: {error}')
39
+
40
+ def save_html_report(self, state: CoverageReportState):
41
+ html_report_file = self.settings.html_report_file
42
+
43
+ if not html_report_file:
44
+ logger.info("HTML report file is not configured — skipping HTML report generation.")
45
+ return
46
+
47
+ try:
48
+ html_report_file.touch(exist_ok=True)
49
+ html_report_file.write_text(self.inject_state_into_html(state), encoding='utf-8')
50
+ logger.info(f'HTML report saved to {html_report_file}')
51
+ except Exception as error:
52
+ logger.error(f'Failed to write HTML report: {error}')
@@ -0,0 +1,13 @@
1
+ from enum import Enum
2
+ from typing import Self
3
+
4
+
5
+ class ActionType(str, Enum):
6
+ FILL = "FILL"
7
+ CLICK = "CLICK"
8
+ ASSERT_VISIBLE = "ASSERT_VISIBLE"
9
+ ASSERT_HAVE_TEXT = "ASSERT_HAVE_TEXT"
10
+
11
+ @classmethod
12
+ def to_list(cls) -> list[Self]:
13
+ return list(cls)
@@ -0,0 +1,16 @@
1
+ import logging
2
+
3
+
4
+ def get_logger(name: str) -> logging.Logger:
5
+ logger = logging.getLogger(name)
6
+ logger.setLevel(logging.DEBUG)
7
+
8
+ handler = logging.StreamHandler()
9
+ handler.setLevel(logging.DEBUG)
10
+
11
+ formatter = logging.Formatter('%(asctime)s | %(name)s | %(levelname)s | %(message)s')
12
+ handler.setFormatter(formatter)
13
+
14
+ logger.addHandler(handler)
15
+
16
+ return logger
@@ -0,0 +1,9 @@
1
+ from enum import Enum
2
+
3
+
4
+ class SelectorType(str, Enum):
5
+ CSS = "CSS"
6
+ XPATH = "XPATH"
7
+
8
+ def __str__(self) -> str:
9
+ return str(self.value)
@@ -0,0 +1,7 @@
1
+ from typing import NewType
2
+
3
+ AppKey = NewType('AppKey', str)
4
+ AppName = NewType('AppName', str)
5
+
6
+ Selector = NewType('Selector', str)
7
+ SelectorKey = NewType('SelectorKey', str)
@@ -0,0 +1,30 @@
1
+ from ui_coverage_tool.config import Settings, get_settings
2
+ from ui_coverage_tool.src.tools.logger import get_logger
3
+ from ui_coverage_tool.src.tools.types import Selector, AppKey
4
+ from ui_coverage_tool.src.tracker.models import SelectorType, ActionType, CoverageResult
5
+ from ui_coverage_tool.src.tracker.storage import UICoverageTrackerStorage
6
+
7
+ logger = get_logger("UI_COVERAGE_TRACKER_STORAGE")
8
+
9
+
10
+ class UICoverageTracker:
11
+ def __init__(self, app: AppKey, settings: Settings | None = None):
12
+ self.app = app
13
+ self.settings = settings or get_settings()
14
+
15
+ self.storage = UICoverageTrackerStorage(self.settings)
16
+
17
+ def track_coverage(
18
+ self,
19
+ selector: str,
20
+ action_type: ActionType,
21
+ selector_type: SelectorType,
22
+ ):
23
+ self.storage.save(
24
+ CoverageResult(
25
+ app=self.app,
26
+ selector=Selector(selector),
27
+ action_type=action_type,
28
+ selector_type=selector_type
29
+ )
30
+ )
@@ -0,0 +1,71 @@
1
+ from collections import Counter
2
+ from functools import cached_property
3
+ from itertools import groupby
4
+ from typing import Self
5
+
6
+ from pydantic import BaseModel, RootModel
7
+
8
+ from ui_coverage_tool.src.tools.actions import ActionType
9
+ from ui_coverage_tool.src.tools.selector import SelectorType
10
+ from ui_coverage_tool.src.tools.types import Selector, AppKey
11
+
12
+ SelectorGroupKey = tuple[Selector, SelectorType]
13
+
14
+
15
+ class CoverageResult(BaseModel):
16
+ app: AppKey
17
+ selector: Selector
18
+ action_type: ActionType
19
+ selector_type: SelectorType
20
+
21
+
22
+ class CoverageResultList(RootModel):
23
+ root: list[CoverageResult]
24
+
25
+ def filter(self, app: AppKey | None = None) -> Self:
26
+ results = [
27
+ coverage
28
+ for coverage in self.root
29
+ if (app is None or coverage.app.lower() == app.lower())
30
+ ]
31
+ return CoverageResultList(root=results)
32
+
33
+ @cached_property
34
+ def grouped_by_action(self) -> dict[ActionType, Self]:
35
+ results = sorted(self.root, key=lambda r: r.action_type)
36
+ return {
37
+ grouper: CoverageResultList(root=results)
38
+ for grouper, results in groupby(results, key=lambda r: r.action_type)
39
+ }
40
+
41
+ @cached_property
42
+ def grouped_by_selector(self) -> dict[SelectorGroupKey, Self]:
43
+ results = sorted(self.root, key=lambda r: (r.selector, r.selector_type))
44
+ return {
45
+ grouper: CoverageResultList(root=results)
46
+ for grouper, results in groupby(results, key=lambda r: (r.selector, r.selector_type))
47
+ }
48
+
49
+ @property
50
+ def total_actions(self) -> int:
51
+ return len(self.root)
52
+
53
+ @property
54
+ def total_selectors(self) -> int:
55
+ return len(self.grouped_by_selector)
56
+
57
+ def count_action(self, action_type: ActionType) -> int:
58
+ counter = Counter(r.action_type for r in self.root)
59
+ return counter.get(action_type, 0)
60
+
61
+
62
+ r = CoverageResultList(
63
+ root=[
64
+ CoverageResult(selector="#user", selector_type=SelectorType.CSS, action_type=ActionType.FILL),
65
+ CoverageResult(selector="#user", selector_type=SelectorType.XPATH, action_type=ActionType.FILL),
66
+ CoverageResult(selector="#user", selector_type=SelectorType.CSS, action_type=ActionType.FILL),
67
+ CoverageResult(selector="#user", selector_type=SelectorType.XPATH, action_type=ActionType.CLICK),
68
+ CoverageResult(selector="#user", selector_type=SelectorType.CSS, action_type=ActionType.FILL)
69
+ ]
70
+ )
71
+ print(r.grouped_by_action)
@@ -0,0 +1,42 @@
1
+ import uuid
2
+
3
+ from ui_coverage_tool.config import Settings
4
+ from ui_coverage_tool.src.tools.logger import get_logger
5
+ from ui_coverage_tool.src.tracker.models import CoverageResult, CoverageResultList
6
+
7
+ logger = get_logger("UI_COVERAGE_TRACKER_STORAGE")
8
+
9
+
10
+ class UICoverageTrackerStorage:
11
+ def __init__(self, settings: Settings):
12
+ self.settings = settings
13
+
14
+ def load(self) -> CoverageResultList:
15
+ results_dir = self.settings.results_dir
16
+ logger.info(f"Loading coverage results from directory: {results_dir}")
17
+
18
+ if not results_dir.exists():
19
+ logger.warning(f"Results directory does not exist: {results_dir}")
20
+ return CoverageResultList(root=[])
21
+
22
+ results = [
23
+ CoverageResultList.model_validate_json(file.read_text())
24
+ for file in results_dir.glob("*.json") if file.is_file()
25
+ ]
26
+
27
+ logger.info(f"Loaded {len(results)} coverage files from directory: {results_dir}")
28
+ return CoverageResultList(root=results)
29
+
30
+ def save(self, coverage: CoverageResult):
31
+ results_dir = self.settings.results_dir
32
+
33
+ if not results_dir.exists():
34
+ logger.info(f"Results directory does not exist, creating: {results_dir}")
35
+ results_dir.mkdir(exist_ok=True)
36
+
37
+ result_file = results_dir.joinpath(f'{uuid.uuid4()}.json')
38
+
39
+ try:
40
+ result_file.write_text(coverage.model_dump_json())
41
+ except Exception as error:
42
+ logger.error(f"Error saving coverage data to file {result_file}: {error}")
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.4
2
+ Name: ui-coverage-tool
3
+ Version: 0.1.0
4
+ Summary: TODO
5
+ Home-page: https://github.com/Nikita-Filonov/ui-coverage-tool
6
+ Author: Nikita Filonov
7
+ Author-email: filonov.nikitkaa@gmail.com
8
+ Project-URL: Bug Tracker, https://github.com/Nikita-Filonov/ui-coverage-tool/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: click
16
+ Requires-Dist: pyyaml>=6.0.2
17
+ Requires-Dist: pydantic>=2.0.0
18
+ Requires-Dist: pydantic-settings>=2.8.0
19
+ Dynamic: author
20
+ Dynamic: author-email
21
+ Dynamic: classifier
22
+ Dynamic: description
23
+ Dynamic: description-content-type
24
+ Dynamic: home-page
25
+ Dynamic: license-file
26
+ Dynamic: project-url
27
+ Dynamic: requires-dist
28
+ Dynamic: requires-python
29
+ Dynamic: summary
30
+
31
+ TODO
@@ -0,0 +1,37 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.py
5
+ ui_coverage_tool/__init__.py
6
+ ui_coverage_tool/config.py
7
+ ui_coverage_tool.egg-info/PKG-INFO
8
+ ui_coverage_tool.egg-info/SOURCES.txt
9
+ ui_coverage_tool.egg-info/dependency_links.txt
10
+ ui_coverage_tool.egg-info/entry_points.txt
11
+ ui_coverage_tool.egg-info/requires.txt
12
+ ui_coverage_tool.egg-info/top_level.txt
13
+ ui_coverage_tool/cli/__init__.py
14
+ ui_coverage_tool/cli/main.py
15
+ ui_coverage_tool/cli/commands/__init__.py
16
+ ui_coverage_tool/cli/commands/save_report.py
17
+ ui_coverage_tool/src/__init__.py
18
+ ui_coverage_tool/src/coverage/__init__.py
19
+ ui_coverage_tool/src/coverage/builder.py
20
+ ui_coverage_tool/src/coverage/models.py
21
+ ui_coverage_tool/src/history/__init__.py
22
+ ui_coverage_tool/src/history/builder.py
23
+ ui_coverage_tool/src/history/models.py
24
+ ui_coverage_tool/src/history/selector.py
25
+ ui_coverage_tool/src/history/storage.py
26
+ ui_coverage_tool/src/reports/__init__.py
27
+ ui_coverage_tool/src/reports/models.py
28
+ ui_coverage_tool/src/reports/storage.py
29
+ ui_coverage_tool/src/tools/__init__.py
30
+ ui_coverage_tool/src/tools/actions.py
31
+ ui_coverage_tool/src/tools/logger.py
32
+ ui_coverage_tool/src/tools/selector.py
33
+ ui_coverage_tool/src/tools/types.py
34
+ ui_coverage_tool/src/tracker/__init__.py
35
+ ui_coverage_tool/src/tracker/core.py
36
+ ui_coverage_tool/src/tracker/models.py
37
+ ui_coverage_tool/src/tracker/storage.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ui-coverage-tool = ui_coverage_tool.cli.main:cli
@@ -0,0 +1,4 @@
1
+ click
2
+ pyyaml>=6.0.2
3
+ pydantic>=2.0.0
4
+ pydantic-settings>=2.8.0
@@ -0,0 +1 @@
1
+ ui_coverage_tool