Skip to content

Commit

Permalink
Merge pull request #59 from TheoMF/temporary_ipynb
Browse files Browse the repository at this point in the history
use copy of ipynb for test action
  • Loading branch information
nim65s authored Aug 18, 2023
2 parents 532831d + de62649 commit 1bbd917
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gepetuto/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Add "test" action for the "gepetuto" program."""

import logging
import shutil
import tempfile
from collections import defaultdict
from pathlib import Path
from subprocess import check_call
Expand All @@ -18,10 +20,11 @@ def test(files, **kwargs):
for tp_file in tp_files:
LOG.debug("Checking %s", tp_file)
check_call([python_interpreter, str(tp_file)])
tmp_dir = tempfile.TemporaryDirectory(prefix="gepetuto-")
ipynbs = get_ipynbs(files)
for tp_ipynbs in ipynbs.values():
for tp_ipynb in tp_ipynbs:
check_ipynb(tp_ipynb, python_interpreter)
check_ipynb(tp_ipynb, python_interpreter, tmp_dir)
LOG.info("test passed.")


Expand All @@ -38,14 +41,16 @@ def get_ipynbs(files):
return ipynbs


def check_ipynb(ipynb, python_interpreter):
def check_ipynb(ipynb, python_interpreter, tmp_dir):
"""Check .ipynb files from given tp_number."""
prefix = str(ipynb).split("-")[0]
tp_path = Path(f"tp{prefix}" if prefix.isdecimal() else prefix)
check_call(["cp", f"{ipynb}", tmp_dir.name])
shutil.copy(ipynb, tmp_dir.name)
ipynb_copy = Path(tmp_dir.name) / ipynb.name
if tp_path.exists():
generate_ipynb(ipynb, tp_path, True)
check_call(["jupyter", "nbconvert", "--to", "script", f"{ipynb}"])
converted_ipynb = next(Path().glob(f"{prefix}-*.py"))
generate_ipynb(ipynb_copy, tp_path, True)
check_call(["jupyter", "nbconvert", "--to", "script", ipynb_copy])
converted_ipynb = Path(tmp_dir.name) / f"{ipynb_copy.stem}.py"
LOG.debug("Checking temporary file %s", converted_ipynb)
check_call([python_interpreter, converted_ipynb])
Path.unlink(converted_ipynb)

0 comments on commit 1bbd917

Please sign in to comment.