-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpseudo_builder_test.py
More file actions
88 lines (73 loc) · 2.49 KB
/
pseudo_builder_test.py
File metadata and controls
88 lines (73 loc) · 2.49 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import annotations
import shutil
import subprocess
import venv
from dataclasses import dataclass
from pathlib import Path
from unittest import TestCase
ITEST_VENV_PATH = Path("venv-itest")
@dataclass
class PackageTestCase:
name: str
git_url: str
version_args: str | None = None
version_output: str | None = None
PACKAGE_TEST_CASES = [
PackageTestCase(
"stylua",
"git+https://github.com/JohnnyMorganz/StyLua@v2.3.0",
"--version",
"stylua 2.3.0",
),
PackageTestCase(
"hadolint",
# Contrived test relying on git tags
"git+https://github.com/IamTheFij/hadolint@v2.13.1",
"--version",
"Haskell Dockerfile Linter 2.13.1",
),
PackageTestCase(
"hadolint",
# Contrived test for cabal version
"git+https://github.com/IamTheFij/hadolint@v2.12.0",
"--version",
"Haskell Dockerfile Linter 2.12.0",
),
]
class TestPseudoBuilder(TestCase):
def setUp(self):
venv.create(
ITEST_VENV_PATH,
system_site_packages=False,
clear=True,
with_pip=True,
)
self.pip_install("-e", ".[builder]")
def tearDown(self):
shutil.rmtree(ITEST_VENV_PATH)
def pip_install(self, *args: str):
subprocess.run(
[str(ITEST_VENV_PATH.joinpath("bin", "pip")), "install", *args],
check=True,
)
def test_install_remote_package(self):
self.assertTrue(ITEST_VENV_PATH.exists())
self.assertTrue(ITEST_VENV_PATH.joinpath("bin", "python").exists())
self.assertTrue(ITEST_VENV_PATH.joinpath("bin", "pip").exists())
for package in PACKAGE_TEST_CASES:
self.pip_install("--no-index", "--no-build-isolation", package.git_url)
# Check if the package is installed
assert ITEST_VENV_PATH.joinpath("bin", package.name).exists()
# Check if the package has executable permissions
assert ITEST_VENV_PATH.joinpath("bin", package.name).stat().st_mode & 0o111
result = subprocess.run(
[
str(ITEST_VENV_PATH.joinpath("bin", package.name)),
*(package.version_args.split() if package.version_args else []),
],
capture_output=True,
text=True,
check=True,
)
if package.version_output:
self.assertIn(package.version_output, result.stdout)