Skip to content

Commit c9908d7

Browse files
committed
test: benchmark improvements
1 parent 0973f44 commit c9908d7

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

benchmark/benchmark.py

+40-3
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,15 @@ class ProjectToTest:
191191

192192
# Where can we clone the project from?
193193
git_url: str = ""
194+
local_git: str = ""
194195
slug: str = ""
195196
env_vars: Env_VarsType = {}
196197

197198
def __init__(self) -> None:
198-
url_must_exist(self.git_url)
199+
if self.git_url:
200+
url_must_exist(self.git_url)
201+
if self.local_git:
202+
file_must_exist(self.local_git)
199203
if not self.slug:
200204
if self.git_url:
201205
self.slug = self.git_url.split("/")[-1]
@@ -211,12 +215,13 @@ def make_dir(self) -> None:
211215

212216
def get_source(self, shell: ShellSession, retries: int = 5) -> None:
213217
"""Get the source of the project."""
218+
git_source = self.local_git or self.git_url
214219
for retry in range(retries):
215220
try:
216-
shell.run_command(f"git clone {self.git_url} {self.dir}")
221+
shell.run_command(f"git clone {git_source} {self.dir}")
217222
return
218223
except Exception as e:
219-
print(f"Retrying to clone {self.git_url} due to error:\n{e}")
224+
print(f"Retrying to clone {git_source} due to error:\n{e}")
220225
if retry == retries - 1:
221226
raise e
222227

@@ -423,6 +428,38 @@ def __init__(self, more_pytest_args: str = ""):
423428
self.slug = "mashbranch"
424429

425430

431+
class ProjectPillow(ProjectToTest):
432+
git_url = "https://github.com/python-pillow/Pillow"
433+
local_git = "/src/Pillow"
434+
435+
def __init__(self, more_pytest_args: str = ""):
436+
super().__init__()
437+
self.more_pytest_args = more_pytest_args
438+
439+
def prep_environment(self, env: Env) -> None:
440+
env.shell.run_command(f"{env.python} -m pip install '.[tests]'")
441+
442+
def run_no_coverage(self, env: Env) -> float:
443+
env.shell.run_command(f"{env.python} -m pytest {self.more_pytest_args}")
444+
return env.shell.last_duration
445+
446+
def run_with_coverage(self, env: Env, cov_ver: Coverage) -> float:
447+
env.shell.run_command(f"{env.python} -m pip install {cov_ver.pip_args}")
448+
env.shell.run_command(
449+
f"{env.python} -m pytest --cov=PIL --cov=Tests {self.more_pytest_args}"
450+
)
451+
duration = env.shell.last_duration
452+
report = env.shell.run_command(f"{env.python} -m coverage report --precision=6")
453+
print("Results:", report.splitlines()[-1])
454+
return duration
455+
456+
457+
class ProjectPillowBranch(ProjectPillow):
458+
def __init__(self, more_pytest_args: str = ""):
459+
super().__init__(more_pytest_args="--cov-branch " + more_pytest_args)
460+
self.slug = "Pilbranch"
461+
462+
426463
class ProjectOperator(ProjectToTest):
427464
git_url = "https://github.com/nedbat/operator"
428465

benchmark/run.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,15 @@
107107
CoverageSource(slug="sysmon", env_vars={"COVERAGE_CORE": "sysmon"}),
108108
],
109109
projects=[
110+
ProjectPillow(), #"-k test_pickle"),
111+
ProjectPillowBranch(), #"-k test_pickle"),
110112
# ProjectSphinx(), # Works, slow
111113
# ProjectPygments(), # Doesn't work on 3.14
112114
# ProjectRich(), # Doesn't work
113115
# ProjectTornado(), # Works, tests fail
114116
# ProjectDulwich(), # Works
115117
# ProjectBlack(), # Works, slow
116-
ProjectMpmath(), # Works, slow
118+
# ProjectMpmath(), # Works, slow
117119
# ProjectMypy(), # Works, slow
118120
# ProjectHtml5lib(), # Doesn't work on 3.14
119121
# ProjectUrllib3(), # Works

0 commit comments

Comments
 (0)