From 6e4043bc3e99a912c93366ea0dd1124768a678bf Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:04:00 -0600 Subject: [PATCH 01/11] Cleanup --- setup.cfg | 1 - tests/resources/closes-on-exception-filenotfounderror.log | 2 +- .../resources/closes-on-exception-notimplementederror.log | 8 ++++---- tests/resources/closes-on-exception-oserror.log | 2 +- tests/resources/closes-on-exception-success.log | 8 ++++---- tests/resources/closes-on-exception-typeerror.log | 2 +- tests/resources/closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 8 ++++---- tests/resources/example.log | 8 ++++---- tests/resources/test_config.log | 8 ++++---- 10 files changed, 24 insertions(+), 25 deletions(-) diff --git a/setup.cfg b/setup.cfg index b8496e3..cee1b6c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,6 @@ description = A Python package that provides general utility functions for manag long_description = file: README.md long_description_content_type = text/markdown author = Tom Eleff -author_email = eleffthomas@gmail.com url = https://github.com/thomaseleff/pytensils project_urls = Issues = https://github.com/thomaseleff/pytensils/issues diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 12cfc95..2b47ce3 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-08-12 21:39:28 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index 0fab4e1..16194b3 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-08-12 21:39:29 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 18:33:26.617300 - End time : 18:33:26.893199 - Run time : 00:00:00.275899 + Start time : 21:39:29.006285 + End time : 21:39:29.203790 + Run time : 00:00:00.197505 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 12cfc95..2b47ce3 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-08-12 21:39:28 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index 7679932..d80d60a 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-08-12 21:39:28 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 18:33:25.566032 - End time : 18:33:25.737897 - Run time : 00:00:00.171865 + Start time : 21:39:28.135284 + End time : 21:39:28.259434 + Run time : 00:00:00.124150 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 12cfc95..2b47ce3 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-08-12 21:39:28 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 12cfc95..2b47ce3 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-08-12 21:39:28 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index b35cc44..f6603a1 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-08-12 21:39:28 -------------------------------------------------------------------------- @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 18:33:25.823342 - End time : 18:33:26.211961 - Run time : 00:00:00.388619 + Start time : 21:39:28.337832 + End time : 21:39:28.667502 + Run time : 00:00:00.329670 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 4288f21..95db1a6 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:24 + Start time : 2024-08-12 21:39:27 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 18:33:24.702949 - End time : 18:33:24.981427 - Run time : 00:00:00.278478 + Start time : 21:39:27.251310 + End time : 21:39:27.527256 + Run time : 00:00:00.275946 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index 4bd7a25..e8cefce 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-07-08 18:33:24 + Start time : 2024-08-12 21:39:27 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 18:33:24.471101 - End time : 18:33:24.680127 - Run time : 00:00:00.209026 + Start time : 21:39:27.023033 + End time : 21:39:27.229021 + Run time : 00:00:00.205988 -------------------------------------------------------------------------- From 93e099f4e99ac6e5a7dc32639d3098e26b05eebe Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:12:43 -0600 Subject: [PATCH 02/11] Resolves #33 --- pytensils/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pytensils/utils.py b/pytensils/utils.py index 8b497b3..4ea907c 100644 --- a/pytensils/utils.py +++ b/pytensils/utils.py @@ -55,6 +55,7 @@ def generate_output_directory( def as_type( value: str, return_dtype: Literal[ + 'none', 'str', 'int', 'float', @@ -88,6 +89,12 @@ def as_type( """ try: + if ( + return_dtype.strip().upper() == 'NONE' + and not ast.literal_eval(value) + ): + return None + if return_dtype.strip().upper() == 'STR': return str(value) From 66ec7fc68eb79fcdd436c2b5281c298169d9d111 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:16:13 -0600 Subject: [PATCH 03/11] Adds tests #33 --- tests/resources/closes-on-exception-filenotfounderror.log | 2 +- .../resources/closes-on-exception-notimplementederror.log | 8 ++++---- tests/resources/closes-on-exception-oserror.log | 2 +- tests/resources/closes-on-exception-success.log | 8 ++++---- tests/resources/closes-on-exception-typeerror.log | 2 +- tests/resources/closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 8 ++++---- tests/resources/example.log | 8 ++++---- tests/resources/test_config.log | 8 ++++---- tests/test_utils.py | 4 ++++ 10 files changed, 28 insertions(+), 24 deletions(-) diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 2b47ce3..84cfa93 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:50 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index 16194b3..d9cf6db 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:29 + Start time : 2024-12-06 16:15:50 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 21:39:29.006285 - End time : 21:39:29.203790 - Run time : 00:00:00.197505 + Start time : 16:15:50.318851 + End time : 16:15:50.505226 + Run time : 00:00:00.186375 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 2b47ce3..262f196 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:49 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index d80d60a..e69c503 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:49 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 21:39:28.135284 - End time : 21:39:28.259434 - Run time : 00:00:00.124150 + Start time : 16:15:49.543041 + End time : 16:15:49.636580 + Run time : 00:00:00.093539 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 2b47ce3..84cfa93 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:50 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 2b47ce3..84cfa93 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:50 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index f6603a1..21843e4 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:28 + Start time : 2024-12-06 16:15:49 -------------------------------------------------------------------------- @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 21:39:28.337832 - End time : 21:39:28.667502 - Run time : 00:00:00.329670 + Start time : 16:15:49.689143 + End time : 16:15:49.944698 + Run time : 00:00:00.255555 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 95db1a6..f8c53e6 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-08-12 21:39:27 + Start time : 2024-12-06 16:15:48 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 21:39:27.251310 - End time : 21:39:27.527256 - Run time : 00:00:00.275946 + Start time : 16:15:48.736294 + End time : 16:15:49.104660 + Run time : 00:00:00.368366 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index e8cefce..e2433a8 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-08-12 21:39:27 + Start time : 2024-12-06 16:15:48 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 21:39:27.023033 - End time : 21:39:27.229021 - Run time : 00:00:00.205988 + Start time : 16:15:48.545189 + End time : 16:15:48.709758 + Run time : 00:00:00.164569 -------------------------------------------------------------------------- diff --git a/tests/test_utils.py b/tests/test_utils.py index 4cb2704..951e7c6 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -36,6 +36,10 @@ def test_generate_output_directory_oserror(): ) +def test_as_type_success_none(): + assert not utils.as_type(value='None', return_dtype='none') + + def test_as_type_success_str(): assert utils.as_type(value='ABC') == 'ABC' From d4cb1fd60d293b11139b8437b5dde9749f9bc43b Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:27:40 -0600 Subject: [PATCH 04/11] Resolves #35 --- pytensils/config.py | 6 +++++- tests/resources/closes-on-exception-filenotfounderror.log | 2 +- .../resources/closes-on-exception-notimplementederror.log | 8 ++++---- tests/resources/closes-on-exception-oserror.log | 2 +- tests/resources/closes-on-exception-success.log | 8 ++++---- tests/resources/closes-on-exception-typeerror.log | 2 +- tests/resources/closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 8 ++++---- tests/resources/example.log | 8 ++++---- tests/resources/test_config.log | 8 ++++---- 10 files changed, 29 insertions(+), 25 deletions(-) diff --git a/pytensils/config.py b/pytensils/config.py index 67ed385..651eab8 100644 --- a/pytensils/config.py +++ b/pytensils/config.py @@ -123,7 +123,8 @@ def __init__( ) def read(self) -> dict: - """ Reads a '.json' config-file and returns the content as a `dict`. + """ Reads a '.json' config-file, updates the config data + and returns the content as a `dict`. """ with open( os.path.join( @@ -164,6 +165,9 @@ def read(self) -> dict: ) ) + # Update the config data + self.data = copy.deepcopy(dict_object) + return dict_object except json.decoder.JSONDecodeError: diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 12cfc95..0a28e18 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:27:06 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index 0fab4e1..18c6097 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:27:06 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 18:33:26.617300 - End time : 18:33:26.893199 - Run time : 00:00:00.275899 + Start time : 16:27:06.449937 + End time : 16:27:06.576043 + Run time : 00:00:00.126106 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 12cfc95..0a28e18 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:27:06 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index 7679932..6271fa3 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 16:27:05 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 18:33:25.566032 - End time : 18:33:25.737897 - Run time : 00:00:00.171865 + Start time : 16:27:05.734584 + End time : 16:27:05.857534 + Run time : 00:00:00.122950 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 12cfc95..0a28e18 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:27:06 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 12cfc95..0a28e18 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:27:06 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index b35cc44..1835d3e 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 16:27:05 -------------------------------------------------------------------------- @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 18:33:25.823342 - End time : 18:33:26.211961 - Run time : 00:00:00.388619 + Start time : 16:27:05.917535 + End time : 16:27:06.202919 + Run time : 00:00:00.285384 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 4288f21..86d9dee 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 16:27:04 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 18:33:24.702949 - End time : 18:33:24.981427 - Run time : 00:00:00.278478 + Start time : 16:27:04.893262 + End time : 16:27:05.165485 + Run time : 00:00:00.272223 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index 4bd7a25..870781b 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 16:27:04 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 18:33:24.471101 - End time : 18:33:24.680127 - Run time : 00:00:00.209026 + Start time : 16:27:04.671258 + End time : 16:27:04.868506 + Run time : 00:00:00.197248 -------------------------------------------------------------------------- From 20a2253097fe3a91ca2326891aa003213136d259 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:38:56 -0600 Subject: [PATCH 05/11] Resolves #36 --- pytensils/config.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pytensils/config.py b/pytensils/config.py index 67ed385..a00c7a9 100644 --- a/pytensils/config.py +++ b/pytensils/config.py @@ -9,6 +9,7 @@ Contains the `class` methods for managing configuration. """ +from __future__ import annotations import os import json import copy @@ -218,7 +219,7 @@ def write(self): def validate( self, - dtypes: dict + dtypes: Union[dict, Handler], ) -> bool: """ Validates the config-file data against the dtypes in `dtypes`. Returns `True` when validation completes successfully. @@ -229,6 +230,16 @@ def validate( Dictionary object that contains the expected configuration value dtypes. """ + assert type(dtypes) in [dict, Handler], ( + ''.join([ + '{dtypes} must be either a `dict` or an instance of', + ' `pytensils.config.Handler`.' + ]) + ) + + # Parse the config data as a dictionary + if isinstance(dtypes, Handler): + dtypes = dtypes.to_dict() # Validate instance self._validate_instance(dict_object=dtypes, parameter='dtypes') From 49a332b0b1945b892cf185afd93864cc348633bc Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:39:59 -0600 Subject: [PATCH 06/11] Cleanup #36 --- pytensils/config.py | 2 +- tests/resources/closes-on-exception-filenotfounderror.log | 2 +- .../resources/closes-on-exception-notimplementederror.log | 8 ++++---- tests/resources/closes-on-exception-oserror.log | 2 +- tests/resources/closes-on-exception-success.log | 8 ++++---- tests/resources/closes-on-exception-typeerror.log | 2 +- tests/resources/closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 8 ++++---- tests/resources/example.log | 8 ++++---- tests/resources/test_config.log | 8 ++++---- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/pytensils/config.py b/pytensils/config.py index a00c7a9..bf1b059 100644 --- a/pytensils/config.py +++ b/pytensils/config.py @@ -226,7 +226,7 @@ def validate( Parameters ---------- - dtypes : `dict` + dtypes : Union[`dict`, `pytensils.config.Handler`] Dictionary object that contains the expected configuration value dtypes. """ diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 12cfc95..00814b8 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:39:05 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index 0fab4e1..ff314c6 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:39:05 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 18:33:26.617300 - End time : 18:33:26.893199 - Run time : 00:00:00.275899 + Start time : 16:39:05.985247 + End time : 16:39:06.107531 + Run time : 00:00:00.122284 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 12cfc95..00814b8 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:39:05 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index 7679932..2ff2953 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 16:39:05 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 18:33:25.566032 - End time : 18:33:25.737897 - Run time : 00:00:00.171865 + Start time : 16:39:05.225213 + End time : 16:39:05.359483 + Run time : 00:00:00.134270 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 12cfc95..00814b8 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:39:05 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 12cfc95..00814b8 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 16:39:05 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index b35cc44..3c46acc 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 16:39:05 -------------------------------------------------------------------------- @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 18:33:25.823342 - End time : 18:33:26.211961 - Run time : 00:00:00.388619 + Start time : 16:39:05.416755 + End time : 16:39:05.649986 + Run time : 00:00:00.233231 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 4288f21..0637ec7 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 16:39:04 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 18:33:24.702949 - End time : 18:33:24.981427 - Run time : 00:00:00.278478 + Start time : 16:39:04.521261 + End time : 16:39:04.783789 + Run time : 00:00:00.262528 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index 4bd7a25..f492a2f 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 16:39:04 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 18:33:24.471101 - End time : 18:33:24.680127 - Run time : 00:00:00.209026 + Start time : 16:39:04.306208 + End time : 16:39:04.494261 + Run time : 00:00:00.188053 -------------------------------------------------------------------------- From 1f76f108aaa1e85de92ec9be84030d84f5966651 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 15:43:17 -0600 Subject: [PATCH 07/11] Adds tests #36 --- .../closes-on-exception-filenotfounderror.log | 2 +- ...loses-on-exception-notimplementederror.log | 8 +++---- .../resources/closes-on-exception-oserror.log | 2 +- .../resources/closes-on-exception-success.log | 8 +++---- .../closes-on-exception-typeerror.log | 2 +- .../closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 8 +++---- tests/resources/example.log | 8 +++---- tests/resources/test_config.log | 8 +++---- tests/test_config.py | 21 ++++++++++++++++++- 10 files changed, 44 insertions(+), 25 deletions(-) diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 00814b8..398b9a7 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:58 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index ff314c6..74086ca 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:58 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 16:39:05.985247 - End time : 16:39:06.107531 - Run time : 00:00:00.122284 + Start time : 16:42:58.215060 + End time : 16:42:58.342184 + Run time : 00:00:00.127124 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 00814b8..8ac7661 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:57 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index 2ff2953..5feddbc 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:57 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 16:39:05.225213 - End time : 16:39:05.359483 - Run time : 00:00:00.134270 + Start time : 16:42:57.522496 + End time : 16:42:57.613167 + Run time : 00:00:00.090671 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 00814b8..398b9a7 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:58 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 00814b8..398b9a7 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:58 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index 3c46acc..bfa765e 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:05 + Start time : 2024-12-06 16:42:57 -------------------------------------------------------------------------- @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 16:39:05.416755 - End time : 16:39:05.649986 - Run time : 00:00:00.233231 + Start time : 16:42:57.683633 + End time : 16:42:57.954380 + Run time : 00:00:00.270747 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 0637ec7..402e89c 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-12-06 16:39:04 + Start time : 2024-12-06 16:42:56 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 16:39:04.521261 - End time : 16:39:04.783789 - Run time : 00:00:00.262528 + Start time : 16:42:56.847556 + End time : 16:42:57.107387 + Run time : 00:00:00.259831 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index f492a2f..9207016 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-12-06 16:39:04 + Start time : 2024-12-06 16:42:56 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 16:39:04.306208 - End time : 16:39:04.494261 - Run time : 00:00:00.188053 + Start time : 16:42:56.668643 + End time : 16:42:56.821305 + Run time : 00:00:00.152662 -------------------------------------------------------------------------- diff --git a/tests/test_config.py b/tests/test_config.py index 82b4ce6..4595581 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -202,7 +202,7 @@ def test_from_dict_success( } -def test_validate_success( +def test_validate_from_dict_success( CONFIG_FIXTURE: config.Handler, DTYPES_FIXTURE: config.Handler ): @@ -212,6 +212,25 @@ def test_validate_success( assert not CONFIG_FIXTURE.validation_errors +def test_validate_from_config_handler_success( + CONFIG_FIXTURE: config.Handler, + DTYPES_FIXTURE: config.Handler +): + assert CONFIG_FIXTURE.validate( + dtypes=DTYPES_FIXTURE + ) + assert not CONFIG_FIXTURE.validation_errors + + +def test_validate_assertionerror( + CONFIG_FIXTURE: config.Handler +): + with pytest.raises(AssertionError): + CONFIG_FIXTURE.validate( + dtypes='invalid-type' + ) + + def test_validate_instance_validationerror(CONFIG_FIXTURE: config.Handler): with pytest.raises(errors.config.ValidationError): CONFIG_FIXTURE._validate_instance( From cc442fb5e77d8679df609178569614995c21a586 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 16:07:44 -0600 Subject: [PATCH 08/11] Revises gitignore --- .gitignore | 2 +- python.log | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 python.log diff --git a/.gitignore b/.gitignore index f19a515..bd8e414 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ __pycache__ /archive .vscode -.pytensils +.venv .pytest_cache .coverage testing.py \ No newline at end of file diff --git a/python.log b/python.log new file mode 100644 index 0000000..a4f2acb --- /dev/null +++ b/python.log @@ -0,0 +1,19 @@ + Run information + --------------- + + Environment information summary. + + Start time : 2024-12-06 16:59:14 + + -------------------------------------------------------------------------- + + Config validation + ----------------- + + INFO: Config validation completed successfully. + + str : ABC + bool : True + int : 1 + float : 9.9 + list : ['A', 'B', 'C'] From a8574863a141445669b106fbf1a11a954da5b0ba Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 17:06:04 -0600 Subject: [PATCH 09/11] Resolves #38 --- pytensils/logging.py | 10 +++- python.log | 19 ------ .../closes-on-exception-filenotfounderror.log | 2 +- ...loses-on-exception-notimplementederror.log | 8 +-- .../resources/closes-on-exception-oserror.log | 2 +- .../resources/closes-on-exception-success.log | 8 +-- .../closes-on-exception-typeerror.log | 2 +- .../closes-on-exception-validationerror.log | 2 +- tests/resources/closes-on-exception.log | 10 ++-- tests/resources/example.log | 8 +-- tests/resources/test_config.log | 8 +-- tests/test_logging.py | 58 ++++++++++++++----- 12 files changed, 79 insertions(+), 58 deletions(-) delete mode 100644 python.log diff --git a/pytensils/logging.py b/pytensils/logging.py index 0b421eb..94fb856 100644 --- a/pytensils/logging.py +++ b/pytensils/logging.py @@ -31,10 +31,18 @@ # Setup CPython logging pytensils = logging.getLogger('pytensils') pytensils.setLevel(level=logging.DEBUG) + +# Prevent propagation to the root logger to avoid duplicate messages +pytensils.propagate = False + +# Setup a CPython logging stream handler debugger = logging.StreamHandler() debugger.setLevel(level=logging.DEBUG) debugger.setFormatter(fmt=logging.Formatter('[DEBUG] %(message)s')) -pytensils.addHandler(hdlr=debugger) + +# Add the handler if it does not currently exist +if not any(isinstance(h, logging.StreamHandler) for h in pytensils.handlers): + pytensils.addHandler(hdlr=debugger) # Setup tabulate tabulate.PRESERVE_WHITESPACE = True diff --git a/python.log b/python.log deleted file mode 100644 index a4f2acb..0000000 --- a/python.log +++ /dev/null @@ -1,19 +0,0 @@ - Run information - --------------- - - Environment information summary. - - Start time : 2024-12-06 16:59:14 - - -------------------------------------------------------------------------- - - Config validation - ----------------- - - INFO: Config validation completed successfully. - - str : ABC - bool : True - int : 1 - float : 9.9 - list : ['A', 'B', 'C'] diff --git a/tests/resources/closes-on-exception-filenotfounderror.log b/tests/resources/closes-on-exception-filenotfounderror.log index 12cfc95..f345a54 100644 --- a/tests/resources/closes-on-exception-filenotfounderror.log +++ b/tests/resources/closes-on-exception-filenotfounderror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 18:04:46 diff --git a/tests/resources/closes-on-exception-notimplementederror.log b/tests/resources/closes-on-exception-notimplementederror.log index 0fab4e1..8a33deb 100644 --- a/tests/resources/closes-on-exception-notimplementederror.log +++ b/tests/resources/closes-on-exception-notimplementederror.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 18:04:46 -------------------------------------------------------------------------- @@ -28,8 +28,8 @@ Run-time performance summary. - Start time : 18:33:26.617300 - End time : 18:33:26.893199 - Run time : 00:00:00.275899 + Start time : 18:04:46.649282 + End time : 18:04:46.847472 + Run time : 00:00:00.198190 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-oserror.log b/tests/resources/closes-on-exception-oserror.log index 12cfc95..f345a54 100644 --- a/tests/resources/closes-on-exception-oserror.log +++ b/tests/resources/closes-on-exception-oserror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 18:04:46 diff --git a/tests/resources/closes-on-exception-success.log b/tests/resources/closes-on-exception-success.log index 7679932..4490bf0 100644 --- a/tests/resources/closes-on-exception-success.log +++ b/tests/resources/closes-on-exception-success.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 18:04:45 -------------------------------------------------------------------------- @@ -13,8 +13,8 @@ Run-time performance summary. - Start time : 18:33:25.566032 - End time : 18:33:25.737897 - Run time : 00:00:00.171865 + Start time : 18:04:45.812073 + End time : 18:04:45.939506 + Run time : 00:00:00.127433 -------------------------------------------------------------------------- diff --git a/tests/resources/closes-on-exception-typeerror.log b/tests/resources/closes-on-exception-typeerror.log index 12cfc95..f345a54 100644 --- a/tests/resources/closes-on-exception-typeerror.log +++ b/tests/resources/closes-on-exception-typeerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 18:04:46 diff --git a/tests/resources/closes-on-exception-validationerror.log b/tests/resources/closes-on-exception-validationerror.log index 12cfc95..f345a54 100644 --- a/tests/resources/closes-on-exception-validationerror.log +++ b/tests/resources/closes-on-exception-validationerror.log @@ -4,4 +4,4 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:26 + Start time : 2024-12-06 18:04:46 diff --git a/tests/resources/closes-on-exception.log b/tests/resources/closes-on-exception.log index b35cc44..b8e4096 100644 --- a/tests/resources/closes-on-exception.log +++ b/tests/resources/closes-on-exception.log @@ -4,7 +4,7 @@ Generates close-on-exception content for `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:25 + Start time : 2024-12-06 18:04:46 -------------------------------------------------------------------------- @@ -16,7 +16,7 @@ >>> ZeroDivisionError: division by zero Filename : T:\Documents\Projects\[...]sils\tests\test_logging.py - Line Number : Line 329 + Line Number : Line 361 Function : divide_by_zero() Exception : ZeroDivisionError @@ -27,8 +27,8 @@ Run-time performance summary. - Start time : 18:33:25.823342 - End time : 18:33:26.211961 - Run time : 00:00:00.388619 + Start time : 18:04:46.014435 + End time : 18:04:46.316471 + Run time : 00:00:00.302036 -------------------------------------------------------------------------- diff --git a/tests/resources/example.log b/tests/resources/example.log index 4288f21..ffcfc83 100644 --- a/tests/resources/example.log +++ b/tests/resources/example.log @@ -4,7 +4,7 @@ Generates example user-log content for all `pytenstils.logging` functionality. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 18:04:44 Extra parameter (1) : 1 Extra parameter (2) : 2 @@ -74,8 +74,8 @@ Run-time performance summary. - Start time : 18:33:24.702949 - End time : 18:33:24.981427 - Run time : 00:00:00.278478 + Start time : 18:04:44.965261 + End time : 18:04:45.237671 + Run time : 00:00:00.272410 -------------------------------------------------------------------------- diff --git a/tests/resources/test_config.log b/tests/resources/test_config.log index 4bd7a25..c03ed0e 100644 --- a/tests/resources/test_config.log +++ b/tests/resources/test_config.log @@ -3,7 +3,7 @@ Environment information summary. - Start time : 2024-07-08 18:33:24 + Start time : 2024-12-06 18:04:44 -------------------------------------------------------------------------- @@ -31,8 +31,8 @@ Run-time performance summary. - Start time : 18:33:24.471101 - End time : 18:33:24.680127 - Run time : 00:00:00.209026 + Start time : 18:04:44.750909 + End time : 18:04:44.938004 + Run time : 00:00:00.187095 -------------------------------------------------------------------------- diff --git a/tests/test_logging.py b/tests/test_logging.py index b88db94..33ca027 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -10,6 +10,7 @@ """ import os +from io import StringIO import pandas as pd import logging as clogging import pytest @@ -228,8 +229,7 @@ def test_write_typeerror(): ) -def test_debug_console(caplog: pytest.LogCaptureFixture): - caplog.set_level(clogging.DEBUG) +def test_debug_console(): # Initialize logging Logging = logging.Handler( @@ -241,19 +241,51 @@ def test_debug_console(caplog: pytest.LogCaptureFixture): debug_console=True ) - # Create debug console output - Logging.write(content='Log-content-for-the-output-console') - - # Cleanup - os.remove( - os.path.join( - os.path.dirname(__file__), - 'resources', - 'python.log' - ) + # Ensure that a StreamHandler is attached + handler = next( + ( + h for h in logging.pytensils.handlers if isinstance( + h, + clogging.StreamHandler + ) + ), + None ) + assert handler is not None + + # Replace the StreamHandler with StringIO + log_output = StringIO() + original_stream = handler.stream + handler.setStream(log_output) + + try: + + # Loging + test_message = "Log-content-for-the-output-console" + Logging.write('Log-content-for-the-output-console') + + # Flush the handler and retrieve the log output + handler.flush() + log_output.seek(0) + captured_logs = log_output.read() + + # Ensure the log message is present in the captured output + assert test_message in captured_logs + assert "DEBUG" in captured_logs - assert 'Log-content-for-the-output-console' in caplog.text + finally: + + # Restore the StreamHandler + handler.setStream(original_stream) + + # Cleanup + os.remove( + os.path.join( + os.path.dirname(__file__), + 'resources', + 'python.log' + ) + ) def test_pretty_dict_valueerror(): From d5abc9efb4b7252d31a02859287edadf4619e317 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 17:12:55 -0600 Subject: [PATCH 10/11] Updates docstrings --- pytensils/__init__.py | 7 +++++++ pytensils/config.py | 34 ++++++++++++++++++++-------------- pytensils/errors.py | 12 ++---------- pytensils/logging.py | 34 +++++++++++++++++++++++----------- pytensils/profiler.py | 13 ++----------- pytensils/utils.py | 11 +---------- 6 files changed, 55 insertions(+), 56 deletions(-) diff --git a/pytensils/__init__.py b/pytensils/__init__.py index cf99000..6ccf26b 100644 --- a/pytensils/__init__.py +++ b/pytensils/__init__.py @@ -1,3 +1,10 @@ +""" pytensils + +A Python package that provides general utility functions for managing +configuration, user-logging, directories and data-types as well as +a basic run-time profiler. +""" + import pytensils.config as config import pytensils.logging as logging import pytensils.utils as utils diff --git a/pytensils/config.py b/pytensils/config.py index 67ed385..e069e7a 100644 --- a/pytensils/config.py +++ b/pytensils/config.py @@ -1,13 +1,4 @@ -""" -Information ---------------------------------------------------------------------- -Name : config.py -Location : ~/ - -Description ---------------------------------------------------------------------- -Contains the `class` methods for managing configuration. -""" +""" Configuration management """ import os import json @@ -21,6 +12,23 @@ class Handler(): + """ A `class` that represents a configuration-handler. + + Parameters + ---------- + path : `str` + Directory path to the folder that contains the `file_name` of the + '.json' config-file. + file_name : `str` + File name of the '.json' config-file. + create: `bool` + `True` or `False`, creates an empty log-file, `file_name` + within `path` when `True`. + Logging: `pytensils.logging.Handler` + An instance of the `pytensils.logging.Handler` class that allows + for native 'pretty' user-logging of all `ValidationError` + exceptions. + """ def __init__( self, @@ -201,8 +209,7 @@ def read(self) -> dict: ) def write(self): - """ Writes a '.json' config-file. - """ + """ Writes a '.json' config-file. """ with open( os.path.join( self.path, @@ -251,8 +258,7 @@ def validate( return True def to_dict(self) -> dict: - """ Returns a dictionary object of the config-file data. - """ + """ Returns a dictionary object of the config-file data. """ return copy.deepcopy(self.data) def from_dict( diff --git a/pytensils/errors.py b/pytensils/errors.py index ad4e6bf..cfafde8 100644 --- a/pytensils/errors.py +++ b/pytensils/errors.py @@ -1,16 +1,8 @@ -""" -Information ---------------------------------------------------------------------- -Name : errors.py -Location : ~/ -Description ---------------------------------------------------------------------- -Contains the `class` exceptions for all native `pytensils` errors and -all error accessor functions. -""" +""" errors """ class config: + """ A `class` that contains all config-related errors. """ # Exceptions class OSError(OSError): diff --git a/pytensils/logging.py b/pytensils/logging.py index 94fb856..08029ed 100644 --- a/pytensils/logging.py +++ b/pytensils/logging.py @@ -1,13 +1,4 @@ -""" -Information ---------------------------------------------------------------------- -Name : logging.py -Location : ~/ - -Description ---------------------------------------------------------------------- -Contains the `class` methods for 'pretty' user-logging. -""" +""" Pretty user-logging """ import os import textwrap @@ -49,6 +40,27 @@ class Handler(): + """ A `class` that represents a logging-handler. + + Parameters + ---------- + path : `str` + Directory path to the folder that contains the `file_name` of the + log-file. + file_name : `str` + File name of the log-file. + description : `str` + Information about the executed Python job run. + metadata : `dict` + Environment parameters to display as metadata about the executed + Python job run. + create: `bool` + `True` or `False`, creates an empty log-file, `file_name` + within `path` when `True`. + debug_console: `bool` + `True` or `False`, outputs the logging content to the console + output when `True` using `logging.debug()`. + """ def __init__( self, @@ -59,7 +71,7 @@ def __init__( create: bool = True, debug_console: bool = False ): - """ Initializes an instance of the logger-handler class. + """ Initializes an instance of the logging-handler class. Parameters ---------- diff --git a/pytensils/profiler.py b/pytensils/profiler.py index bbb70d6..40965b3 100644 --- a/pytensils/profiler.py +++ b/pytensils/profiler.py @@ -1,13 +1,4 @@ -""" -Information ---------------------------------------------------------------------- -Name : profiler.py -Location : ~/ - -Description ---------------------------------------------------------------------- -Contains utility functions for profiling functions. -""" +""" Run-time profiling """ import time import datetime as dt @@ -31,7 +22,7 @@ def wrapper(*args, **kwargs): result = func(*args, **kwargs) t2 = time.time() td = dt.timedelta(seconds=(t2-t1)) - print("\n[INFO] Function {%s()} executed in %s hh:mm:ss" % ( + print("\n[INFO] Function {%s()} executed in %s hh:mm:ss." % ( func.__name__, td ) diff --git a/pytensils/utils.py b/pytensils/utils.py index 8b497b3..44a40d5 100644 --- a/pytensils/utils.py +++ b/pytensils/utils.py @@ -1,13 +1,4 @@ -""" -Information ---------------------------------------------------------------------- -Name : utils.py -Location : ~/ - -Description ---------------------------------------------------------------------- -Contains utility functions for managing directories and data-types. -""" +""" Directory and data-type utilities """ import os import ast From 408c5b73c8e1473bbddd9cd3a2b9e7d6f5911ae4 Mon Sep 17 00:00:00 2001 From: Thomas Eleff Date: Fri, 6 Dec 2024 17:33:26 -0600 Subject: [PATCH 11/11] Resolves bug issue --- tests/test_logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_logging.py b/tests/test_logging.py index 33ca027..5572f03 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -262,7 +262,7 @@ def test_debug_console(): # Loging test_message = "Log-content-for-the-output-console" - Logging.write('Log-content-for-the-output-console') + Logging.write(test_message) # Flush the handler and retrieve the log output handler.flush()