From 05abc762716e96308952c1d83e290f393596cd90 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 6 Jun 2019 19:06:11 -0400 Subject: [PATCH] bt2: add `_Trace.cls` property Signed-off-by: Philippe Proulx Change-Id: I0669de442d91da7b188a02d633e1fad15fc5814c Reviewed-on: https://review.lttng.org/c/babeltrace/+/1395 Reviewed-by: Simon Marchi --- bindings/python/bt2/bt2/trace.py | 7 +++++++ tests/bindings/python/bt2/test_trace.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/bindings/python/bt2/bt2/trace.py b/bindings/python/bt2/bt2/trace.py index 47dab8f7..5830ec3f 100644 --- a/bindings/python/bt2/bt2/trace.py +++ b/bindings/python/bt2/bt2/trace.py @@ -25,6 +25,7 @@ import bt2.field_class import collections.abc import bt2.value import bt2.stream +import bt2.trace_class import bt2 import functools @@ -63,6 +64,12 @@ class _Trace(object._SharedObject, collections.abc.Mapping): yield id + @property + def cls(self): + trace_class_ptr = native_bt.trace_borrow_class(self._ptr) + assert trace_class_ptr is not None + return bt2.trace_class._TraceClass._create_from_ptr_and_get_ref(trace_class_ptr) + @property def name(self): return native_bt.trace_get_name(self._ptr) diff --git a/tests/bindings/python/bt2/test_trace.py b/tests/bindings/python/bt2/test_trace.py index 69029244..f3602c25 100644 --- a/tests/bindings/python/bt2/test_trace.py +++ b/tests/bindings/python/bt2/test_trace.py @@ -18,6 +18,10 @@ class TraceTestCase(unittest.TestCase): with self.assertRaises(TypeError): self._tc(name=17) + def test_attr_trace_class(self): + trace = self._tc(name='my name') + self.assertEqual(trace.cls.addr, self._tc.addr) + def test_len(self): trace = self._tc() sc = self._tc.create_stream_class() -- 2.34.1