-
Notifications
You must be signed in to change notification settings - Fork 324
Expand file tree
/
Copy pathtest_dev.py
More file actions
65 lines (59 loc) · 2.18 KB
/
test_dev.py
File metadata and controls
65 lines (59 loc) · 2.18 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
import os
import subprocess
import tempfile
import unittest
from pathlib import Path
class TestDev(unittest.TestCase):
def test_simple_change_to_backend(self):
"""Test that we can use a development version of SymbolicRegression.jl"""
PYSR_TEST_JULIA_VERSION = os.environ.get("PYSR_TEST_JULIA_VERSION", "1.11")
PYSR_TEST_PYTHON_VERSION = os.environ.get("PYSR_TEST_PYTHON_VERSION", "3.12")
repo_root = Path(__file__).parent.parent.parent
with tempfile.TemporaryDirectory(prefix="pysr-docker-config-") as docker_config:
env = dict(os.environ)
env["DOCKER_CONFIG"] = docker_config
build_result = subprocess.run(
[
"docker",
"buildx",
"bake",
"-f",
"docker-bake.hcl",
"pysr-dev",
"--set",
f"pysr-dev.args.JLVERSION={PYSR_TEST_JULIA_VERSION}",
"--set",
f"pysr-dev.args.PYVERSION={PYSR_TEST_PYTHON_VERSION}",
],
env=env,
cwd=repo_root,
universal_newlines=True,
)
self.assertEqual(build_result.returncode, 0)
test_result = subprocess.run(
[
"docker",
"run",
"--rm",
"pysr-dev",
"python3",
"-c",
"from pysr import SymbolicRegression as SR; print(SR.__test_function())",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=env,
cwd=repo_root,
)
self.assertEqual(test_result.returncode, 0)
self.assertEqual(test_result.stdout.decode("utf-8").strip(), "2.3")
def runtests(just_tests=False):
tests = [TestDev]
if just_tests:
return tests
suite = unittest.TestSuite()
loader = unittest.TestLoader()
for test in tests:
suite.addTests(loader.loadTestsFromTestCase(test))
runner = unittest.TextTestRunner()
return runner.run(suite)