Coverage for tests/test_000_frigid/test_012_docstrings.py: 100%
20 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-24 04:09 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-24 04:09 +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''' Assert correct function of docstring utilities. '''
24import pytest
26from . import PACKAGE_NAME, cache_import_module
29MODULE_QNAME = f"{PACKAGE_NAME}.__.docstrings"
32def test_100_container_init( ):
33 ''' Docstring container is a string subclass. '''
34 module = cache_import_module( MODULE_QNAME )
35 doc = module.Docstring( 'test' )
36 assert isinstance( doc, str )
37 assert 'test' == doc
40def test_200_generator_fragments( ):
41 ''' Docstring generator handles various fragment types. '''
42 class Example:
43 ''' Class docstring. '''
45 module = cache_import_module( MODULE_QNAME )
46 result = module.generate_docstring(
47 Example,
48 module.Docstring( 'Container string' ) )
49 assert 'Class docstring. \n\nContainer string' == result
52def test_210_generator_lookup( ):
53 ''' Docstring generator uses provided lookup table. '''
54 module = cache_import_module( MODULE_QNAME )
55 test_table = { 'test_key': 'Test value' }
56 result = module.generate_docstring( 'test_key', table = test_table )
57 assert 'Test value' == result
58 with pytest.raises( KeyError ):
59 module.generate_docstring( 'nonexistent', table = test_table )