Coverage for tests/test_000_accretive/__init__.py: 100%
22 statements
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-06 17:17 +0000
« prev ^ index » next coverage.py v7.5.4, created at 2024-07-06 17:17 +0000
1# vim: set filetype=python fileencoding=utf-8:
2# -*- coding: utf-8 -*-
4#============================================================================#
5# #
6# Licensed under the Apache License, Version 2.0 (the "License"); #
7# you may not use this file except in compliance with the License. #
8# You may obtain a copy of the License at #
9# #
10# http://www.apache.org/licenses/LICENSE-2.0 #
11# #
12# Unless required by applicable law or agreed to in writing, software #
13# distributed under the License is distributed on an "AS IS" BASIS, #
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15# See the License for the specific language governing permissions and #
16# limitations under the License. #
17# #
18#============================================================================#
21''' Package of tests. '''
23# mypy: ignore-errors
24# pylint: disable=magic-value-comparison
27from types import MappingProxyType as DictionaryProxy
30PACKAGE_NAME = 'accretive'
31PACKAGES_NAMES = (
32 PACKAGE_NAME,
33 *( f"{PACKAGE_NAME}.{name}" for name
34 in ( 'concealment', 'protection', 'complete' ) )
35)
36CONCEALMENT_PACKAGES_NAMES = tuple(
37 f"{PACKAGE_NAME}.{name}" for name in ( 'concealment', 'complete', ) )
38PROTECTION_PACKAGES_NAMES = tuple(
39 f"{PACKAGE_NAME}.{name}" for name in ( 'protection', 'complete', ) )
42_modules_cache = { }
43def cache_import_module( qname ):
44 ''' Imports module from package by name and caches it. '''
45 from importlib import import_module
46 package_name, *maybe_module_name = qname.rsplit( '.', maxsplit = 1 )
47 if not maybe_module_name: arguments = ( qname, )
48 else: arguments = ( f".{maybe_module_name[0]}", package_name, )
49 if qname not in _modules_cache:
50 _modules_cache[ qname ] = import_module( *arguments )
51 return _modules_cache[ qname ]
54def _discover_module_names( package_name ):
55 from pathlib import Path
56 package = cache_import_module( package_name )
57 return tuple( path.stem
58 for path in Path( package.__file__ ).parent.glob( '*.py' )
59 if '__init__.py' != path.name and path.is_file( ) )
61MODULES_NAMES_BY_PACKAGE_NAME = DictionaryProxy( {
62 name: _discover_module_names( name ) for name in PACKAGES_NAMES } )
63PACKAGES_NAMES_BY_MODULE_QNAME = DictionaryProxy( {
64 f"{subpackage_name}.{module_name}": subpackage_name
65 for subpackage_name in PACKAGES_NAMES
66 for module_name in MODULES_NAMES_BY_PACKAGE_NAME[ subpackage_name ] } )
67MODULES_QNAMES = tuple( PACKAGES_NAMES_BY_MODULE_QNAME.keys( ) )
68MODULES_NAMES_BY_MODULE_QNAME = DictionaryProxy( {
69 name: name.rsplit( '.', maxsplit = 1 )[ -1 ]
70 for name in PACKAGES_NAMES_BY_MODULE_QNAME.keys( ) } )