Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
acce2c2
1
Parent(s):
099a9c6
Convert static libpython test to proper unittest
Browse files
.github/workflows/CI.yml
CHANGED
@@ -132,7 +132,7 @@ jobs:
|
|
132 |
- name: "Install Coverage tool"
|
133 |
run: python3 -m pip install coverage coveralls
|
134 |
- name: "Ensure that static libpython warning appears"
|
135 |
-
run: coverage run --source=pysr --omit='*/feynman_problems.py' test
|
136 |
- name: "Run tests"
|
137 |
run: coverage run --append --source=pysr --omit='*/feynman_problems.py' -m unittest test.test
|
138 |
- name: Coveralls
|
|
|
132 |
- name: "Install Coverage tool"
|
133 |
run: python3 -m pip install coverage coveralls
|
134 |
- name: "Ensure that static libpython warning appears"
|
135 |
+
run: coverage run --source=pysr --omit='*/feynman_problems.py' -m unittest test.test_static_libpython_warning.py
|
136 |
- name: "Run tests"
|
137 |
run: coverage run --append --source=pysr --omit='*/feynman_problems.py' -m unittest test.test
|
138 |
- name: Coveralls
|
test/test_static_libpython_warning.py
CHANGED
@@ -1,13 +1,20 @@
|
|
1 |
-
"""Test that running PySR with static libpython raises a warning.
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
import warnings
|
4 |
import pysr
|
5 |
|
6 |
# Taken from https://stackoverflow.com/a/14463362/2689923
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
1 |
+
"""Test that running PySR with static libpython raises a warning.
|
2 |
|
3 |
+
Note: This test will ONLY pass with statically-linked python binaries, such
|
4 |
+
as provided by conda. It will not pass on other versions of python, and that is
|
5 |
+
okay."""
|
6 |
+
|
7 |
+
import unittest
|
8 |
import warnings
|
9 |
import pysr
|
10 |
|
11 |
# Taken from https://stackoverflow.com/a/14463362/2689923
|
12 |
+
class TestLibpythonWarning(unittest.TestCase):
|
13 |
+
def test_warning(self):
|
14 |
+
with warnings.catch_warnings(record=True) as warning_catcher:
|
15 |
+
warnings.simplefilter("always")
|
16 |
+
pysr.sr.init_julia()
|
17 |
|
18 |
+
self.assertEqual(len(warning_catcher), 1)
|
19 |
+
self.assertTrue(issubclass(warning_catcher[-1].category, UserWarning))
|
20 |
+
self.assertIn("static", str(warning_catcher[-1].message))
|