File: expected.py

package info (click to toggle)
python-scrapli 2023.7.30-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,536 kB
  • sloc: python: 14,459; makefile: 72
file content (25 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
from pathlib import Path

PYTEST_CURRENT_TEST = "PYTEST_CURRENT_TEST"


def write_expected(f: str, result: str):
    expected_dir = Path(os.path.abspath(f)).parent

    current_test = os.getenv(PYTEST_CURRENT_TEST).split("::")[-1].split(" ")[0]

    with open(f"{expected_dir}/expected/{current_test}", "w") as out:
        out.write(result)


def get_expected(f: str) -> str:
    expected_dir = Path(os.path.abspath(f)).parent

    current_test = os.getenv(PYTEST_CURRENT_TEST).split("::")[-1].split(" ")[0]

    try:
        with open(f"{expected_dir}/expected/{current_test}", "r") as out:
            return out.read()
    except NotADirectoryError:
        return ""