def test_tag_write_append_paths(tagwrite): all_paths = tagwrite.content + ["third"] with Tag(tagwrite.path, read_only=False) as tag: tag.write(all_paths) with Tag(tagwrite.path, read_only=True) as tag: read_paths = tag.read() assert len(set(read_paths)) == len(read_paths), "Append created duplicates" assert sorted(read_paths) == sorted( all_paths), "Append wrote wrong content"
def test_tag_delete(mark, parts): basename = parts[0] name = os.path.join(*parts) tagpath = Tag.path(name) os.makedirs(os.path.dirname(tagpath), exist_ok=True, mode=0o700) with open(Tag.path(name), "w") as f: f.write("My tag content") mark.tag_delete(basename) assert not os.path.exists(Tag.path(basename))
def tagwrite(tagdir): paths = ["first", "second"] name = "test" with Tag(name, read_only=False) as tag: tag.write(paths) path = os.path.join(tagdir, name) yield collections.namedtuple("tagwrite", ["path", "content"])(path, paths)
def test_tag_read(tagwrite): with Tag(tagwrite.path, read_only=True) as tag: paths = tag.read() for path in tagwrite.content: assert path in paths
def check_tag_file_not_exists(name): assert not os.path.exists(Tag.path(name))
def check_tag_file(name, n_paths): assert os.path.isfile(Tag.path(name)), f"Tag file {name} does not exist" with Tag(name, "r") as tag: paths = tag.read() assert len(paths) == n_paths
def create_tag_with_permission(name, mode): with Tag(name, read_only=False): pass path = Tag.path(name) os.chmod(path, 0o000)
def check_tag_file(name, n_paths): with Tag(name, "r") as tag: paths = tag.read() assert len(paths) == n_paths