Coverage for tests/test_000_emcd_projects/__init__.py: 100%
20 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-24 01:25 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-24 01:25 +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 Common imports, constants, and utilities for tests.
24'''
27from types import MappingProxyType as DictionaryProxy
30PACKAGE_NAME = 'emcd_projects'
31PACKAGES_NAMES = ( PACKAGE_NAME, )
34_modules_cache = { }
35def cache_import_module( qname ):
36 ''' Imports module from package by name and caches it. '''
37 from importlib import import_module
38 package_name, *maybe_module_name = qname.rsplit( '.', maxsplit = 1 )
39 if not maybe_module_name: arguments = ( qname, )
40 else: arguments = ( f".{maybe_module_name[0]}", package_name, )
41 if qname not in _modules_cache:
42 _modules_cache[ qname ] = import_module( *arguments )
43 return _modules_cache[ qname ]
46def _discover_module_names( package_name ):
47 from pathlib import Path
48 package = cache_import_module( package_name )
49 return tuple(
50 path.stem
51 for path in Path( package.__file__ ).parent.glob( '*.py' )
52 if '__init__.py' != path.name and path.is_file( ) )
55MODULES_NAMES_BY_PACKAGE_NAME = DictionaryProxy( {
56 name: _discover_module_names( name ) for name in PACKAGES_NAMES } )
57PACKAGES_NAMES_BY_MODULE_QNAME = DictionaryProxy( {
58 f"{subpackage_name}.{module_name}": subpackage_name
59 for subpackage_name in PACKAGES_NAMES
60 for module_name in MODULES_NAMES_BY_PACKAGE_NAME[ subpackage_name ] } )
61MODULES_QNAMES = tuple( PACKAGES_NAMES_BY_MODULE_QNAME.keys( ) )
62MODULES_NAMES_BY_MODULE_QNAME = DictionaryProxy( {
63 name: name.rsplit( '.', maxsplit = 1 )[ -1 ]
64 for name in PACKAGES_NAMES_BY_MODULE_QNAME.keys( ) } )