From 76ff252acece4097e9390fd3cb51f285f4100767 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Sun, 28 Jan 2024 21:46:53 +0100 Subject: [PATCH] [cmp_tool_integration_test.py] Fix python test times DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC). --- test/cmp_tool/cmp_tool_integration_test.py | 27 +++++++++++----------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/cmp_tool/cmp_tool_integration_test.py b/test/cmp_tool/cmp_tool_integration_test.py index 5cadbf2..e66f38d 100755 --- a/test/cmp_tool/cmp_tool_integration_test.py +++ b/test/cmp_tool/cmp_tool_integration_test.py @@ -10,6 +10,7 @@ from pathlib import Path from datetime import datetime from datetime import timedelta +from datetime import timezone EXIT_FAILURE = 1 @@ -78,7 +79,7 @@ def del_directory(directoryPath): def cuc_timestamp(now): - epoch = datetime(2020, 1, 1) + epoch = datetime(2020, 1, 1, tzinfo=timezone.utc) timestamp = (now - epoch).total_seconds() cuc_coarse = int( math.floor(timestamp) * 256 * 256) @@ -447,9 +448,9 @@ def test_compression_diff(): assert(header['cmp_ent_size']['value'] == IMAGETTE_HEADER_SIZE+3) assert(header['original_size']['value'] == 10) # todo - assert(header['start_time']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['start_time']['value'] < cuc_timestamp(datetime.now(timezone.utc))) # todo - assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.now(timezone.utc))) assert(header['data_type']['value'] == 1) assert(header['cmp_mode_used']['value'] == 2) # assert(header['model_value_used']['value'] == 8) @@ -582,9 +583,9 @@ def test_model_compression(): assert(header['cmp_ent_size']['value'] == IMAGETTE_ADAPTIVE_HEADER_SIZE+2) assert(header['original_size']['value'] == 10) # todo - assert(header['start_time']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['start_time']['value'] < cuc_timestamp(datetime.now(timezone.utc))) #todo - assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.now(timezone.utc))) assert(header['data_type']['value'] == DATA_TYPE_IMAGETTE_ADAPTIVE) assert(header['cmp_mode_used']['value'] == 3) assert(header['model_value_used']['value'] == int(cfg['model_value'])) @@ -691,9 +692,9 @@ def test_raw_mode_compression(): assert(header['cmp_ent_size']['value'] == GENERIC_HEADER_SIZE+10) assert(header['original_size']['value'] == 10) # todo - assert(header['start_time']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['start_time']['value'] < cuc_timestamp(datetime.now(timezone.utc))) #todo - assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.utcnow())) + assert(header['end_timestamp']['value'] < cuc_timestamp(datetime.now(timezone.utc))) assert(header['data_type']['value'] == 1+0x8000) # assert(header['cmp_mode_used']['value'] == 2) # assert(header['model_value_used']['value'] == 8) @@ -1017,8 +1018,8 @@ def test_sample_used_is_to_big(): cmp_ent_size = IMAGETTE_HEADER_SIZE + len(cmp_data)//2 original_size = 0xE # wrong original_size correct is 0xA - start_time = cuc_timestamp(datetime.utcnow()) - end_time = cuc_timestamp(datetime.utcnow()) + start_time = cuc_timestamp(datetime.now(timezone.utc)) + end_time = cuc_timestamp(datetime.now(timezone.utc)) data_type = 1 cmp_mode_used = 2 @@ -1083,8 +1084,8 @@ def test_cmp_entity_not_4_byte_aligned(): cmp_ent_size = IMAGETTE_HEADER_SIZE + len(cmp_data)//2 original_size = 0xC - start_time = cuc_timestamp(datetime.utcnow()) - end_time = cuc_timestamp(datetime.utcnow()) + start_time = cuc_timestamp(datetime.now(timezone.utc)) + end_time = cuc_timestamp(datetime.now(timezone.utc)) data_type = 1 cmp_mode_used = 2 @@ -1177,8 +1178,8 @@ def test_header_read_in(): cmp_ent_size = IMAGETTE_HEADER_SIZE + len(cmp_data)//2 original_size = 0xA - start_time = cuc_timestamp(datetime.utcnow()) - end_time = cuc_timestamp(datetime.utcnow()) + start_time = cuc_timestamp(datetime.now(timezone.utc)) + end_time = cuc_timestamp(datetime.now(timezone.utc)) data_type = 1 cmp_mode_used = 2 -- GitLab