Skip to content

Commit

Permalink
Randomize tests
Browse files Browse the repository at this point in the history
Modify test015_iec_phantom_2 and test040_gan_phsp_pet_gan to be able to run the tests independently
Try to run randomize tests only for PR, the cron CI should run all the tests to be sure to run all tests once a week
  • Loading branch information
tbaudier committed Jul 18, 2023
1 parent 5fed96f commit e39c39c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,17 @@ jobs:
path=`opengate_tests_utils -p libG4geometry`
export LD_PRELOAD=${path}:${LD_PRELOAD}
fi
OutputTest=$(opengate_tests)
if [ $Pr_Number == "" ]; then
OutputTest=$(opengate_tests)
else
OutputTest=$(opengate_tests -r)
fi
echo "$OutputTest"
OutputTest=$(echo "$OutputTest" | tail -1)
if [ "$OutputTest" != "True" ]; then
exit -1
else
exit 0
fi
env:
Pr_Number: ${{ github.event.number }}
15 changes: 14 additions & 1 deletion opengate/bin/opengate_tests
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ from opengate_core.testsDataSetup import *
import pathlib
import click
import hashlib
import random

CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])


@click.command(context_settings=CONTEXT_SETTINGS)
@click.option("--test_id", "-i", default="all", help="Start test from this number")
def go(test_id):
@click.option(
"--random_tests",
"-r",
is_flag=True,
default=False,
help="Start the last 10 tests and 1/5 of the others randomly",
)
def go(test_id, random_tests):
pathFile = pathlib.Path(__file__).parent.resolve()
if "src" in os.listdir(pathFile):
mypath = os.path.join(pathFile, "../tests/src")
Expand Down Expand Up @@ -88,6 +96,11 @@ def go(test_id):
else:
print(f"Ignoring: {f:<40} (< {test_id}) ")
files = files_new
elif random_tests:
files_new = files[-10:]
prob = 0.2
files = files_new + random.sample(files[:-10], int(prob * (len(files) - 10)))
files = sorted(files)

print(f"Running {len(files)} tests")
print(f"-" * 70)
Expand Down
8 changes: 8 additions & 0 deletions opengate/tests/src/test015_iec_phantom_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
import opengate.contrib.phantom_nema_iec_body as gate_iec
import pathlib
import os
import subprocess

pathFile = pathlib.Path(__file__).parent.resolve()

# To compare output this takes the output of test015_iec_phantom_1.py
# If the output of test015_iec_phantom_1.py does not exist (eg: random test), create it
if not os.path.isfile(pathFile / ".." / "output" / "stats_test015_iec_phantom_1.txt"):
print("---------- Begin of test015_iec_phantom_1.py ----------")
subprocess.call(["python", pathFile / "test015_iec_phantom_1.py"])
print("----------- End of test015_iec_phantom_1.py -----------")

# global log level
# create the simulation
sim = gate.Simulation()
Expand Down
9 changes: 9 additions & 0 deletions opengate/tests/src/test040_gan_phsp_pet_gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import numpy as np
import matplotlib.pyplot as plt
import os
import subprocess

paths = gate.get_default_test_paths(__file__, "")
paths.output_ref = paths.output_ref / "test040_ref"

# The test needs the output of test040_gan_phsp_pet_aref.py
# If the output of test040_gan_phsp_pet_aref.py does not exist (eg: random test), create it
if not os.path.isfile(paths.output / "test040_gan_phsp.root"):
print("---------- Begin of test040_gan_phsp_pet_aref.py ----------")
subprocess.call(["python", paths.current / "test040_gan_phsp_pet_aref.py"])
print("----------- End of test040_gan_phsp_pet_aref.py -----------")


# create the simulation
sim = gate.Simulation()

Expand Down

0 comments on commit e39c39c

Please sign in to comment.