def _set_output(self, output_data): # IO object. self._resource = None if not output_data: self._output = None if self.resource_path is not None: self._resource = get_storage(self.resource_path) self._output_file = None return if hasattr(output_data, 'write'): self._output = output_data if self.resource_path is not None: self._resource = get_storage(self.resource_path) self._output_file = None return # Else save to a file. if not output_data.endswith('/') and os.path.isdir(output_data): output_data += '/' self._output = get_storage(os.path.dirname(output_data)) if self.resource_path is not None: self._resource = get_storage(self._output.url(self.resource_path)) self._output_file = os.path.basename(output_data) if not self._output_file: if self._input: basename = os.path.splitext(os.path.basename(self._input))[0] self._output_file = basename + '.svg' else: raise ValueError('Invalid output: {}'.format(output_data))
def _load_storage(self, url): storage = get_storage(os.path.dirname(url)) filename = os.path.basename(url) logger.debug('Opening {}'.format(url)) with storage.open(filename) as f: self._load_stream(f) self._input = url
def test_file_readwrite(tmpdir, key, value): storage = get_storage(tmpdir.dirname) storage.put(key, value) assert storage.exists(key) assert storage.get(key) == value with storage.open(key) as f: assert f.read() == value storage.delete(key) assert not storage.exists(key)
def test_url_read(url, key): storage = get_storage(url) assert storage.exists(key) assert storage.get(key) with storage.open(key) as f: assert f.read()