# the `conds-triggers` program's full path
-_CONDS_TRIGGERS_PATH = os.environ['BT_TESTS_LIB_CONDS_TRIGGER_BIN']
+_CONDS_TRIGGERS_PATH = os.environ["BT_TESTS_LIB_CONDS_TRIGGER_BIN"]
# test methods are added by _create_tests()
class _PreCondTriggerDescriptor(_CondTriggerDescriptor):
@property
def type_str(self):
- return 'pre'
+ return "pre"
# postcondition trigger descriptor
class _PostCondTriggerDescriptor(_CondTriggerDescriptor):
@property
def type_str(self):
- return 'post'
+ return "post"
# test method template for `LibPrePostCondsTestCase`
#
# where `<index>` is the descriptor's index.
with subprocess.Popen(
- [_CONDS_TRIGGERS_PATH, 'run', str(descriptor.index)],
+ [_CONDS_TRIGGERS_PATH, "run", str(descriptor.index)],
stderr=subprocess.PIPE,
universal_newlines=True,
) as proc:
# wait for program end and get standard error pipe's contents
_, stderr = proc.communicate(timeout=timeout)
except subprocess.TimeoutExpired:
- self.fail('Process hanged for {} seconds'.format(timeout))
+ self.fail("Process hanged for {} seconds".format(timeout))
return
# assert that program aborted (only available on POSIX)
- if os.name == 'posix':
+ if os.name == "posix":
self.assertEqual(proc.returncode, -int(signal.SIGABRT))
# assert that the standard error text contains the condition ID
- text = 'Condition ID: `{}`.'.format(descriptor.cond_id)
+ text = "Condition ID: `{}`.".format(descriptor.cond_id)
self.assertIn(text, stderr)
for index, json_descr in enumerate(json_descr_array):
# sanity check: check for duplicate
- trigger_name = json_descr['name']
+ trigger_name = json_descr["name"]
if trigger_name in descriptor_names:
raise ValueError(
- 'Duplicate condition trigger name `{}`'.format(trigger_name)
+ "Duplicate condition trigger name `{}`".format(trigger_name)
)
# condition ID
- cond_id = json_descr['cond-id']
+ cond_id = json_descr["cond-id"]
- if cond_id.startswith('pre'):
+ if cond_id.startswith("pre"):
cond_type = _PreCondTriggerDescriptor
- elif cond_id.startswith('post'):
+ elif cond_id.startswith("post"):
cond_type = _PostCondTriggerDescriptor
else:
- raise ValueError('Invalid condition ID `{}`'.format(cond_id))
+ raise ValueError("Invalid condition ID `{}`".format(cond_id))
descriptors.append(cond_type(index, trigger_name, cond_id))
descriptor_names.add(trigger_name)
# 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)
+ subprocess.check_output([_CONDS_TRIGGERS_PATH, "list"], universal_newlines=True)
)
# get condition trigger descriptor objects from JSON
# create test methods
for descriptor in descriptors:
# test method name
- test_meth_name = 'test_{}'.format(
- re.sub(r'[^a-zA-Z0-9_]', '_', descriptor.trigger_name)
+ test_meth_name = "test_{}".format(
+ re.sub(r"[^a-zA-Z0-9_]", "_", descriptor.trigger_name)
)
# test method
_create_tests()
-if __name__ == '__main__':
+if __name__ == "__main__":
unittest.main()