Skip to content
Snippets Groups Projects
Commit 52348ca9 authored by Cyril Moineau's avatar Cyril Moineau
Browse files

Test export now clean successfull tests.

parent 9f86629b
No related branches found
No related tags found
2 merge requests!63Update 0.3.1 -> 0.3.2,!50Test export now clean successfull tests.
Pipeline #76059 failed
...@@ -12,6 +12,9 @@ import shutil ...@@ -12,6 +12,9 @@ import shutil
from aidge_core.utils import run_command from aidge_core.utils import run_command
from aidge_export_cpp import cpp_fuse_to_metaops, set_nodes_names from aidge_export_cpp import cpp_fuse_to_metaops, set_nodes_names
import pytest
from _pytest.unittest import TestCaseFunction
def initFiller(model): def initFiller(model):
# Initialize parameters (weights and biases) # Initialize parameters (weights and biases)
...@@ -64,15 +67,40 @@ def _np_init_ones(shape, default_value=0.01, dtype=np.float32): ...@@ -64,15 +67,40 @@ def _np_init_ones(shape, default_value=0.01, dtype=np.float32):
return data.reshape(shape).astype(dtype) return data.reshape(shape).astype(dtype)
# Global dictionary to store test reports
test_reports = {}
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
# Execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# Store the report in the global dictionary
test_reports[item.nodeid] = rep
class test_operator_export(unittest.TestCase): class test_operator_export(unittest.TestCase):
def setUp(self): def setUp(self):
# TODO change seed at each test ?
RNG_SEED = 1234 RNG_SEED = 1234
np.random.seed(RNG_SEED) np.random.seed(RNG_SEED)
aidge_core.random.Generator.set_seed(RNG_SEED) aidge_core.random.Generator.set_seed(RNG_SEED)
def tearDown(self): def tearDown(self):
pass result = self._outcome.result
test_succeeded = True
if isinstance(result, TestCaseFunction):
print("Test ran with pytest cannot retrieve if the test was a success.")
else:
test_succeeded = not any(test is self for test, _ in result.failures + result.errors)
if test_succeeded:
shutil.rmtree(self.export_folder)
# rep = test_reports.get(self.id())
# if rep is not None and rep.passed:
# # Perform teardown actions only if the test passed
# print(g"Removing {self.export_folder}")
# shutil.rmtree(self.export_folder, ignore_errors=True)
def unit_test_export(self, graph_view, op_name, in_dims, random_inputs=True, random_weights=True, default_value=0.01): def unit_test_export(self, graph_view, op_name, in_dims, random_inputs=True, random_weights=True, default_value=0.01):
""" """
...@@ -117,7 +145,7 @@ class test_operator_export(unittest.TestCase): ...@@ -117,7 +145,7 @@ class test_operator_export(unittest.TestCase):
# Note the convention ``<op_name>_test`` is useful for gitignore to avoid pushing generated export by accident. # Note the convention ``<op_name>_test`` is useful for gitignore to avoid pushing generated export by accident.
export_folder = op_name + "_test" export_folder = op_name + "_test"
self.export_folder = export_folder
shutil.rmtree(export_folder, ignore_errors=True) shutil.rmtree(export_folder, ignore_errors=True)
# Export the model in C++ standalone # Export the model in C++ standalone
...@@ -624,10 +652,6 @@ class test_operator_export(unittest.TestCase): ...@@ -624,10 +652,6 @@ class test_operator_export(unittest.TestCase):
self.unit_test_export(model, "BatchNorm2DDenser", [[1, 3, 5, 7]], False, False) self.unit_test_export(model, "BatchNorm2DDenser", [[1, 3, 5, 7]], False, False)
def test_cpp(self):
print("Export test to do")
def test_Conv(self): def test_Conv(self):
model = aidge_core.sequential([ model = aidge_core.sequential([
aidge_core.Conv2D(1, 1, [3, 3], name="InputNode") aidge_core.Conv2D(1, 1, [3, 3], name="InputNode")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment