Check type

Check utility functions

Module private variables

logging_strict.util.check_type.__all__: tuple[str, str, str, str, str] = ("check_type_path", "is_not_ok", "is_ok", "check_int_verbosity",    "check_start_folder_importable")

Exported objects from this module

Module objects

logging_strict.util.check_type.check_int_verbosity(test)

Check verbosity is an integer with value either 1 or 2

Parameters:

test (Any | None) – variable to test

Returns:

True if integer 1 or 2 otherwise False

Return type:

bool

logging_strict.util.check_type.check_start_folder_importable(folder_start)

Folder containing tests, must have a __init__.py file. Super easy to forget. The required file, indicates the test folder is within a “package”. Not having that file, unittest discover will ungraciously complain.

To reproduce the issue, on a folder not containing a __init__.py file

python -m unittest discover -t . -s "tests/util" -p 'test_check_type*.py'

ImportError: Start directory is not importable: ‘[top level folder absolute path]/tests/util’

With the laughable and useless exit code 1. Exit code 1 and 2 (insufficient permissions) indicates the coder hates you and doesn’t care about UX.

Have a searing hate for error messages that offer no suggestions on how to resolve the issue. Forcing a web search. Bad UX! BAD!! Also unnecessarily bleeds a traceback. Should produce only an exit code

python -m unittest discover --help

Should contain a section, EXIT CODES, listing the exit codes with the message and suggestion on how to resolve the issue. Added benefit, the entrypoint becomes testable. Call the entrypoint in a subprocess and assert the return value(s)

Did figure out why without a web search, but coulda just said, “Make a __init__.py” in that folder, touch [folder path]/__init__.py”

Parameters:

folder_start (Any | None) – folder absolute path

Returns:

True if folder contains __init__.py file otherwise False

Return type:

bool

Raises:
  • TypeError – Unsupported type. Expected folder absolute path

  • ValueError – Cannot expand session user home folder or path is invalid

  • NotADirectoryError – Not a folder. Expected a folder absolute path

logging_strict.util.check_type.check_type_path(module_path, *, msg_context=None)

Check logging_strict.util.check_type.check_type_path.params.module_path is a Path

Parameters:
  • module_path (Any | None) – Parameter to check, if possible and necessary, coerse into Path

  • msg_additional (str | None) – Context specific message, not concerning type

Returns:

Parameter coersed to Path

Return type:

pathlib.Path

Raises:
  • TypeError – Invalid type. Path or PathLike expected

  • ValueError – Cannot expand session user home folder or path is invalid

logging_strict.util.check_type.is_not_ok(test)

Check not None, not a str, or an empty str

Parameters:

test (Any | None) – variable to test

Returns:

True if either: None, not a str, or an empty str

Return type:

bool

logging_strict.util.check_type.is_ok(test)

Check if non-empty str

Edge case: contains only whitespace –> False

Parameters:

test (Any | None) – variable to test

Returns:

True if non-empty str otherwise False

Return type:

bool