Skip to content

Commit

Permalink
get refactored tests working
Browse files Browse the repository at this point in the history
  • Loading branch information
znd4 committed Nov 15, 2023
1 parent 7ba63e9 commit 8028441
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,8 @@ known_first_party = ["pdm_dotenv"]

[tool.pytest.ini_options]
filterwarnings = ["ignore::DeprecationWarning"]
addopts = [
# "-ra",
# "-q",
]
testpaths = ["tests"]
36 changes: 28 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pdm.cli.actions import textwrap
from pdm.project import Project
import pathlib
import tempfile
from typing import TYPE_CHECKING, Tuple
import toml

Expand All @@ -9,19 +11,24 @@

def check_env(project: Project, pdm: "PDMCallable", environ: Tuple[Tuple[str, str]]) -> None:
for key, val in environ:
assert (
val
== pdm(
with tempfile.NamedTemporaryFile() as f:
fp = pathlib.Path(f.name)
pdm(
[
"run",
"python",
"-c",
f"import os; print(os.environ['{key}'])",
textwrap.dedent(
f"""
import os, pathlib
pathlib.Path({f.name!r}).write_text(os.environ.get({key!r}, ""))
"""
),
],
strict=True,
obj=project,
).stdout
)
)
assert val == fp.read_text().strip()


def test_build(project: Project, pdm: "PDMCallable") -> None:
Expand Down Expand Up @@ -66,7 +73,19 @@ def test_build(project: Project, pdm: "PDMCallable") -> None:
def test_happy_path(project: Project, pdm: "PDMCallable") -> None:
environ = (("FOO_BAR_BAZ", "hello"),)
for key, val in environ:
pdm(["run", "dotenv", "set", key, val])
pdm(
[
"run",
"dotenv",
f"--file={project.root / '.env'}",
"set",
key,
val,
],
obj=project,
strict=True,
)
print((project.root / ".env").read_text())

check_env(project, pdm, environ)

Expand All @@ -78,12 +97,13 @@ def test_different_file(project: Project, pdm: "PDMCallable") -> None:
[
"run",
"dotenv",
f"--file={'.foo.env'}",
f"--file={project.root / '.foo.env'}",
"set",
key,
val,
],
obj=project,
strict=True,
)
pdm(
[
Expand Down

0 comments on commit 8028441

Please sign in to comment.