From 5419000df272a7bce62af2dcc0f78d5f32691cd9 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Wed, 11 Nov 2020 12:08:00 +0100 Subject: [PATCH] Hash properly regression tests --- reframe/core/pipeline.py | 9 +++++++++ unittests/test_pipeline.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 3f33a4baff..d873797ba8 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -1742,6 +1742,15 @@ def __str__(self): return "%s(name='%s', prefix='%s')" % (type(self).__name__, self.name, self.prefix) + def __eq__(self, other): + if not isinstance(other, RegressionTest): + return NotImplemented + + return self.name == other.name + + def __hash__(self): + return hash(self.name) + class RunOnlyRegressionTest(RegressionTest, special=True): '''Base class for run-only regression tests. diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index 91e494e25d..b3030c46fa 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -131,6 +131,24 @@ def _container_exec_ctx(platform): return _container_exec_ctx +def test_eq(): + class T0(rfm.RegressionTest): + def __init__(self): + self.name = 'T0' + + class T1(rfm.RegressionTest): + def __init__(self): + self.name = 'T0' + + t0, t1 = T0(), T1() + assert t0 == t1 + assert hash(t0) == hash(t1) + + t1.name = 'T1' + assert t0 != t1 + assert hash(t0) != hash(t1) + + def test_environ_setup(hellotest, local_exec_ctx): # Use test environment for the regression check hellotest.variables = {'_FOO_': '1', '_BAR_': '2'}