Beispiel #1
0
 def _create_tmp_cache_file(self, tmp_dir, serializer):
     """
     Helper function that creates a temporary cache file using localfs.store. This
     is to used to create DRY unit tests for the localfs cache.
     """
     with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
         with patch.dict(localfs.__context__, {"serial": serializer}):
             localfs.store(bank="bank", key="key", data="payload data")
Beispiel #2
0
 def _create_tmp_cache_file(self, tmp_dir, serializer):
     '''
     Helper function that creates a temporary cache file using localfs.store. This
     is to used to create DRY unit tests for the localfs cache.
     '''
     with patch.dict(localfs.__opts__, {'cachedir': tmp_dir}):
         with patch.dict(localfs.__context__, {'serial': serializer}):
             localfs.store(bank='bank', key='key', data='payload data')
 def _create_tmp_cache_file(self, tmp_dir):
     """
     Helper function that creates a temporary cache file using localfs.store. This
     is to used to create DRY unit tests for the localfs cache.
     """
     self.addCleanup(shutil.rmtree, tmp_dir)
     with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
         localfs.store(bank="bank", key="key", data="payload data", cachedir=tmp_dir)
    def test_mix_of_utf8_and_non_utf8_can_be_round_tripped(self):

        tmp_dir = tempfile.mkdtemp(dir=RUNTIME_VARS.TMP)

        data = {
            # Any unicode, which ideally is invalid ascii.
            "unicode": "áéí",
            # Any bytes so long as they're not valid utf-8
            "bytes": b"\xfe\x99\x00\xff",
        }
        bank = "bank"
        key = "key"

        self.addCleanup(shutil.rmtree, tmp_dir)
        with patch.dict(localfs.__opts__, {"cachedir": tmp_dir}):
            localfs.store(bank, key, data, tmp_dir)

            actual = localfs.fetch(bank, key, tmp_dir)

        self.assertEqual(data, actual)