approval-utilities 16.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.
Files changed (72) hide show
  1. approval_utilities-16.0.0/LICENSE +191 -0
  2. approval_utilities-16.0.0/MANIFEST.in +2 -0
  3. approval_utilities-16.0.0/PKG-INFO +30 -0
  4. approval_utilities-16.0.0/README.md +325 -0
  5. approval_utilities-16.0.0/approval_utilities/__init__.py +0 -0
  6. approval_utilities-16.0.0/approval_utilities/approvaltests/__init__.py +0 -0
  7. approval_utilities-16.0.0/approval_utilities/approvaltests/core/__init__.py +0 -0
  8. approval_utilities-16.0.0/approval_utilities/approvaltests/core/executable_command.py +17 -0
  9. approval_utilities-16.0.0/approval_utilities/approvaltests/core/verifiable.py +10 -0
  10. approval_utilities-16.0.0/approval_utilities/approvaltests/core/verify_parameters.py +9 -0
  11. approval_utilities-16.0.0/approval_utilities/list_utils.py +20 -0
  12. approval_utilities-16.0.0/approval_utilities/py.typed +0 -0
  13. approval_utilities-16.0.0/approval_utilities/utilities/__init__.py +0 -0
  14. approval_utilities-16.0.0/approval_utilities/utilities/clipboard_utilities.py +7 -0
  15. approval_utilities-16.0.0/approval_utilities/utilities/deprecated.py +25 -0
  16. approval_utilities-16.0.0/approval_utilities/utilities/exceptions/__init__.py +0 -0
  17. approval_utilities-16.0.0/approval_utilities/utilities/exceptions/exception_collector.py +40 -0
  18. approval_utilities-16.0.0/approval_utilities/utilities/exceptions/exception_utils.py +2 -0
  19. approval_utilities-16.0.0/approval_utilities/utilities/exceptions/multiple_exceptions.py +9 -0
  20. approval_utilities-16.0.0/approval_utilities/utilities/logger/__init__.py +0 -0
  21. approval_utilities-16.0.0/approval_utilities/utilities/logger/logging_instance.py +250 -0
  22. approval_utilities-16.0.0/approval_utilities/utilities/logger/simple_logger.py +89 -0
  23. approval_utilities-16.0.0/approval_utilities/utilities/map_reduce.py +17 -0
  24. approval_utilities-16.0.0/approval_utilities/utilities/markdown_table.py +53 -0
  25. approval_utilities-16.0.0/approval_utilities/utilities/multiline_string_utils.py +11 -0
  26. approval_utilities-16.0.0/approval_utilities/utilities/os_utilities.py +7 -0
  27. approval_utilities-16.0.0/approval_utilities/utilities/persistence/__init__.py +0 -0
  28. approval_utilities-16.0.0/approval_utilities/utilities/persistence/loader.py +10 -0
  29. approval_utilities-16.0.0/approval_utilities/utilities/persistence/saver.py +10 -0
  30. approval_utilities-16.0.0/approval_utilities/utilities/stack_frame_utilities.py +10 -0
  31. approval_utilities-16.0.0/approval_utilities/utilities/string_wrapper.py +17 -0
  32. approval_utilities-16.0.0/approval_utilities/utilities/time_utilities.py +28 -0
  33. approval_utilities-16.0.0/approval_utilities/utilities/wrapper.py +34 -0
  34. approval_utilities-16.0.0/approval_utilities/utils.py +102 -0
  35. approval_utilities-16.0.0/approval_utilities.egg-info/PKG-INFO +30 -0
  36. approval_utilities-16.0.0/approval_utilities.egg-info/SOURCES.txt +70 -0
  37. approval_utilities-16.0.0/approval_utilities.egg-info/dependency_links.txt +1 -0
  38. approval_utilities-16.0.0/approval_utilities.egg-info/top_level.txt +1 -0
  39. approval_utilities-16.0.0/requirements.prod.extras.txt +5 -0
  40. approval_utilities-16.0.0/requirements.prod.required.txt +5 -0
  41. approval_utilities-16.0.0/requirements.prod.txt +2 -0
  42. approval_utilities-16.0.0/setup/setup_utils.py +70 -0
  43. approval_utilities-16.0.0/setup.cfg +4 -0
  44. approval_utilities-16.0.0/tests/test_ai_fixer_loop.py +41 -0
  45. approval_utilities-16.0.0/tests/test_approvaltests_temp_dir.py +8 -0
  46. approval_utilities-16.0.0/tests/test_asserts.py +68 -0
  47. approval_utilities-16.0.0/tests/test_build.py +33 -0
  48. approval_utilities-16.0.0/tests/test_combinations.py +175 -0
  49. approval_utilities-16.0.0/tests/test_compare_file_lists.py +30 -0
  50. approval_utilities-16.0.0/tests/test_custom_printers.py +41 -0
  51. approval_utilities-16.0.0/tests/test_emoji_handling.py +11 -0
  52. approval_utilities-16.0.0/tests/test_example_numpy.py +60 -0
  53. approval_utilities-16.0.0/tests/test_exception_utils.py +22 -0
  54. approval_utilities-16.0.0/tests/test_fileapprover.py +114 -0
  55. approval_utilities-16.0.0/tests/test_find_stale_approved_files.py +137 -0
  56. approval_utilities-16.0.0/tests/test_inline_approvals.py +308 -0
  57. approval_utilities-16.0.0/tests/test_list.py +38 -0
  58. approval_utilities-16.0.0/tests/test_multiline_string_utils.py +35 -0
  59. approval_utilities-16.0.0/tests/test_namer.py +70 -0
  60. approval_utilities-16.0.0/tests/test_options.py +118 -0
  61. approval_utilities-16.0.0/tests/test_pairwise_combinations.py +108 -0
  62. approval_utilities-16.0.0/tests/test_parse_inputs.py +147 -0
  63. approval_utilities-16.0.0/tests/test_python_patterns.py +20 -0
  64. approval_utilities-16.0.0/tests/test_scenarios.py +73 -0
  65. approval_utilities-16.0.0/tests/test_simple_logger.py +264 -0
  66. approval_utilities-16.0.0/tests/test_split_code.py +67 -0
  67. approval_utilities-16.0.0/tests/test_verify.py +339 -0
  68. approval_utilities-16.0.0/tests/test_verify_all.py +10 -0
  69. approval_utilities-16.0.0/tests/test_verify_argument_parser.py +14 -0
  70. approval_utilities-16.0.0/tests/test_workflow_matrix.py +40 -0
  71. approval_utilities-16.0.0/tests/test_writer.py +31 -0
  72. approval_utilities-16.0.0/version.py +1 -0
