def test_write_bytes(): path = "./tests/fixtures/bytes" write(random_bytes, path) content = io.open(path, "rb").read() assert os.path.isfile(path) assert content == random_bytes
def test_write_scope(): target_path = "./tests/fixtures/write_scope.txt" if os.path.exists(target_path): os.remove(target_path) with io_scope("./tests/fixtures"): write("test", "write_scope.txt", mode="w") assert os.path.isfile(target_path)
def test_write_text(): text = u"The quick brown fox jumps over the lazy 🐕" path = "./tests/fixtures/string.txt" write(text, path, mode="w") content = io.open(path, "rt").read() assert os.path.isfile(path) assert content == text
def export_mesh(name, mesh): data_to_save = { 'position': mesh['position'].ravel(), 'uv': mesh['uv'].ravel(), 'face': np.uint32(mesh['face'].ravel()) } for key, value in data_to_save.items(): data = value.tobytes() filename = '%s_%s.3d'%(name, key) write(data, filename)
def _read_and_cache(url): local_name = RESERVED_PATH_CHARS.sub('_', url) local_path = os.path.join(gettempdir(), local_name) if os.path.exists(local_path): log.info("Found cached file '%s'.", local_path) return _handle_gfile(local_path) else: log.info("Caching URL '%s' locally at '%s'.", url, local_path) data = read(url, cache=False) # important to avoid endless loop write(data, local_path) return BytesIO(data)
def test_set_write_scopes(): target_path = "./tests/fixtures/write_scope5.txt" if os.path.exists(target_path): os.remove(target_path) # fake write scopes, such as when called on a remote worker: _old_scopes = scoping.io_scopes scoping.io_scopes = ["./tests", "fixtures"] write("test", "write_scope5.txt", mode="w") assert os.path.isfile(target_path) # restore write scopes for later tests scoping.io_scopes = _old_scopes
def save_json(object, url, indent=2): """Save object as json on CNS.""" obj_json = json.dumps(object, indent=indent) write(obj_json, url, 'w')