From 544d8425fb15197a195ca16c2993e6a4026c0493 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Mon, 27 Mar 2023 15:37:24 -0400 Subject: [PATCH] Tests: python: enum.auto() introduced in python 3.6 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Assign descriptive string values to the enumeration members instead of using auto() and provide a repr() method that hides the value as recommended upstream [1]. [1] https://docs.python.org/3.6/library/enum.html#omitting-values Change-Id: I0bc8fcc19d68342ade1aeb587f07a9b483f81b3e Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- tests/utils/lttngtest/lttng.py | 16 ++++++++++------ tests/utils/lttngtest/lttngctl.py | 32 ++++++++++++++++--------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/tests/utils/lttngtest/lttng.py b/tests/utils/lttngtest/lttng.py index 6829fa707..2679fd1a6 100644 --- a/tests/utils/lttngtest/lttng.py +++ b/tests/utils/lttngtest/lttng.py @@ -144,13 +144,17 @@ class _Channel(lttngctl.Channel): return self._domain +@enum.unique class _ProcessAttribute(enum.Enum): - PID = (enum.auto(),) - VPID = (enum.auto(),) - UID = (enum.auto(),) - VUID = (enum.auto(),) - GID = (enum.auto(),) - VGID = (enum.auto(),) + PID = "Process ID" + VPID = "Virtual Process ID" + UID = "User ID" + VUID = "Virtual User ID" + GID = "Group ID" + VGID = "Virtual Group ID" + + def __repr__(self): + return "<%s.%s>" % (self.__class__.__name__, self.name) def _get_process_attribute_option_name(attribute: _ProcessAttribute) -> str: diff --git a/tests/utils/lttngtest/lttngctl.py b/tests/utils/lttngtest/lttngctl.py index 632c13083..0301b6e09 100644 --- a/tests/utils/lttngtest/lttngctl.py +++ b/tests/utils/lttngtest/lttngctl.py @@ -68,14 +68,18 @@ class JavaApplicationContextType(ContextType): return self._field_name +@enum.unique class TracingDomain(enum.Enum): """Tracing domain.""" - User = enum.auto(), "User space tracing domain" - Kernel = enum.auto(), "Linux kernel tracing domain." - Log4j = enum.auto(), "Log4j tracing back-end." - JUL = enum.auto(), "Java Util Logging tracing back-end." - Python = enum.auto(), "Python logging module tracing back-end." + User = "User space tracing domain" + Kernel = "Linux kernel tracing domain." + Log4j = "Log4j tracing back-end." + JUL = "Java Util Logging tracing back-end." + Python = "Python logging module tracing back-end." + + def __repr__(self): + return "<%s.%s>" % (self.__class__.__name__, self.name) class EventRule(abc.ABC): @@ -210,19 +214,17 @@ class ProcessAttributeTracker(abc.ABC): policy back to "all" once it has transitioned to "include set". """ + @enum.unique class TrackingPolicy(enum.Enum): - INCLUDE_ALL = ( - enum.auto(), - """ + INCLUDE_ALL = """ Track all possible process attribute value of a given type (i.e. no filtering). This is the default state of a process attribute tracker. - """, - ) - EXCLUDE_ALL = ( - enum.auto(), - "Exclude all possible process attribute values of a given type.", - ) - INCLUDE_SET = enum.auto(), "Track a set of specific process attribute values." + """ + EXCLUDE_ALL = "Exclude all possible process attribute values of a given type." + INCLUDE_SET = "Track a set of specific process attribute values." + + def __repr__(self): + return "<%s.%s>" % (self.__class__.__name__, self.name) def __init__(self, policy: TrackingPolicy): self._policy = policy -- 2.34.1