Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,12 @@ jobs:
path: /home/runner/.cache/symfem
key: symfem-cache

- name: Load OEIS cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /home/runner/.oeis-cache
key: oeis-cache

- name: Clone Symfem
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -213,5 +219,11 @@ jobs:

- run: python3 -m pytest -n4 test
name: Run tests with pytest

- name: Save OEIS cache
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: /home/runner/.oeis-cache
key: oeis-cache-${{ github.run_id }}-${{ github.run_attempt }}
permissions:
contents: read
62 changes: 41 additions & 21 deletions test/test_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sympy
import yaml

oeis_cache: dict[str, str] = {}
oeis_cache_location = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../.oeis-cache")


class TimeOutTheTest(BaseException):
Expand Down Expand Up @@ -72,28 +72,37 @@ def check_oeis(oeis, seq):
oeis, condition = oeis.split(" [")
condition = condition.split("]")[0]
seq = {i: j for i, j in seq.items() if is_satisfied(condition, i)}
if not os.path.isdir(oeis_cache_location):
os.mkdir(oeis_cache_location)
seq = {i: j for i, j in seq.items() if j > 0}
if oeis not in oeis_cache:
if oeis not in os.listdir(oeis_cache_location):
try:
with urllib.request.urlopen(
urllib.request.Request(
f"http://oeis.org/{oeis}/list",
headers={"User-Agent": "DefElement test runner"},
)
) as f:
oeis_cache[oeis] = "".join(
[
i.strip()
for i in f.read()
.decode("utf-8")
.split("<pre>[")[1]
.split("]</pre>")[0]
.split("\n")
]
with (
urllib.request.urlopen(
urllib.request.Request(
f"http://oeis.org/{oeis}/list",
headers={"User-Agent": "DefElement test runner"},
)
) as o,
open(os.path.join(oeis_cache_location, oeis), "w") as f,
):
f.write(
"".join(
[
i.strip()
for i in o.read()
.decode("utf-8")
.split("<pre>[")[1]
.split("]</pre>")[0]
.split("\n")
]
)
)
except urllib.error.HTTPError:
pytest.xfail("Error reading from OEIS")
assert ",".join([str(i) for i in seq.values()]) in oeis_cache[oeis]

with open(os.path.join(oeis_cache_location, oeis)) as f:
assert ",".join([str(i) for i in seq.values()]) in f.read()


def parse_degree(degree, cellname):
Expand Down Expand Up @@ -128,9 +137,20 @@ def test_sequence(file, cellname):
pytest.skip()

if isinstance(data["implementations"]["symfem"], dict):
if cellname not in data["implementations"]["symfem"]:
pytest.skip()
symfem_name = data["implementations"]["symfem"][cellname]
if cellname in data["implementations"]["symfem"]:
symfem_name = data["implementations"]["symfem"][cellname]
else:
for d in data["implementations"]["symfem"].values():
if isinstance(d, str):
symfem_name = d
break
else:
for d in data["implementations"]["symfem"].values():
if isinstance(d, dict) and cellname in d:
symfem_name = d[cellname]
break
else:
pytest.skip()
else:
symfem_name = data["implementations"]["symfem"]

Expand Down