You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2021/03/19 12:35:06 UTC

[ignite] branch ignite-ducktape updated: Addh sha-1 hash of args to results dir and test name. (#8899)

This is an automated email from the ASF dual-hosted git repository.

av pushed a commit to branch ignite-ducktape
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/ignite-ducktape by this push:
     new 3a68ccb  Addh sha-1 hash of args to results dir and test name. (#8899)
3a68ccb is described below

commit 3a68ccb32dffe287e3064457dc4750c3fca2860d
Author: Ivan Daschinskiy <iv...@gmail.com>
AuthorDate: Fri Mar 19 15:34:42 2021 +0300

    Addh sha-1 hash of args to results dir and test name. (#8899)
---
 .../ducktests/tests/ignitetest/tests/__init__.py   | 57 ++++++++++++++++++++++
 1 file changed, 57 insertions(+)

diff --git a/modules/ducktests/tests/ignitetest/tests/__init__.py b/modules/ducktests/tests/ignitetest/tests/__init__.py
index ec20143..fb0a3ed 100644
--- a/modules/ducktests/tests/ignitetest/tests/__init__.py
+++ b/modules/ducktests/tests/ignitetest/tests/__init__.py
@@ -12,3 +12,60 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+# pylint: disable=missing-module-docstring
+
+import hashlib
+import os
+
+from ducktape.tests.test import TestContext
+
+
+def decorate_args(args, with_args=False):
+    """
+    Decorate args with sha1 hash.
+    """
+    prefix = ''
+    if args:
+        sha_1 = hashlib.sha1()
+        sha_1.update(args.encode('utf-8'))
+
+        digest = sha_1.hexdigest()[0:6]
+        prefix = digest + '@'
+
+    return prefix + args if with_args else prefix
+
+
+def patched_test_name(self):
+    """
+    Monkey patched test_name property function.
+    """
+    name_components = [self.module_name,
+                       self.cls_name,
+                       self.function_name,
+                       self.injected_args_name]
+
+    name = ".".join(filter(lambda x: x is not None and len(x) > 0, name_components))
+    return decorate_args(self.injected_args_name) + name
+
+
+def patched_results_dir(test_context, test_index):
+    """
+    Monkey patch results_dir.
+    """
+    results_dir = test_context.session_context.results_dir
+
+    if test_context.cls is not None:
+        results_dir = os.path.join(results_dir, test_context.cls.__name__)
+    if test_context.function is not None:
+        results_dir = os.path.join(results_dir, test_context.function.__name__)
+    if test_context.injected_args is not None:
+        results_dir = os.path.join(results_dir, decorate_args(test_context.injected_args_name, True))
+    if test_index is not None:
+        results_dir = os.path.join(results_dir, str(test_index))
+
+    return results_dir
+
+
+TestContext.test_name = property(patched_test_name)
+TestContext.results_dir = staticmethod(patched_results_dir)