diff --git a/README.md b/README.md index 971a406a..5724d186 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,31 @@ # ApprovalTests.Python - ## Contents -- [ApprovalTests.Python](#approvaltestspython) - - [Contents](#contents) - - [What can I use ApprovalTests for?](#what-can-i-use-approvaltests-for) - - [Getting Started](#getting-started) - - [What Are Approvals](#what-are-approvals) - - [New Projects](#new-projects) - - [Minimal Example Tutorial](#minimal-example-tutorial) - - [Adding to Existing Projects](#adding-to-existing-projects) - - [Overview](#overview) - - [Example using pytest](#example-using-pytest) - - [Example using unittest](#example-using-unittest) - - [Example using CLI](#example-using-cli) - - [Usage](#usage) - - [Argument Definitions](#argument-definitions) - - [Reporters](#reporters) - - [Selecting a Reporter](#selecting-a-reporter) - - [JSON file for collection of reporters](#json-file-for-collection-of-reporters) - - [Support and Documentation](#support-and-documentation) - - [Missing Documentation?](#missing-documentation) - - [Dependencies](#dependencies) - - [Required dependencies](#required-dependencies) - - [Extra dependencies](#extra-dependencies) - - [For developers](#for-developers) - - [Weekly Ensemble](#weekly-ensemble) - - [Pull Requests](#pull-requests) - + * [What can I use ApprovalTests for?](#what-can-i-use-approvaltests-for) + * [Getting Started](#getting-started) + * [What Are Approvals](#what-are-approvals) + * [New Projects](#new-projects) + * [Minimal Example Tutorial](#minimal-example-tutorial) + * [Adding to Existing Projects](#adding-to-existing-projects) + * [Overview](#overview) + * [Example using pytest](#example-using-pytest) + * [Example using unittest](#example-using-unittest) + * [Example using CLI](#example-using-cli) + * [Usage](#usage) + * [Argument Definitions](#argument-definitions) + * [Reporters](#reporters) + * [Selecting a Reporter](#selecting-a-reporter) + * [JSON file for collection of reporters](#json-file-for-collection-of-reporters) + * [Support and Documentation](#support-and-documentation) + * [Missing Documentation?](#missing-documentation) + * [Dependencies](#dependencies) + * [Required dependencies](#required-dependencies) + * [Extra dependencies](#extra-dependencies) + * [For developers](#for-developers) + * [Weekly Ensemble](#weekly-ensemble) + * [Pull Requests](#pull-requests) Capturing Human Intelligence - ApprovalTests is an open source assertion/verification library to aid testing. `approvaltests` is the ApprovalTests port for Python. @@ -83,9 +79,7 @@ golden master. ### Example using pytest - - ```py from approvaltests.approvals import verify @@ -94,9 +88,7 @@ def test_simple(): result = "Hello ApprovalTests" verify(result) ``` - snippet source | anchor - Install the plugin pytest-approvaltests and use it to select a reporter: @@ -111,9 +103,7 @@ reporters see [the documentation](https://github.com/approvals/ApprovalTests.Pyt ### Example using unittest - - ```py import unittest @@ -128,9 +118,7 @@ class GettingStartedTest(unittest.TestCase): if __name__ == "__main__": unittest.main() ``` - snippet source | anchor - This example has the same behaviour as the pytest version, but uses the built-in test framework `unittest` instead. @@ -176,17 +164,13 @@ ApprovalTests.Python comes with a few reporters configured, supporting Linux, Ma In the example shown below, we pass in an options with a reporter we're selecting directly: - - ```py class TestSelectReporterFromClass(unittest.TestCase): def test_simple(self): verify("Hello", options=Options().with_reporter(report_with_beyond_compare())) ``` - snippet source | anchor - You can also use the `GenericDiffReporterFactory` to find and select the first diff utility that exists on our system. @@ -194,9 +178,7 @@ You can also use the `GenericDiffReporterFactory` to find and select the first d An advantage of this method is you can modify the reporters.json file directly to handle your unique system. - - ```py class TestSelectReporter(unittest.TestCase): def setUp(self): @@ -207,17 +189,13 @@ class TestSelectReporter(unittest.TestCase): "Hello", options=Options().with_reporter(self.factory.get("BeyondCompare")) ) ``` - snippet source | anchor - Or you can build your own GenericDiffReporter on the fly - - ```py class GettingStartedTest(unittest.TestCase): def test_simple(self): @@ -228,9 +206,7 @@ class GettingStartedTest(unittest.TestCase): ), ) ``` - snippet source | anchor - As long as `C:/my/favorite/diff/utility.exe` can be invoked from the command line using the format `utility.exe file1 file2` @@ -299,17 +275,13 @@ ApprovalTests require Python 3.7 or greater and the following dependencies: These dependencies are always required for approvaltests - - ```txt pytest>=4.0.0 empty-files>=0.0.3 typing_extensions>=3.6.2 ``` - snippet source | anchor - #### Extra dependencies @@ -319,18 +291,16 @@ If you want the bare minimum you can use the pypi project [approvaltests-minimal](https://pypi.org/project/approvaltests-minimal/) - - ```txt pyperclip>=1.5.29 # For Clipboard Reporter beautifulsoup4>=4.4.0 # For verify_html allpairspy>=2.1.0 # For PairwiseCombinations mrjob>=0.7.4 # For MrJob +testfixtures >= 7.1.0 # For verify_logging +mock >= 5.1.0 # For verify_logging ``` - -snippet source | anchor - +snippet source | anchor ## For developers diff --git a/approvaltests/utilities/logging/logging_approvals.py b/approvaltests/utilities/logging/logging_approvals.py index 5a87e5ad..9df2313e 100644 --- a/approvaltests/utilities/logging/logging_approvals.py +++ b/approvaltests/utilities/logging/logging_approvals.py @@ -7,9 +7,10 @@ from approvaltests.scrubbers.date_scrubber import DateScrubber + def verify_logging( - *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ - options: Optional[Options] = None + *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ + options: Optional[Options] = None ) -> ContextManager: class VerifyLogging: def __init__(self): @@ -26,7 +27,9 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): self.l.__exit__(exc_type, exc_val, exc_tb) - self.options = self.options.with_scrubber(DateScrubber.get_scrubber_for("2023-07-16 17:39:03.293919")) + self.options = self.options.with_scrubber( + DateScrubber.get_scrubber_for("2023-07-16 17:39:03.293919") + ) verify(self.l, options=self.options) - return VerifyLogging() \ No newline at end of file + return VerifyLogging() diff --git a/docs/how_to/scrub_dates.md b/docs/how_to/scrub_dates.md index 96cbf500..716ee8bf 100644 --- a/docs/how_to/scrub_dates.md +++ b/docs/how_to/scrub_dates.md @@ -46,5 +46,6 @@ created at | 2020-9-10T08:07Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}Z | | 2020-09-10T08:07:89Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}:\d{2}Z | | 2020-09-10T01:23:45.678Z | \d{4}-\d{1,2}-\d{1,2}T\d{1,2}:\d{2}\:\d{2}\.\d{3}Z | +| 2023-07-16 17:39:03.293919 | \d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{2}\:\d{2}\.\d{6} | | 20210505T091112Z | \d{8}T\d{6}Z | diff --git a/tests/logging/test_logging.py b/tests/logging/test_logging.py index c03832b4..92001b50 100644 --- a/tests/logging/test_logging.py +++ b/tests/logging/test_logging.py @@ -9,28 +9,31 @@ def verify_logging( - *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ - options: Optional[Options] = None - ) -> ContextManager: - class VerifyLogging: - def __init__(self): - self.l = LogCapture() - self.output = "anything" - self.options = options - if not options: - self.options = Options() - def __enter__(self): - self.l.__enter__() - - - pass - - def __exit__(self, exc_type, exc_val, exc_tb): - self.l.__exit__(exc_type, exc_val, exc_tb) - self.options = self.options.with_scrubber(DateScrubber.get_scrubber_for("2023-07-16 17:39:03.293919")) - verify(self.l, options=self.options) - - return VerifyLogging() + *, # enforce keyword arguments - https://www.python.org/dev/peps/pep-3102/ + options: Optional[Options] = None +) -> ContextManager: + class VerifyLogging: + def __init__(self): + self.l = LogCapture() + self.output = "anything" + self.options = options + if not options: + self.options = Options() + + def __enter__(self): + self.l.__enter__() + + pass + + def __exit__(self, exc_type, exc_val, exc_tb): + self.l.__exit__(exc_type, exc_val, exc_tb) + self.options = self.options.with_scrubber( + DateScrubber.get_scrubber_for("2023-07-16 17:39:03.293919") + ) + verify(self.l, options=self.options) + + return VerifyLogging() + def test_basic_logging(): with verify_logging():