from pathlib import Path

# File with rw access
assert choose_file(["foo", "~/.bashrc"]) == Path("~/.bashrc").expanduser()
# Folder with rwx access
assert choose_folder(["foo/bar", "/proc", "~"]) == Path("~").expanduser()
# Folder with rwx or creatable
assert (
    choose_folder(
        ["/non/existing/path", "/foo", "/bar"],
        read=True,
        write=True,
        open=True,
        creatable=True,
    )
    is None
)
# First is non-existing and not creatable
assert choose_tmp(["/foo/bar", "/tmp", "/tmp/jobid"]) == Path("/tmp")
assert choose_tmp(["/foo/bar", "/tmp/$USER", "/tmp/"]) == Path("/tmp/$USER")
# First is non-existing but creatable
assert choose_tmp(["foo/bar", "/tmp"]) == Path("foo/bar")
# None is valid
assert choose_tmp(["/foo", "/bar"]) == "system_tmpdir"


rule a:
    input:
        "test2.txt",
    output:
        "test.txt",
    shell:
        "echo {resources.tmpdir} > {output}"


rule b:
    output:
        "test2.txt",
    shell:
        "echo {resources.tmpdir} $TMPDIR $TEMP $TMP $TEMPDIR > {output}"
