def test_link(self, tmp_path): fop = FileOps(tmp_path) # existing dest dir fop.link('from', 'to') assert fop.ops == [(Op.LINK, ('from', 'to'))] fop.clear() # non-existing dest dir dest = os.path.join('dir', 'to') fop.link('from', dest) assert fop.ops == [(Op.MKDIR, 'dir'), (Op.LINK, ('from', dest))]
def test_check_dest_dir(self, tmp_path): fop = FileOps(tmp_path) # check relative path directly in wd fop.check_dest_dir('file') assert fop.ops == [] fop.clear() # check relative path with non-existent dir fop.check_dest_dir(os.path.join('dir', 'file')) assert fop.ops == [(Op.MKDIR, 'dir')] fop.clear() dirname = os.path.join(tmp_path, 'dir') # check relative path with existent dir os.makedirs(dirname) fop.check_dest_dir(os.path.join('dir', 'file')) assert fop.ops == [] fop.clear() os.rmdir(dirname) # check abs path with non-existent dir fop.check_dest_dir(os.path.join(dirname, 'file')) assert fop.ops == [(Op.MKDIR, dirname)] fop.clear() # check absolute path with existent dir os.makedirs(dirname) fop.check_dest_dir(os.path.join(dirname, 'file')) assert fop.ops == []