Coverage for tests/test_000_accretive/test_200_objects.py: 100%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-10 04:52 +0000

1# vim: set filetype=python fileencoding=utf-8: 

2# -*- coding: utf-8 -*- 

3 

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#============================================================================# 

19 

20 

21''' Assert correct function of objects. ''' 

22 

23# mypy: ignore-errors 

24# pylint: disable=attribute-defined-outside-init 

25# pylint: disable=invalid-name,magic-value-comparison,protected-access 

26 

27 

28import pytest 

29 

30from itertools import product 

31 

32from . import ( 

33 MODULES_QNAMES, 

34 PACKAGE_NAME, 

35 cache_import_module, 

36) 

37 

38 

39THESE_MODULE_QNAMES = tuple( 

40 name for name in MODULES_QNAMES if name.endswith( '.objects' ) ) 

41THESE_CLASSES_NAMES = ( 'Object', ) 

42 

43base = cache_import_module( f"{PACKAGE_NAME}.__" ) 

44exceptions = cache_import_module( f"{PACKAGE_NAME}.exceptions" ) 

45 

46 

47@pytest.mark.parametrize( 

48 'module_qname, class_name', 

49 product( THESE_MODULE_QNAMES, THESE_CLASSES_NAMES ) 

50) 

51def test_100_instantiation( module_qname, class_name ): 

52 ''' Class instantiates. ''' 

53 module = cache_import_module( module_qname ) 

54 Object = getattr( module, class_name ) 

55 obj = Object( ) 

56 assert isinstance( obj, Object ) 

57 

58 

59@pytest.mark.parametrize( 

60 'module_qname, class_name', 

61 product( THESE_MODULE_QNAMES, THESE_CLASSES_NAMES ) 

62) 

63def test_101_accretion( module_qname, class_name ): 

64 ''' Object accretes attributes. ''' 

65 module = cache_import_module( module_qname ) 

66 Object = getattr( module, class_name ) 

67 obj = Object( ) 

68 obj.attr = 42 

69 with pytest.raises( exceptions.IndelibleAttributeError ): 

70 obj.attr = -1 

71 assert 42 == obj.attr 

72 with pytest.raises( exceptions.IndelibleAttributeError ): 

73 del obj.attr 

74 assert 42 == obj.attr 

75 

76 

77@pytest.mark.parametrize( 

78 'module_qname, class_name', 

79 product( THESE_MODULE_QNAMES, THESE_CLASSES_NAMES ) 

80) 

81def test_102_string_representation( module_qname, class_name ): 

82 ''' Object has expected string representations. ''' 

83 module = cache_import_module( module_qname ) 

84 factory = getattr( module, class_name ) 

85 obj = factory( ) 

86 assert base.calculate_fqname( obj ) in repr( obj ) 

87 

88 

89@pytest.mark.parametrize( 

90 'module_qname, class_name', 

91 product( THESE_MODULE_QNAMES, THESE_CLASSES_NAMES ) 

92) 

93def test_900_docstring_sanity( module_qname, class_name ): 

94 ''' Class has valid docstring. ''' 

95 module = cache_import_module( module_qname ) 

96 Object = getattr( module, class_name ) 

97 assert hasattr( Object, '__doc__' ) 

98 assert isinstance( Object.__doc__, str ) 

99 assert Object.__doc__ 

100 

101 

102@pytest.mark.parametrize( 

103 'module_qname, class_name', 

104 product( THESE_MODULE_QNAMES, THESE_CLASSES_NAMES ) 

105) 

106def test_902_docstring_mentions_accretion( module_qname, class_name ): 

107 ''' Class docstring mentions accretion. ''' 

108 module = cache_import_module( module_qname ) 

109 Object = getattr( module, class_name ) 

110 fragment = base.generate_docstring( 'instance attributes accretion' ) 

111 assert fragment in Object.__doc__