Skip to main content

codecov tests build

Set of tools that often have to reproduce in Python scripts.

descriptors

Descriptors for extra type checking.

descriptors.TypeChecker

Universal descriptor for type checking. Then set called - checks that attribute value type equals value_type.

Usage example:

class Foo:
    bar = TypeChecker('bar', list)

    def __init__(self, bar):
        self.bar = bar

descriptors.StringType(TypeChecker)

Descriptor for string checking. Send str as TypeChecker value_type.

Usage example:

class Foo:
    bar = StringType('bar')

    def __init__(self, bar):
        self.bar = bar

descriptors.IntType(TypeChecker)

Descriptor for string checking. Send int as TypeChecker value_type.

descriptors.ListType(TypeChecker)

Descriptor for string checking. Send list as TypeChecker value_type.

descriptors.DictType(TypeChecker)

Descriptor for string checking. Send dict as TypeChecker value_type.

descriptors.WritableFile(StringType)

Descriptor for new file checking. Check that file (value) is a writable file or can be created.

descriptors.HttpMethod(StringType)

Descriptor for http method checking. Check that value is one of http methods.

Custom descriptor example

class HttpMethodType(StringType):
    http_methods = frozenset(['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'PATCH', 'OPTIONS'])

    def __set__(self, instance, value):
        super().__set__(instance, value)
        if value not in self.http_methods:
            instance.__dict__[self.name] = None
            raise TypeError(f'{self.name}={value} is not a HTTP Method.')

logger

logger.Logging

Script logger configuration and methods.

log_date_fmt: log date format (only str)
log_fmt: log format (only str)
log_lvl: log level (logging.DEBUG, logging.INFO and etc.)
file_handler is missing intentionally. Use OS features.

log DEBUG level message:

Logging().debug('message')

log INFO level message:

Logging().info('message')

log WARNING level message:

Logging().warning('message')

log ERROR level message:

Logging().error('message')

log CRITICAL level message:

Logging().critical('message')

utils

Some utils for pure python scripts.

utils.Util

Some useful utils methods.

Util().update(attrs_dict: dict)

Update class public attrs.

Util.check_exists(file_path: str)

Raises FileNotFoundError if file_path not exists.

Util.check_not_exists(file_path: str)

Raises FileExistsError if file_path already exists.

Util.check_extension(file_name: str, extension_list: frozenset)

Compare extension of file_name and extension.

file_name example: 'config.json'
extension_list example: ('.json')

Util.str_to_date(date_str: str, date_fmt: str)

Convert str to date.

Util.date_to_str(date: datetime.date, date_fmt: str)

Convert date/datetime to str.

Util.read_file_gen(file_name: str)

Generator object that line by line read the file_name file.

Util.save_text_file(file_path: str, txt_data)

Save file in plaint text format. txt_data can be List, Generator or String.

Util.save_json_file(file_path: str, json_data)

Save file in JSON format.

Util().public_attrs()

Return dictionary of class public attributes and properties (attrs that starts '_' and properties are excluded).

config

Extendable config template.

config.Config(Util)

Script configuration.

logging parameters:
    log_date_fmt: log date format (only str)
    log_fmt: log format (only str)
    log_lvl: log level (logging.DEBUG, logging.INFO and etc.)

__extensions: acceptable configuration file extensions

Config().log

Script logger instance.

debug message example
cfg = Config()
cfg.log.debug('test')

Config().load(config_file: str)

Load configuration attributes from a config_file.

Config().create_template(file_path: str)

Create JSON config file template.

Usage example

import argparse

from dav_utils.config import Config


def parse_args():
    """Incoming script arguments parser."""
    parser = argparse.ArgumentParser()
    parser.add_argument('--config', default='config.json', type=str,
                        help='Path to configuration file, ex: config.json')
    parser.add_argument('--template', default=False, type=bool,
                        help='Create config template')
    return parser.parse_args()


def main():  # pragma: no cover
    """Strait execution examples."""
    args = parse_args()

    if args.template:
        cfg = Config()
        cfg.log.debug('Trying to create template of configuration file.')
        cfg.create_template(args.config)
        cfg.log.debug('Exit.')
        sys.exit(0)

    try:
        user_config = Config(args.config)
        user_config.log.debug(f'Configuration file loaded: {user_config.public_attrs()}')
    except (AssertionError, FileExistsError):
        sys.exit(1)

    sys.exit(0)


if __name__ == '__main__':
    main()

Running tests

python -m unittest discover tests/

Metadata

Release files for dav-utils 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dav-utils 0.2.5
File Size Uploaded Provenance Actions
dav_utils-0.2.5.tar.gz 8.0 kB Without provenance Details for dav_utils-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dav-utils 0.2.5
File Interpreter ABI Platform Actions
dav_utils-0.2.5-py3-none-any.whl Python 3 none any Details for dav_utils-0.2.5-py3-none-any.whl

Total release size: 16.8 kB

Release files / dav_utils-0.2.5.tar.gz

Download URL dav_utils-0.2.5.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9dcd9732214563f939f356d3bc26a04b6c8909b70e697187217e51ce078ae417
BLAKE2b-256 checksum
How to use checksums
cb71e62234db8253ff9c7489371f53931f51f8b69a110b4b11124fc511ebacaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / dav_utils-0.2.5-py3-none-any.whl

Download URL dav_utils-0.2.5-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f39719caa58ea2e2c43e54457633d541d246f41744c610e75b0df62b08c5e344
BLAKE2b-256 checksum
How to use checksums
6c8de3f5aea1d3159b066b1bf9954da8d97219a777ddadc605090822355c61ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Security for dav-utils 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page