Use `tests/utils/python/tjson.py` and add some types annotations to make
`tests/lib/conds/test.py` pyright-clean:
$ PYTHONPATH=/home/simark/src/babeltrace/tests/utils/python pyright tests/lib/conds/test.py
0 errors, 0 warnings, 0 informations
Change-Id: Ie7e233e51b5fef645f6ca2c23a66e8c81f00f2a8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11780
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
#
# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
#
# Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
+# pyright: strict, reportTypeCommentUsage=false, reportMissingTypeStubs=false
+
import signal
import os.path
import unittest
import functools
import subprocess
import signal
import os.path
import unittest
import functools
import subprocess
# the `conds-triggers` program's full path
_CONDS_TRIGGERS_PATH = os.environ["BT_TESTS_LIB_CONDS_TRIGGER_BIN"]
# the `conds-triggers` program's full path
_CONDS_TRIGGERS_PATH = os.environ["BT_TESTS_LIB_CONDS_TRIGGER_BIN"]
# a condition trigger descriptor (base)
class _CondTriggerDescriptor:
# a condition trigger descriptor (base)
class _CondTriggerDescriptor:
- def __init__(self, index, trigger_name, cond_id):
+ def __init__(self, index: int, trigger_name: str, cond_id: str):
self._index = index
self._trigger_name = trigger_name
self._cond_id = cond_id
self._index = index
self._trigger_name = trigger_name
self._cond_id = cond_id
# test method template for `LibPrePostCondsTestCase`
# test method template for `LibPrePostCondsTestCase`
-def _test(self, descriptor):
+def _test(self: unittest.TestCase, descriptor: _CondTriggerDescriptor):
# Execute:
#
# $ conds-triggers run <index>
# Execute:
#
# $ conds-triggers run <index>
# Condition trigger descriptors from the JSON array returned by
#
# $ conds-triggers list
# Condition trigger descriptors from the JSON array returned by
#
# $ conds-triggers list
-def _cond_trigger_descriptors_from_json(json_descr_array):
- descriptors = []
- descriptor_names = set()
+def _cond_trigger_descriptors_from_json(json_descr_array: tjson.ArrayVal):
+ descriptors = [] # type: list[_CondTriggerDescriptor]
+ descriptor_names = set() # type: set[str]
- for index, json_descr in enumerate(json_descr_array):
+ for index, json_descr in enumerate(json_descr_array.iter(tjson.ObjVal)):
# sanity check: check for duplicate
# sanity check: check for duplicate
- trigger_name = json_descr["name"]
+ trigger_name = json_descr.at("name", tjson.StrVal).val
if trigger_name in descriptor_names:
raise ValueError(
if trigger_name in descriptor_names:
raise ValueError(
- cond_id = json_descr["cond-id"]
+ cond_id = json_descr.at("cond-id", tjson.StrVal).val
if cond_id.startswith("pre"):
cond_type = _PreCondTriggerDescriptor
if cond_id.startswith("pre"):
cond_type = _PreCondTriggerDescriptor
def _create_tests():
# Execute `conds-triggers list` to get a JSON array of condition
# trigger descriptors.
def _create_tests():
# Execute `conds-triggers list` to get a JSON array of condition
# trigger descriptors.
- json_descr_array = json.loads(
- subprocess.check_output([_CONDS_TRIGGERS_PATH, "list"], universal_newlines=True)
+ json_descr_array = tjson.loads(
+ subprocess.check_output(
+ [_CONDS_TRIGGERS_PATH, "list"], universal_newlines=True
+ ),
+ tjson.ArrayVal,
)
# get condition trigger descriptor objects from JSON
)
# get condition trigger descriptor objects from JSON