Skip to content

Commit

Permalink
should be pointing to correct test
Browse files Browse the repository at this point in the history
  • Loading branch information
beckynevin committed Apr 9, 2024
1 parent 43d4e79 commit 4f0dae0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 47 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ jobs:
run: echo "PYTHONPATH=$(pwd):$(pwd)/src" >> ${{ runner.workspace }}/.env

- name: Test with pytest
run: |
pwd
python -m poetry run pytest --cov
run: python -m poetry run pytest --cov
env:
PYTHONPATH: ${{ env.PYTHONPATH }}
ENV_FILE: ${{ runner.workspace }}/.env
83 changes: 39 additions & 44 deletions test/test_DeepEnsemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
import subprocess
import tempfile
import shutil

# flake8: noqa
sys.path.append("..")
# print(sys.path)
# from scripts.evaluate import Diagnose_static, Diagnose_generative
# from scripts.io import ModelLoader
from scripts import evaluate, models, DeepEnsemble


Expand All @@ -35,22 +29,22 @@ def temp_directory():
"""
shutil.rmtree(temp_dir)


@pytest.mark.xfail(strict=True)
def test_no_chkpt_saved_xfail(temp_directory):
def test_chkpt_saved(temp_directory):
noise_level = "low"
n_models = 10
wd = str(temp_directory) + "/"
n_epochs = 2
subprocess_args = [
"python",
"../src/scripts/DeepEnsemble.py",
"src/scripts/DeepEnsemble.py",
noise_level,
str(n_models),
wd,
"--n_epochs",
str(n_epochs),
]
"--save_final_checkpoint",
"--savefig"
]
# now run the subprocess
subprocess.run(subprocess_args, check=True)
# check if the right number of checkpoints are saved
Expand All @@ -62,15 +56,38 @@ def test_no_chkpt_saved_xfail(temp_directory):
len(files_in_models_folder) == n_models
), "Expected 10 files in the 'models' folder"

# check if the right number of images were saved
animations_folder = os.path.join(temp_directory, "images/animations")
files_in_animations_folder = os.listdir(animations_folder)
# assert that the number of files is equal to 10
assert (
len(files_in_animations_folder) == n_models
), "Expected 10 files in the 'images/animations' folder"

def test_no_chkpt_saved(temp_directory):
# also check that all files in here have the same name elements
expected_substring = "epoch_" + str(n_epochs - 1)
for file_name in files_in_models_folder:
assert (
expected_substring in file_name
), f"File '{file_name}' does not contain the expected substring"

# also check that all files in here have the same name elements
for file_name in files_in_animations_folder:
assert (
expected_substring in file_name
), f"File '{file_name}' does not contain the expected substring"



@pytest.mark.xfail(strict=True)
def test_no_chkpt_saved_xfail(temp_directory):
noise_level = "low"
n_models = 10
wd = str(temp_directory) + "/"
n_epochs = 2
subprocess_args = [
"python",
"../src/scripts/DeepEnsemble.py",
"src/scripts/DeepEnsemble.py",
noise_level,
str(n_models),
wd,
Expand All @@ -84,56 +101,34 @@ def test_no_chkpt_saved(temp_directory):
# list all files in the "models" folder
files_in_models_folder = os.listdir(models_folder)
# assert that the number of files is equal to 10
assert len(files_in_models_folder) == 0, "Expect 0 files in the 'models' folder"
assert (
len(files_in_models_folder) == n_models
), "Expected 10 files in the 'models' folder"


def test_chkpt_saved(temp_directory):
def test_no_chkpt_saved(temp_directory):
noise_level = "low"
n_models = 10
wd = str(temp_directory) + "/"
n_epochs = 2
subprocess_args = [
"python",
"../src/scripts/DeepEnsemble.py",
"src/scripts/DeepEnsemble.py",
noise_level,
str(n_models),
wd,
"--n_epochs",
str(n_epochs),
"--save_final_checkpoint",
"--savefig"
]
]
# now run the subprocess
subprocess.run(subprocess_args, check=True)
# check if the right number of checkpoints are saved
models_folder = os.path.join(temp_directory, "models")
# list all files in the "models" folder
files_in_models_folder = os.listdir(models_folder)
# assert that the number of files is equal to 10
assert (
len(files_in_models_folder) == n_models
), "Expected 10 files in the 'models' folder"

# check if the right number of images were saved
animations_folder = os.path.join(temp_directory, "images/animations")
files_in_animations_folder = os.listdir(animations_folder)
# assert that the number of files is equal to 10
assert (
len(files_in_animations_folder) == n_models
), "Expected 10 files in the 'images/animations' folder"

# also check that all files in here have the same name elements
expected_substring = "epoch_" + str(n_epochs - 1)
for file_name in files_in_models_folder:
assert (
expected_substring in file_name
), f"File '{file_name}' does not contain the expected substring"
assert len(files_in_models_folder) == 0, "Expect 0 files in the 'models' folder"

# also check that all files in here have the same name elements
for file_name in files_in_animations_folder:
assert (
expected_substring in file_name
), f"File '{file_name}' does not contain the expected substring"


def test_run_simple_ensemble(temp_directory):
Expand All @@ -145,7 +140,7 @@ def test_run_simple_ensemble(temp_directory):
wd = str(temp_directory) + "/"
subprocess_args = [
"python",
"../src/scripts/DeepEnsemble.py",
"src/scripts/DeepEnsemble.py",
noise_level,
n_models,
wd,
Expand All @@ -162,7 +157,7 @@ def test_missing_req_arg(temp_directory):
n_models = "10"
subprocess_args = [
"python",
"../src/scripts/DeepEnsemble.py",
"src/scripts/DeepEnsemble.py",
noise_level,
n_models,
"--n_epochs",
Expand Down

0 comments on commit 4f0dae0

Please sign in to comment.