From 88efaa1940b0e79e422b4a6714cd014c1318f962 Mon Sep 17 00:00:00 2001 From: Rafal Stefanowski Date: Tue, 21 Jan 2020 16:43:54 +0100 Subject: [PATCH] Fix timedelta precision by importing attotimedelta total_seconds() method from Python's datetime class outputs a Float precision number which for some numbers multiplied by 10^n gives wrong values. total_seconds() method from attotime class wraps a native timedelta object and outputs a Decimal precision number which fixes this issue. Signed-off-by: Rafal Stefanowski --- test/functional/api/cas/cache.py | 3 +-- test/functional/api/cas/cache_config.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/functional/api/cas/cache.py b/test/functional/api/cas/cache.py index eb0ab27..6fd4aa9 100644 --- a/test/functional/api/cas/cache.py +++ b/test/functional/api/cas/cache.py @@ -177,8 +177,7 @@ class Cache: if alru_params.staleness_time else None, alru_params.flush_max_buffers if alru_params.flush_max_buffers else None, - int(alru_params.activity_threshold.total_seconds() - * 1000) + alru_params.activity_threshold.total_milliseconds() if alru_params.activity_threshold else None) def get_cache_config(self): diff --git a/test/functional/api/cas/cache_config.py b/test/functional/api/cas/cache_config.py index 2af69af..0908cb9 100644 --- a/test/functional/api/cas/cache_config.py +++ b/test/functional/api/cas/cache_config.py @@ -6,7 +6,7 @@ from enum import IntEnum from aenum import Enum from test_utils.size import Size, Unit -from datetime import timedelta +from attotime import attotimedelta class CacheLineSize(Enum): @@ -79,7 +79,7 @@ class CacheStatus(Enum): incomplete = 5 -class Time(timedelta): +class Time(attotimedelta): def total_milliseconds(self): return int(self.total_seconds() * 1000)