Skip to content

Commit

Permalink
Make the tests compatible with pytest (#323)
Browse files Browse the repository at this point in the history
* make multi model row count use pytest rather than unittest

* fix arg count test

* run1psub0

* add param sweep

* add test runs not zero

* add policy aggregation

* add import nb

* add timestep1psub0

* add empty cadCAD exp test

---------

Co-authored-by: Emanuel Lima <[email protected]>
  • Loading branch information
danlessa and emanuellima1 authored Dec 15, 2023
1 parent 5241edf commit ec70d5d
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 243 deletions.
17 changes: 16 additions & 1 deletion testing/results_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@
import pandas as pd # type: ignore
from tabulate import tabulate # type: ignore
from pandas._testing import assert_frame_equal # type: ignore

from testing.utils import assertEqual

def compare_results_pytest(result_diff):
val_error_status_ind = False not in result_diff.val_error_status.tolist()
type_error_status_ind = False not in result_diff.type_error_status.tolist()
df_out = None
erroneous_indexes = None
select_result_diff = None

if (val_error_status_ind is False) or (type_error_status_ind is False):
erroneous_indexes = list(result_diff.index[result_diff["val_error_status"] == False])
select_result_diff = result_diff.iloc[erroneous_indexes]
df_out = tabulate(select_result_diff, headers='keys', tablefmt='psql')

assertEqual(val_error_status_ind, True, "Value Error")
assertEqual(type_error_status_ind, True, "Type Error")

def compare_results(result_diff):
class CompareResults(unittest.TestCase):
Expand Down
24 changes: 0 additions & 24 deletions testing/tests/cadCAD_exp.py

This file was deleted.

13 changes: 0 additions & 13 deletions testing/tests/import_cadCAD_test.py

This file was deleted.

100 changes: 0 additions & 100 deletions testing/tests/multi_model_row_count.py

This file was deleted.

23 changes: 0 additions & 23 deletions testing/tests/param_sweep.py

This file was deleted.

23 changes: 0 additions & 23 deletions testing/tests/policy_aggregation.py

This file was deleted.

17 changes: 0 additions & 17 deletions testing/tests/run1psub0.py

This file was deleted.

22 changes: 0 additions & 22 deletions testing/tests/runs_not_zero.py

This file was deleted.

22 changes: 22 additions & 0 deletions testing/tests/test_cadCAD_exp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pandas as pd
from tabulate import tabulate
from testing.results_comparison import dataframe_difference, compare_results_pytest
from cadCAD import configs
from cadCAD.engine import ExecutionMode, ExecutionContext, Executor
import pytest


@pytest.fixture
def empty_experiment():
exec_mode = ExecutionMode()
exec_ctx = ExecutionContext(context=exec_mode.local_mode)
run = Executor(exec_context=exec_ctx, configs=configs)
raw_result, _, _ = run.execute()

result_df = pd.DataFrame(raw_result)
expected_df = pd.read_pickle("expected_results/param_sweep_4.pkl")
return dataframe_difference(result_df, expected_df)


def test_experiment(empty_experiment):
compare_results_pytest(empty_experiment)
10 changes: 10 additions & 0 deletions testing/tests/test_import_cadCAD_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os, subprocess, json
from testing.utils import assertEqual

def test_jupyter_nbconvert_row_count():
command = f'jupyter nbconvert --to=notebook --ExecutePreprocessor.enabled=True {os.getcwd()}/testing/tests/import_cadCAD.ipynb'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
process.communicate()
json_path = f'{os.getcwd()}/testing/tests/cadCAD_memory_address.json'
memory_address = json.load(open(json_path))['memory_address']
assertEqual(type(memory_address) == str, True, "cadCAD is not importable by jupyter server")
Loading

0 comments on commit ec70d5d

Please sign in to comment.