Coverage for tests/test_000_absence/test_200_installers.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-21 04:54 +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 builtin installation. ''' 

22 

23# pylint: disable=no-member,redefined-outer-name,unused-argument 

24 

25 

26import builtins 

27 

28import pytest 

29 

30from . import PACKAGE_NAME, cache_import_module 

31 

32 

33@pytest.fixture 

34def cleanup_builtins( ): 

35 ''' Remove test attributes from builtins after test. ''' 

36 yield 

37 for name in ( 'Absent', 'isabsent', 'CustomAbsent', 'custom_absent' ): 

38 if hasattr( builtins, name ): 

39 delattr( builtins, name ) 

40 

41 

42def test_100_default_install( cleanup_builtins ): 

43 ''' Default installation works. ''' 

44 module = cache_import_module( f"{PACKAGE_NAME}.installers" ) 

45 objects = cache_import_module( f"{PACKAGE_NAME}.objects" ) 

46 module.install( ) 

47 assert hasattr( builtins, 'Absent' ) 

48 assert hasattr( builtins, 'isabsent' ) 

49 assert objects.absent is builtins.Absent 

50 assert objects.is_absent is builtins.isabsent 

51 

52 

53def test_101_custom_install( cleanup_builtins ): 

54 ''' Custom installation works. ''' 

55 module = cache_import_module( f"{PACKAGE_NAME}.installers" ) 

56 objects = cache_import_module( f"{PACKAGE_NAME}.objects" ) 

57 module.install( 

58 sentinel_name = 'CustomAbsent', 

59 predicate_name = 'custom_absent', 

60 ) 

61 assert hasattr( builtins, 'CustomAbsent' ) 

62 assert hasattr( builtins, 'custom_absent' ) 

63 assert objects.absent is builtins.CustomAbsent 

64 assert objects.is_absent is builtins.custom_absent 

65 

66 

67def test_102_partial_install( cleanup_builtins ): 

68 ''' Partial installation works. ''' 

69 module = cache_import_module( f"{PACKAGE_NAME}.installers" ) 

70 module.install( sentinel_name = None ) 

71 assert not hasattr( builtins, 'Absent' ) 

72 assert hasattr( builtins, 'isabsent' ) 

73 delattr( builtins, 'isabsent' ) 

74 module.install( predicate_name = None ) 

75 assert hasattr( builtins, 'Absent' ) 

76 assert not hasattr( builtins, 'isabsent' )