def test_download(): d = img.get_local_dir() # assert img.download() assert os.path.exists(img.get_local_path()) shutil.rmtree(d) # img.make_dirs() fs.touch(os.path.join(d, image.SKIP)) assert img.download() is False assert not os.path.exists(img.get_local_path())
def test_touch(self): assert fs.remove_file_silently(cfg.TMP_FILE) # assert fs.touch(cfg.TMP_FILE) assert os.path.exists(cfg.TMP_FILE) # assert fs.remove_file_silently(cfg.TMP_FILE) assert fs.touch(cfg.TMP_FILE, mode=0644) assert fs.get_oct_mode(cfg.TMP_FILE) == '0644' # assert fs.remove_file_silently(cfg.TMP_FILE)
def test_chdir(): tmp_file = os.path.join("/tmp", TEST) assert not os.path.isfile(tmp_file) with ChDir("/tmp"): fs.touch(TEST) assert os.path.isfile(tmp_file) os.unlink(tmp_file) assert not os.path.isfile(tmp_file) # assert not os.path.isfile(TEST) fs.touch(TEST) assert os.path.isfile(TEST) os.unlink(TEST) assert not os.path.isfile(TEST)
def test_get_oct_mode(self): assert fs.remove_file_silently(cfg.TMP_FILE) # assert fs.touch(cfg.TMP_FILE, mode=0755) assert fs.get_oct_mode(cfg.TMP_FILE) == '0755' # assert fs.remove_file_silently(cfg.TMP_FILE)
def test_set_mode_to(self): assert fs.remove_file_silently(cfg.TMP_FILE) # assert fs.touch(cfg.TMP_FILE, mode=0600) assert fs.get_oct_mode(cfg.TMP_FILE) == '0600' assert fs.set_mode_to(cfg.TMP_FILE, 0755) assert fs.set_mode_to(cfg.TMP_FILE, 0700) # assert fs.remove_file_silently(cfg.TMP_FILE)
# from jabbapylib.cmanagers.cmanagers import ChDir """ import os from jabbapylib.filesystem import fs class ChDir(object): """ Step into a directory temporarily. """ def __init__(self, path): self.old_dir = os.getcwd() self.new_dir = path def __enter__(self): os.chdir(self.new_dir) def __exit__(self, *args): os.chdir(self.old_dir) ############################################################################## if __name__ == "__main__": with ChDir("/tmp/test"): fs.touch("test.txt") # fs.touch("here.txt")
Context managers. # from jabbapylib.cmanagers.cmanagers import ChDir """ import os from jabbapylib.filesystem import fs class ChDir(object): """ Step into a directory temporarily. """ def __init__(self, path): self.old_dir = os.getcwd() self.new_dir = path def __enter__(self): os.chdir(self.new_dir) def __exit__(self, *args): os.chdir(self.old_dir) ############################################################################## if __name__ == "__main__": with ChDir("/tmp/test"): fs.touch("test.txt") # fs.touch("here.txt")
def test_remove_file_silently(self): fname = '/stupid_directory_name/doesnt_exist.txt' assert fs.remove_file_silently(fname) assert fs.touch(cfg.TMP_FILE) assert os.path.exists(cfg.TMP_FILE) assert fs.remove_file_silently(cfg.TMP_FILE)