@@ -0,0 +1,191 @@
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, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+ owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities
16
+ that control, are controlled by, or are under common control with that entity.
17
+ For the purposes of this definition, "control" means (i) the power, direct or
18
+ indirect, to cause the direction or management of such entity, whether by
19
+ contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+ outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
23
+ permissions granted by this License.
24
+
25
+ "Source" form shall mean the preferred form for making modifications, including
26
+ but not limited to software source code, documentation source, and configuration
27
+ files.
28
+
29
+ "Object" form shall mean any form resulting from mechanical transformation or
30
+ translation of a Source form, including but not limited to compiled object code,
31
+ generated documentation, and conversions to other media types.
32
+
33
+ "Work" shall mean the work of authorship, whether in Source or Object form, made
34
+ available under the License, as indicated by a copyright notice that is included
35
+ in or attached to the work (an example is provided in the Appendix below).
36
+
37
+ "Derivative Works" shall mean any work, whether in Source or Object form, that
38
+ is based on (or derived from) the Work and for which the editorial revisions,
39
+ annotations, elaborations, or other modifications represent, as a whole, an
40
+ original work of authorship. For the purposes of this License, Derivative Works
41
+ shall not include works that remain separable from, or merely link (or bind by
42
+ name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+ "Contribution" shall mean any work of authorship, including the original version
45
+ of the Work and any modifications or additions to that Work or Derivative Works
46
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+ by the copyright owner or by an individual or Legal Entity authorized to submit
48
+ on behalf of the copyright owner. For the purposes of this definition,
49
+ "submitted" means any form of electronic, verbal, or written communication sent
50
+ to the Licensor or its representatives, including but not limited to
51
+ communication on electronic mailing lists, source code control systems, and
52
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+ the purpose of discussing and improving the Work, but excluding communication
54
+ that is conspicuously marked or otherwise designated in writing by the copyright
55
+ owner as "Not a Contribution."
56
+
57
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+ of whom a Contribution has been received by Licensor and subsequently
59
+ incorporated within the Work.
60
+
61
+ 2. Grant of Copyright License.
62
+
63
+ Subject to the terms and conditions of this License, each Contributor hereby
64
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+ publicly display, publicly perform, sublicense, and distribute the Work and such
67
+ Derivative Works in Source or Object form.
68
+
69
+ 3. Grant of Patent License.
70
+
71
+ Subject to the terms and conditions of this License, each Contributor hereby
72
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+ irrevocable (except as stated in this section) patent license to make, have
74
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+ such license applies only to those patent claims licensable by such Contributor
76
+ that are necessarily infringed by their Contribution(s) alone or by combination
77
+ of their Contribution(s) with the Work to which such Contribution(s) was
78
+ submitted. If You institute patent litigation against any entity (including a
79
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+ Contribution incorporated within the Work constitutes direct or contributory
81
+ patent infringement, then any patent licenses granted to You under this License
82
+ for that Work shall terminate as of the date such litigation is filed.
83
+
84
+ 4. Redistribution.
85
+
86
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+ in any medium, with or without modifications, and in Source or Object form,
88
+ provided that You meet the following conditions:
89
+
90
+ You must give any other recipients of the Work or Derivative Works a copy of
91
+ this License; and
92
+ You must cause any modified files to carry prominent notices stating that You
93
+ changed the files; and
94
+ You must retain, in the Source form of any Derivative Works that You distribute,
95
+ all copyright, patent, trademark, and attribution notices from the Source form
96
+ of the Work, excluding those notices that do not pertain to any part of the
97
+ Derivative Works; and
98
+ If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+ Derivative Works that You distribute must include a readable copy of the
100
+ attribution notices contained within such NOTICE file, excluding those notices
101
+ that do not pertain to any part of the Derivative Works, in at least one of the
102
+ following places: within a NOTICE text file distributed as part of the
103
+ Derivative Works; within the Source form or documentation, if provided along
104
+ with the Derivative Works; or, within a display generated by the Derivative
105
+ Works, if and wherever such third-party notices normally appear. The contents of
106
+ the NOTICE file are for informational purposes only and do not modify the
107
+ License. You may add Your own attribution notices within Derivative Works that
108
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+ provided that such additional attribution notices cannot be construed as
110
+ modifying the License.
111
+ You may add Your own copyright statement to Your modifications and may provide
112
+ additional or different license terms and conditions for use, reproduction, or
113
+ distribution of Your modifications, or for any such Derivative Works as a whole,
114
+ provided Your use, reproduction, and distribution of the Work otherwise complies
115
+ with the conditions stated in this License.
116
+
117
+ 5. Submission of Contributions.
118
+
119
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+ for inclusion in the Work by You to the Licensor shall be under the terms and
121
+ conditions of this License, without any additional terms or conditions.
122
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+ any separate license agreement you may have executed with Licensor regarding
124
+ such Contributions.
125
+
126
+ 6. Trademarks.
127
+
128
+ This License does not grant permission to use the trade names, trademarks,
129
+ service marks, or product names of the Licensor, except as required for
130
+ reasonable and customary use in describing the origin of the Work and
131
+ reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty.
134
+
135
+ Unless required by applicable law or agreed to in writing, Licensor provides the
136
+ Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+ including, without limitation, any warranties or conditions of TITLE,
139
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+ solely responsible for determining the appropriateness of using or
141
+ redistributing the Work and assume any risks associated with Your exercise of
142
+ permissions under this License.
143
+
144
+ 8. Limitation of Liability.
145
+
146
+ In no event and under no legal theory, whether in tort (including negligence),
147
+ contract, or otherwise, unless required by applicable law (such as deliberate
148
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+ liable to You for damages, including any direct, indirect, special, incidental,
150
+ or consequential damages of any character arising as a result of this License or
151
+ out of the use or inability to use the Work (including but not limited to
152
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+ any and all other commercial damages or losses), even if such Contributor has
154
+ been advised of the possibility of such damages.
155
+
156
+ 9. Accepting Warranty or Additional Liability.
157
+
158
+ While redistributing the Work or Derivative Works thereof, You may choose to
159
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+ other liability obligations and/or rights consistent with this License. However,
161
+ in accepting such obligations, You may act only on Your own behalf and on Your
162
+ sole responsibility, not on behalf of any other Contributor, and only if You
163
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+ incurred by, or claims asserted against, such Contributor by reason of your
165
+ accepting any such warranty or additional liability.
166
+
167
+ END OF TERMS AND CONDITIONS
168
+
169
+ APPENDIX: How to apply the Apache License to your work
170
+
171
+ To apply the Apache License to your work, attach the following boilerplate
172
+ notice, with the fields enclosed by brackets "[]" replaced with your own
173
+ identifying information. (Don't include the brackets!) The text should be
174
+ enclosed in the appropriate comment syntax for the file format. We also
175
+ recommend that a file or class name and description of purpose be included on
176
+ the same "printed page" as the copyright notice for easier identification within
177
+ third-party archives.
178
+
179
+ Copyright [yyyy] [name of copyright owner]
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ include requirements.prod.txt requirements.prod.extras.txt requirements.prod.required.txt setup/setup_utils.py version.py
2
+
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: approval_utilities
3
+ Version: 16.0.0
4
+ Summary: Utilities for your production code that work well with approvaltests
5
+ Home-page: https://github.com/approvals/ApprovalTests.Python
6
+ Author: ApprovalTests Contributors
7
+ Author-email: llewellyn.falco@gmail.com
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: POSIX
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: MacOS :: MacOS X
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Classifier: Topic :: Utilities
22
+ Requires-Python: >=3.8
23
+ License-File: LICENSE
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: home-page
28
+ Dynamic: license-file
29
+ Dynamic: requires-python
30
+ Dynamic: summary
@@ -0,0 +1,325 @@
1
+ # ApprovalTests.Python
2
+
3
+ <!-- toc -->
4
+ ## Contents
5
+
6
+ * [What can I use ApprovalTests for?](#what-can-i-use-approvaltests-for)
7
+ * [Getting Started](#getting-started)
8
+ * [What Are Approvals](#what-are-approvals)
9
+ * [New Projects](#new-projects)
10
+ * [Minimal Example Tutorial](#minimal-example-tutorial)
11
+ * [Adding to Existing Projects](#adding-to-existing-projects)
12
+ * [Overview](#overview)
13
+ * [Example using pytest](#example-using-pytest)
14
+ * [Example using unittest](#example-using-unittest)
15
+ * [Example using CLI](#example-using-cli)
16
+ * [Usage](#usage)
17
+ * [Argument Definitions](#argument-definitions)
18
+ * [Reporters](#reporters)
19
+ * [Selecting a Reporter](#selecting-a-reporter)
20
+ * [JSON file for collection of reporters](#json-file-for-collection-of-reporters)
21
+ * [Support and Documentation](#support-and-documentation)
22
+ * [Missing Documentation?](#missing-documentation)
23
+ * [Dependencies](#dependencies)
24
+ * [Required dependencies](#required-dependencies)
25
+ * [Extra dependencies](#extra-dependencies)
26
+ * [For developers](#for-developers)
27
+ * [Weekly Ensemble](#weekly-ensemble)
28
+ * [Pull Requests](#pull-requests)<!-- endToc -->
29
+
30
+ Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid testing.
31
+ `approvaltests` is the ApprovalTests port for Python.
32
+
33
+ For more information see: [www.approvaltests.com](http://approvaltests.com/).
34
+
35
+ [![PyPI version](https://img.shields.io/pypi/v/approvaltests.svg)](https://pypi.org/project/approvaltests)
36
+ [![Python versions](https://img.shields.io/pypi/pyversions/approvaltests.svg)](https://pypi.org/project/approvaltests)
37
+ [![Build Status](https://github.com/approvals/ApprovalTests.Python/workflows/Test/badge.svg?branch=master)](https://github.com/approvals/ApprovalTests.Python/actions)
38
+ [![Build Status](https://github.com/approvals/ApprovalTests.Python/workflows/on-push-do-doco/badge.svg)](https://github.com/approvals/ApprovalTests.Python/actions?query=workflow%3Aon-push-do-doco)
39
+ [![Build Status](https://github.com/approvals/ApprovalTests.Python/workflows/Upload%20Python%20Package/badge.svg)](https://github.com/approvals/ApprovalTests.Python/actions?query=workflow%3A%22Upload+Python+Package%22)
40
+ [![Discord](https://img.shields.io/discord/1349240939406819409?logo=discord)](https://discord.gg/XDrgy6x6Se)
41
+
42
+ ## What can I use ApprovalTests for?
43
+
44
+ You can use ApprovalTests to verify objects that require more than a simple assert including long strings, large arrays,
45
+ and complex hash structures and objects. ApprovalTests really shines when you need a more granular look at the test
46
+ failure. Sometimes, trying to find a small difference in a long string printed to STDOUT is just too hard!
47
+ ApprovalTests solves this problem by providing reporters which let you view the test results in one of many popular diff
48
+ utilities.
49
+
50
+ ## Getting Started
51
+
52
+ ### What Are Approvals
53
+
54
+ If you need to gain a better understanding or are new to this concept, start [here](https://github.com/approvals/ApprovalTests.Documentation/blob/main/explanations/what_are_approvals.md).
55
+
56
+ ### New Projects
57
+
58
+ If you are starting a new project, we suggest you use the [Starter Project](https://github.com/approvals/ApprovalTests.Python.StarterProject).
59
+ You can just clone this and go. It's great for exercises, katas, and green field projects.
60
+
61
+ #### Minimal Example Tutorial
62
+
63
+ If this is first time approvaltesting in python, consider starting here: [Minimal Example Tutorial](docs/tutorial/minimal-example.md)
64
+
65
+ ### Adding to Existing Projects
66
+
67
+ From [pypi](https://pypi.org/project/approvaltests/):
68
+
69
+ pip install approvaltests
70
+
71
+ ## Overview
72
+
73
+ Approvals work by comparing the test results to a golden master. If no golden master exists you can create a snapshot
74
+ of the current test results and use that as the golden master. The reporter helps you manage the golden master.
75
+ Whenever your current results differ from the golden master, Approvals will launch an external application for you to
76
+ examine the differences. Either you will update the master because you expected the changes and they are good,
77
+ or you will go back to your code and update or roll back your changes to get your results back in line with the
78
+ golden master.
79
+
80
+ ### Example using pytest
81
+
82
+ <!-- snippet: getting_started_with_pytest.py -->
83
+ <a id='snippet-getting_started_with_pytest.py'></a>
84
+ ```py
85
+ from approvaltests.approvals import verify
86
+
87
+
88
+ def test_simple() -> None:
89
+ result = "Hello ApprovalTests"
90
+ verify(result)
91
+ ```
92
+ <sup><a href='/tests/examples/getting_started_with_pytest.py#L1-L6' title='Snippet source file'>snippet source</a> | <a href='#snippet-getting_started_with_pytest.py' title='Start of snippet'>anchor</a></sup>
93
+ <!-- endSnippet -->
94
+
95
+ Install the plugin pytest-approvaltests and use it to select a reporter:
96
+
97
+ pip install pytest-approvaltests
98
+ pytest --approvaltests-use-reporter='PythonNative'
99
+
100
+ The reporter is used both to alert you to changes in your test output, and to provide a tool to update the golden
101
+ master. In this snippet, we chose the 'PythonNative' reporter when we ran the tests. For more information about selecting
102
+ reporters see [the documentation](https://github.com/approvals/ApprovalTests.Python.PytestPlugin)
103
+
104
+ ### Example using unittest
105
+
106
+ <!-- snippet: getting_started_with_unittest.py -->
107
+ <a id='snippet-getting_started_with_unittest.py'></a>
108
+ ```py
109
+ import unittest
110
+
111
+ from approvaltests.approvals import verify
112
+
113
+
114
+ class GettingStartedTest(unittest.TestCase):
115
+ def test_simple(self) -> None:
116
+ verify("Hello ApprovalTests")
117
+
118
+
119
+ if __name__ == "__main__":
120
+ unittest.main()
121
+ ```
122
+ <sup><a href='/tests/examples/getting_started_with_unittest.py#L1-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-getting_started_with_unittest.py' title='Start of snippet'>anchor</a></sup>
123
+ <!-- endSnippet -->
124
+
125
+ This example has the same behaviour as the pytest version, but uses the built-in test framework `unittest` instead.
126
+
127
+ ### Example using CLI
128
+
129
+ You can invoke a verify() call from the command line. This allows invoking python approvals from any other stack via subprocesses.
130
+
131
+ #### Usage
132
+
133
+ ```
134
+ python -m approvaltests --test-id hello --received "hello world!"
135
+ ```
136
+
137
+ or
138
+
139
+ ```
140
+ python -m approvaltests -t hello -r "hello world!"
141
+ ```
142
+
143
+ or
144
+
145
+ ```
146
+ echo "hello world!" | python -m approvaltests -t hello
147
+ ```
148
+
149
+ #### Argument Definitions
150
+
151
+ - **`--test-id`** or **`-t`**: Test identifier used to name the `approved.txt` and `received.txt` files for the test.
152
+
153
+ - **`--received`** or **`-r`**: The output of the program under test (a string) that is passed to the verify method.
154
+
155
+ - **`stdin`**: Instead of providing a `received` argument, you may use `stdin`.
156
+
157
+ ## Reporters
158
+
159
+ ### Selecting a Reporter
160
+
161
+ All verify functions take an optional `options` parameter that can configure reporters (as well as many other aspects).
162
+
163
+ ApprovalTests.Python comes with a few reporters configured, supporting Linux, Mac OSX, and Windows.
164
+
165
+ In the example shown below, we pass in an options with a reporter we're selecting directly:
166
+
167
+ <!-- snippet: select_reporter_from_class -->
168
+ <a id='snippet-select_reporter_from_class'></a>
169
+ ```py
170
+ class TestSelectReporterFromClass(unittest.TestCase):
171
+ def test_simple(self):
172
+ verify("Hello", options=Options().with_reporter(report_with_beyond_compare()))
173
+ ```
174
+ <sup><a href='/tests/samples/test_getting_started.py#L28-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-select_reporter_from_class' title='Start of snippet'>anchor</a></sup>
175
+ <!-- endSnippet -->
176
+
177
+ You can also use the `GenericDiffReporterFactory` to find and select the first diff utility that exists on our system.
178
+
179
+ An advantage of this method is you can modify the reporters.json file directly to handle your unique system.
180
+
181
+ <!-- snippet: select_reporter_from_factory -->
182
+ <a id='snippet-select_reporter_from_factory'></a>
183
+ ```py
184
+ class TestSelectReporter(unittest.TestCase):
185
+ @override
186
+ def setUp(self):
187
+ self.factory = GenericDiffReporterFactory()
188
+
189
+ def test_simple(self):
190
+ verify(
191
+ "Hello", options=Options().with_reporter(self.factory.get("BeyondCompare"))
192
+ )
193
+ ```
194
+ <sup><a href='/tests/samples/test_getting_started.py#L13-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-select_reporter_from_factory' title='Start of snippet'>anchor</a></sup>
195
+ <!-- endSnippet -->
196
+
197
+ Or you can build your own GenericDiffReporter on the fly
198
+
199
+ <!-- snippet: custom_generic_diff_reporter -->
200
+ <a id='snippet-custom_generic_diff_reporter'></a>
201
+ ```py
202
+ class GettingStartedTest(unittest.TestCase):
203
+ def test_simple(self):
204
+ verify(
205
+ "Hello",
206
+ options=Options().with_reporter(
207
+ GenericDiffReporter.create(r"C:\my\favorite\diff\utility.exe")
208
+ ),
209
+ )
210
+ ```
211
+ <sup><a href='/tests/samples/test_getting_started.py#L37-L48' title='Snippet source file'>snippet source</a> | <a href='#snippet-custom_generic_diff_reporter' title='Start of snippet'>anchor</a></sup>
212
+ <!-- endSnippet -->
213
+
214
+ As long as `C:/my/favorite/diff/utility.exe` can be invoked from the command line using the format `utility.exe file1 file2`
215
+ then it will be compatible with GenericDiffReporter. Otherwise you will have to derive your own reporter, which
216
+ we won't cover here.
217
+
218
+ ### JSON file for collection of reporters
219
+
220
+ To wrap things up, I should note that you can completely replace the collection of reporters known to the reporter
221
+ factory by writing your own JSON file and loading it.
222
+
223
+ For example if you had `C:/myreporters.json`
224
+
225
+ ```json
226
+ [
227
+ ["BeyondCompare4", "C:/Program Files (x86)/Beyond Compare 4/BCompare.exe"],
228
+ ["WinMerge", "C:/Program Files (x86)/WinMerge/WinMergeU.exe"],
229
+ ["Tortoise", "C:/Program Files (x86)/TortoiseSVN/bin/tortoisemerge.exe"]
230
+ ]
231
+ ```
232
+
233
+ You could then use that file by loading it into the factory:
234
+
235
+ ```python
236
+
237
+ import unittest
238
+
239
+ from approvaltests.approvals import verify
240
+ from approvaltests.reporters.generic_diff_reporter_factory import GenericDiffReporterFactory
241
+
242
+
243
+ class GettingStartedTest(unittest.TestCase):
244
+ def setUp(self):
245
+ factory = GenericDiffReporterFactory()
246
+ factory.load('C:/myreporters.json')
247
+ self.reporter = factory.get_first_working()
248
+
249
+ def test_simple(self):
250
+ verify('Hello', self.reporter)
251
+
252
+ if __name__ == "__main__":
253
+ unittest.main()
254
+ ```
255
+
256
+ Of course, if you have some interesting new reporters in `myreporters.json` then please consider updating the
257
+ `reporters.json` file that ships with Approvals and submitting a pull request.
258
+
259
+ ## Support and Documentation
260
+
261
+ - [Documentation](/docs/README.md)
262
+
263
+ - GitHub: [https://github.com/approvals/ApprovalTests.Python](https://github.com/approvals/ApprovalTests.Python)
264
+
265
+ - ApprovalTests Homepage: [http://www.approvaltests.com](http://www.approvaltests.com)
266
+
267
+ ### Missing Documentation?
268
+
269
+ If there is documentation you wish existed, please add a `page request` to [this issue](https://github.com/approvals/ApprovalTests.Python/issues/135).
270
+
271
+ ### Dependencies
272
+
273
+ ApprovalTests is tested on the following Python versions: 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14.<!-- singleLineInclude: tests/approved_files/test_workflow_matrix.test_workflow_matrix_python_versions.approved.txt -->
274
+
275
+ ApprovalTests requires the following dependencies:
276
+
277
+ #### Required dependencies
278
+
279
+ These dependencies are always required for approvaltests
280
+
281
+ <!-- snippet: requirements.prod.required.txt -->
282
+ <a id='snippet-requirements.prod.required.txt'></a>
283
+ ```txt
284
+ pytest>=4.0.0
285
+ empty-files>=0.0.3
286
+ typing_extensions>=3.6.2
287
+ ```
288
+ <sup><a href='/requirements.prod.required.txt#L1-L5' title='Snippet source file'>snippet source</a> | <a href='#snippet-requirements.prod.required.txt' title='Start of snippet'>anchor</a></sup>
289
+ <!-- endSnippet -->
290
+
291
+ #### Extra dependencies
292
+
293
+ These dependencies are required if you are going to use the related functionality.
294
+ If you want the bare minimum you can use the pypi project
295
+ [approvaltests-minimal](https://pypi.org/project/approvaltests-minimal/).
296
+
297
+ <!-- snippet: requirements.prod.extras.txt -->
298
+ <a id='snippet-requirements.prod.extras.txt'></a>
299
+ ```txt
300
+ pyperclip>=1.5.29 # For Clipboard Reporter
301
+ beautifulsoup4>=4.4.0 # For verify_html
302
+ allpairspy>=2.1.0 # For PairwiseCombinations
303
+ testfixtures >= 7.1.0 # For verify_logging
304
+ mock >= 5.1.0 # For verify_logging
305
+ ```
306
+ <sup><a href='/requirements.prod.extras.txt#L1-L5' title='Snippet source file'>snippet source</a> | <a href='#snippet-requirements.prod.extras.txt' title='Start of snippet'>anchor</a></sup>
307
+ <!-- endSnippet -->
308
+
309
+ ## For developers
310
+
311
+ ### Weekly Ensemble
312
+
313
+ The best way to contribute is to [join our weekly mob/ensemble](./docs/Contribute.md).
314
+
315
+ ### Pull Requests
316
+
317
+ Pull requests are welcomed, particularly those accompanied by automated tests.
318
+
319
+ To run the self-tests:
320
+ `./build_and_test.sh`
321
+
322
+ This will run the self-tests on several python versions. We support python 3.8 and above.
323
+
324
+ All pull requests will be pre-checked using GitHub actions to execute all these tests. You can see the [results of test
325
+ runs here](https://github.com/approvals/ApprovalTests.Python/actions).
@@ -0,0 +1,17 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+
4
+ class CommandGetter(ABC):
5
+ @abstractmethod
6
+ def get_command(self) -> str:
7
+ raise NotImplementedError("Interface member not implemented")
8
+
9
+
10
+ class CommandExecutor(ABC):
11
+ @abstractmethod
12
+ def execute_command(self, command: str) -> str:
13
+ raise NotImplementedError("Interface member not implemented")
14
+
15
+
16
+ class ExecutableCommand(CommandGetter, CommandExecutor):
17
+ pass
@@ -0,0 +1,10 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from approval_utilities.approvaltests.core.verify_parameters import VerifyParameters
4
+ from approvaltests.core.options import Options
5
+
6
+
7
+ class Verifiable(ABC):
8
+ @abstractmethod
9
+ def get_verify_parameters(self, options: "Options") -> VerifyParameters:
10
+ pass
@@ -0,0 +1,9 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ if TYPE_CHECKING:
4
+ from approvaltests.core.options import Options
5
+
6
+
7
+ class VerifyParameters:
8
+ def __init__(self, options: "Options"):
9
+ self.options = options
@@ -0,0 +1,20 @@
1
+ from typing import Any, Callable, List, Optional
2
+
3
+
4
+ def format_list(alist: List[Any], formatter: Optional[Callable], header: str) -> str:
5
+ if formatter is None:
6
+ formatter = FormatLineItem().print_item
7
+ text = (header + "\n\n") if header else ""
8
+ for i in alist:
9
+ text += formatter(i) + "\n"
10
+ return text
11
+
12
+
13
+ class FormatLineItem:
14
+ def __init__(self) -> None:
15
+ self.index = 0
16
+
17
+ def print_item(self, item: Any) -> str:
18
+ text = str(self.index) + ") " + str(item)
19
+ self.index += 1
20
+ return text
File without changes
@@ -0,0 +1,7 @@
1
+ def copy_to_clipboard(text: str) -> None:
2
+ """
3
+ This acts as a wrapper to defer the importing of pyperclip util actual usage
4
+ """
5
+ import pyperclip # type ignore
6
+
7
+ pyperclip.copy(text)
@@ -0,0 +1,25 @@
1
+ import functools
2
+ import warnings
3
+ from typing import Callable
4
+
5
+
6
+ def deprecated(reason: str) -> Callable:
7
+ def decorator(func: Callable) -> Callable:
8
+ """This is a decorator which can be used to mark functions
9
+ as deprecated. It will result in a warning being emitted
10
+ when the function is used."""
11
+
12
+ @functools.wraps(func)
13
+ def new_func(*args, **kwargs):
14
+ warnings.simplefilter("always", DeprecationWarning) # turn off filter
15
+ warnings.warn(
16
+ f"Call to deprecated function {func.__name__}. {reason}",
17
+ category=DeprecationWarning,
18
+ stacklevel=2,
19
+ )
20
+ warnings.simplefilter("default", DeprecationWarning) # reset filter
21
+ return func(*args, **kwargs)
22
+
23
+ return new_func
24
+
25
+ return decorator