def test_streamlit_read_zero_bytes(self): """Test streamlit.util.streamlit.read.""" self.os_stat.return_value.st_size = 0 with pytest.raises(util.Error) as e: with util.streamlit_read(FILENAME) as input: data = input.read() self.assertEqual(str(e.value), 'Read zero byte file: "/some/cache/file"')
def read_from_disk_cache(key): path = util.get_streamlit_file_path('cache', '%s.pickle' % key) try: with util.streamlit_read(path, binary=True) as input: rv = pickle.load(input) LOGGER.debug('Cache HIT: ' + str(type(rv))) except util.Error as e: LOGGER.debug(e) raise CacheError('Unable to read from cache: %s' % e) return rv
def _read_from_disk_cache(key): path = util.get_streamlit_file_path("cache", "%s.pickle" % key) try: with util.streamlit_read(path, binary=True) as input: value, args_mutated = pickle.load(input) LOGGER.debug("Disk cache HIT: %s", type(value)) except util.Error as e: LOGGER.error(e) raise CacheError("Unable to read from cache: %s" % e) except (OSError, FileNotFoundError): # Python 2 # Python 3 raise CacheKeyNotFoundError("Key not found in disk cache") return value, args_mutated
def _read_from_disk_cache(key): path = util.get_streamlit_file_path('cache', '%s.pickle' % key) try: with util.streamlit_read(path, binary=True) as input: value, args_mutated = pickle.load(input) LOGGER.debug('Disk cache HIT: %s', type(value)) except util.Error as e: LOGGER.error(e) raise CacheError('Unable to read from cache: %s' % e) except ( OSError, # Python 2 FileNotFoundError # Python 3 ): raise CacheKeyNotFoundError('Key not found in disk cache') return value, args_mutated
def test_streamlit_read_binary(self): """Test streamlit.util.streamlit.read.""" with util.streamlit_read(FILENAME, binary=True) as input: data = input.read() self.assertEqual(b"\xaa\xbb", data)
def test_streamlit_read(self): """Test streamlit.util.streamlit.read.""" with util.streamlit_read(FILENAME) as input: data = input.read() self.assertEqual("data", data)