Skip to content

Commit

Permalink
added unittest that covers Find_Req_Files and related code in `Depe…
Browse files Browse the repository at this point in the history
…ndencyCompiler.__init__`
  • Loading branch information
telamonian committed Sep 19, 2024
1 parent bc105ad commit 1f7407f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 4 deletions.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added tests/uv/mock_comfy/setup.cfg
Empty file.
Empty file added tests/uv/mock_comfy/setup.py
Empty file.
30 changes: 26 additions & 4 deletions tests/uv/test_uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from comfy_cli.uv import DependencyCompiler

hereDir = Path(__file__).parent.resolve()
reqsDir = hereDir / "mock_requirements"
mockComfyDir = hereDir / "mock_comfy"
mockReqsDir = hereDir / "mock_requirements"

# set up a temp dir to write files to
testsDir = hereDir.parent.resolve()
Expand All @@ -27,19 +28,40 @@ def _mock_prompt_select(*args, **kwargs):
monkeypatch.setattr(ui, "prompt_select", _mock_prompt_select)


def test_find_req_files():
mockNodesDir = mockComfyDir / "custom_nodes"

knownReqFilesCore = [mockComfyDir / "pyproject.toml"]
knownReqFilesExt = sorted(
[
mockNodesDir / "x" / "requirements.txt",
mockNodesDir / "y" / "setup.cfg",
mockNodesDir / "z" / "setup.py",
]
)

depComp = DependencyCompiler(cwd=mockComfyDir)

testReqFilesCore = depComp.reqFilesCore
testReqFilesExt = sorted(depComp.reqFilesExt)

assert knownReqFilesCore == testReqFilesCore
assert knownReqFilesExt == testReqFilesExt


def test_compile(mock_prompt_select):
depComp = DependencyCompiler(
cwd=temp,
gpu=GPU_OPTION.AMD,
outDir=temp,
reqFilesCore=[reqsDir / "core_reqs.txt"],
reqFilesExt=[reqsDir / "x_reqs.txt", reqsDir / "y_reqs.txt"],
reqFilesCore=[mockReqsDir / "core_reqs.txt"],
reqFilesExt=[mockReqsDir / "x_reqs.txt", mockReqsDir / "y_reqs.txt"],
)

depComp.make_override()
depComp.compile_core_plus_ext()

with open(reqsDir / "requirements.compiled", "r") as known, open(temp / "requirements.compiled", "r") as test:
with open(mockReqsDir / "requirements.compiled", "r") as known, open(temp / "requirements.compiled", "r") as test:
# compare all non-commented lines in generated file vs reference file
knownLines, testLines = [
[line for line in known.readlines() if not line.strip().startswith("#")],
Expand Down

0 comments on commit 1f7407f

Please sign in to comment.