From f6f1b9bb256a655f9114374e17871c3c137f00f5 Mon Sep 17 00:00:00 2001 From: Massimiliano Date: Tue, 17 Dec 2024 19:21:50 +0100 Subject: [PATCH] Support float castable values instead of just floats (bugfix) (#1658) * Support float castable values instead of just floats This is done because the value may be 0, which is a valid value for it (delay == 0) * Now ints are supported, lets replace it with another invalid value --- checkbox-ng/plainbox/impl/session/resume.py | 8 +++++++- checkbox-ng/plainbox/impl/session/test_resume.py | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/checkbox-ng/plainbox/impl/session/resume.py b/checkbox-ng/plainbox/impl/session/resume.py index db0db7ab81..e052e558bb 100644 --- a/checkbox-ng/plainbox/impl/session/resume.py +++ b/checkbox-ng/plainbox/impl/session/resume.py @@ -1082,7 +1082,13 @@ def _rewrite_pathname(cls, pathname, location): def _build_IOLogRecord(cls, record_repr): """Convert the representation of IOLogRecord back the object.""" _validate(record_repr, value_type=list) - delay = _validate(record_repr, key=0, value_type=float) + delay = _validate(record_repr, key=0) + try: + delay = float(delay) + except ValueError: + raise CorruptedSessionError( + "IOLogRecord has invalid delay {}".format(delay) + ) if delay < 0: # TRANSLATORS: please keep delay untranslated raise CorruptedSessionError(_("delay cannot be negative")) diff --git a/checkbox-ng/plainbox/impl/session/test_resume.py b/checkbox-ng/plainbox/impl/session/test_resume.py index f5289d7f76..9e59826291 100644 --- a/checkbox-ng/plainbox/impl/session/test_resume.py +++ b/checkbox-ng/plainbox/impl/session/test_resume.py @@ -812,7 +812,9 @@ def test_build_IOLogRecord_bad_type_for_delay(self): verify that _build_IOLogRecord() checks that ``delay`` is float """ with self.assertRaises(CorruptedSessionError): - self.parameters.resume_cls._build_IOLogRecord([0, "stdout", ""]) + self.parameters.resume_cls._build_IOLogRecord( + ["abc", "stdout", ""] + ) def test_build_IOLogRecord_negative_delay(self): """