<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import os <EOL> import shutil <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . mock import NO_MOCK , NO_MOCK_REASON <EOL> from salt . utils . cache import context_cache <EOL> import salt . payload <EOL> import salt . utils <EOL> __context__ = { '<STR_LIT:a>' : '<STR_LIT:b>' } <EOL> __opts__ = { '<STR_LIT>' : '<STR_LIT>' } <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class ContextCacheTest ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> def setUp ( self ) : <EOL> '''<STR_LIT>''' <EOL> context_dir = os . path . join ( __opts__ [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if os . path . isdir ( context_dir ) : <EOL> shutil . rmtree ( context_dir ) <EOL> def test_set_cache ( self ) : <EOL> '''<STR_LIT>''' <EOL> @ context_cache <EOL> def _test_set_cache ( ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> _test_set_cache ( ) <EOL> target_cache_file = os . path . join ( __opts__ [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' . format ( __name__ ) ) <EOL> self . assertTrue ( os . path . isfile ( target_cache_file ) , '<STR_LIT>' ) <EOL> with salt . utils . fopen ( target_cache_file , '<STR_LIT:rb>' ) as fp_ : <EOL> target_cache_data = salt . payload . Serial ( __opts__ ) . load ( fp_ ) <EOL> self . assertDictEqual ( __context__ , target_cache_data ) <EOL> cc = salt . utils . cache . ContextCache ( __opts__ , __name__ ) <EOL> retrieved_cache = cc . get_cache_context ( ) <EOL> self . assertDictEqual ( retrieved_cache , __context__ ) <EOL> def test_refill_cache ( self ) : <EOL> '''<STR_LIT>''' <EOL> @ context_cache <EOL> def _test_set_cache ( ) : <EOL> pass <EOL> _test_set_cache ( ) <EOL> @ context_cache <EOL> def _test_refill_cache ( comparison_context ) : <EOL> self . assertEqual ( __context__ , comparison_context ) <EOL> global __context__ <EOL> __context__ = { } <EOL> _test_refill_cache ( { '<STR_LIT:a>' : '<STR_LIT:b>' } ) </s>
