File: constrained_path.py

package info (click to toggle)
python-polyfactory 2.22.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,892 kB
  • sloc: python: 11,338; makefile: 103; sh: 37
file content (13 lines) | stat: -rw-r--r-- 433 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
from os.path import realpath
from pathlib import Path
from typing import Literal, cast

from faker import Faker


def handle_constrained_path(constraint: Literal["file", "dir", "new"], faker: Faker) -> Path:
    if constraint == "new":
        return cast("Path", faker.file_path(depth=1, category=None, extension=None))
    if constraint == "file":
        return Path(realpath(__file__))
    return Path(realpath(__file__)).parent