Skip to content

Commit

Permalink
chore: stabilize tests on main
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeo committed Jul 31, 2022
1 parent b3a0cb8 commit e2c971c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 42 deletions.
57 changes: 36 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ PyYAML = "^6.0"
pytest = "^7.1.2"
pre-commit = "^2.20.0"
commitizen = "^2.29.2"
pytest-httpserver = "^1.0.5"

[tool.commitizen]
name = "cz_conventional_commits"
Expand Down
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import mimetypes

from werkzeug.wrappers import Request
from werkzeug.wrappers import Response


def file_handler(path: str):
with open("confs/simple.json", "r") as f:
data = f.read()

def handler(request: Request):
return Response(data, mimetype=mimetypes.guess_type(path)[0])

return handler
43 changes: 22 additions & 21 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from dataconf.main import url
from dateutil.relativedelta import relativedelta
import pytest
from pytest_httpserver import HTTPServer
from tests.conftest import file_handler

PARENT_DIR = os.path.normpath(
os.path.dirname(os.path.realpath(__file__)) + os.sep + os.pardir
Expand Down Expand Up @@ -602,27 +604,21 @@ class A:

assert file("confs/simple.yaml", A) == A(hello="bonjour", foo=["bar"])

def test_yaml_url(self) -> None:
@dataclass
class Repo:
repo: str
rev: str

def test_yaml_url(self, httpserver: HTTPServer) -> None:
@dataclass
class A:
repos: List[Repo]

assert (
len(
url(
"https://raw.githubusercontent.com/zifeo/dataconf/main/.pre-commit-config.yaml",
A,
ignore_unexpected=True,
).repos
)
> 0
hello: Text
foo: List[str]

httpserver.expect_request("/simple.yaml").respond_with_handler(
file_handler("confs/simple.yaml")
)

assert url(
httpserver.url_for("/simple.yaml"),
A,
) == A(hello="bonjour", foo=["bar"])

def test_json_file(self) -> None:
@dataclass
class A:
Expand All @@ -631,11 +627,16 @@ class A:

assert file("confs/simple.json", A) == A(hello="bonjour", foo=["bar"])

def test_json_url(self) -> None:
def test_json_url(self, httpserver: HTTPServer) -> None:
@dataclass
class A:
hello: Text
foo: List[str]

assert url(
"https://raw.githubusercontent.com/zifeo/dataconf/main/confs/simple.json", A
) == A(hello="bonjour")
httpserver.expect_request("/simple.json").respond_with_handler(
file_handler("confs/simple.json")
)

assert url(httpserver.url_for("/simple.json"), A) == A(
hello="bonjour", foo=["bar"]
)

0 comments on commit e2c971c

Please sign in to comment.