Skip to content

Commit c91dc97

Browse files
committed
Add failed test for inherits = ".." in user-defined benchmarks.
1 parent 69f3b19 commit c91dc97

File tree

7 files changed

+57
-20
lines changed

7 files changed

+57
-20
lines changed

pyperformance/tests/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import contextlib
22
import errno
33
import os
4+
import subprocess
5+
import sys
46
import tempfile
57

8+
DATA_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data'))
9+
10+
11+
def run_cmd(cmd):
12+
print("Execute: %s" % ' '.join(cmd))
13+
proc = subprocess.Popen(cmd)
14+
try:
15+
proc.wait()
16+
except: # noqa
17+
proc.kill()
18+
proc.wait()
19+
raise
20+
21+
exitcode = proc.returncode
22+
if exitcode:
23+
sys.exit(exitcode)
24+
625

726
@contextlib.contextmanager
827
def temporary_file(**kwargs):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[benchmarks]
2+
3+
name metafile
4+
1 <local>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[project]
2+
dynamic = ["name"]
3+
version = "1.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[project]
2+
name = "test_bm_1"
3+
requires-python = ">=3.8"
4+
dependencies = ["pyperf"]
5+
urls = { repository = "https://github.com/python/pyperformance" }
6+
dynamic = ["version"]
7+
8+
[tool.pyperformance]
9+
name = "1"
10+
tags = "test"
11+
inherits = ".."

pyperformance/tests/test_compare.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,7 @@
77
import unittest
88

99
from pyperformance import tests
10-
11-
12-
DATA_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data'))
13-
14-
15-
def run_cmd(cmd):
16-
print("Execute: %s" % ' '.join(cmd))
17-
proc = subprocess.Popen(cmd)
18-
try:
19-
proc.wait()
20-
except: # noqa
21-
proc.kill()
22-
proc.wait()
23-
raise
24-
25-
exitcode = proc.returncode
26-
if exitcode:
27-
sys.exit(exitcode)
10+
from pyperformance.tests import run_cmd, DATA_DIR
2811

2912

3013
class CompareTests(unittest.TestCase):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os.path
2+
import sys
3+
import unittest
4+
5+
from pyperformance.tests import DATA_DIR, run_cmd
6+
7+
USER_DEFINED_MANIFEST = os.path.join(DATA_DIR, 'user_defined_bm', 'MANIFEST')
8+
9+
10+
class TestBM(unittest.TestCase):
11+
def test_user_defined_bm(self):
12+
cmd = [sys.executable, '-m', 'pyperformance', 'run', f'--manifest={USER_DEFINED_MANIFEST}']
13+
14+
run_cmd(cmd)
15+
16+
17+
if __name__ == "__main__":
18+
unittest.main()

runtests.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ def run_bench(*cmd):
7777

7878
def main():
7979
# Unit tests
80-
cmd = [sys.executable, '-u',
81-
os.path.join('pyperformance', 'tests', 'test_compare.py')]
80+
cmd = [sys.executable, '-u', '-m', 'unittest']
8281
run_cmd(cmd)
8382

8483
# Functional tests

0 commit comments

Comments
 (0)