File: conftest.py

package info (click to toggle)
python-openapi-spec-validator 0.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 772 kB
  • sloc: python: 2,050; makefile: 54
file content (38 lines) | stat: -rw-r--r-- 986 bytes parent folder | download
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
26
27
28
29
30
31
32
33
34
35
36
37
38
from os import path
from pathlib import PurePath
from urllib.parse import urlunparse

import pytest
from jsonschema_path.handlers.file import FilePathHandler
from jsonschema_path.handlers.urllib import UrllibHandler


def spec_file_url(spec_file, schema="file"):
    directory = path.abspath(path.dirname(__file__))
    full_path = path.join(directory, spec_file)
    return urlunparse((schema, None, full_path, None, None, None))


def spec_from_file(spec_file):
    directory = path.abspath(path.dirname(__file__))
    path_full = path.join(directory, spec_file)
    uri = PurePath(path_full).as_uri()
    return FilePathHandler()(uri)


def spec_from_url(spec_url):
    return UrllibHandler("http", "https")(spec_url)


class Factory(dict):
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__


@pytest.fixture
def factory():
    return Factory(
        spec_file_url=spec_file_url,
        spec_from_file=spec_from_file,
        spec_from_url=spec_from_url,
    )