From 3b865b7c72e57a8f1ce3113ab7e49a2b8f5014a7 Mon Sep 17 00:00:00 2001 From: Paul M <22234727+Poeloe@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:51:38 +0200 Subject: [PATCH] Make all tests work on Windows (#32) (DIS-2009) --- dissect/util/ts.py | 4 ++-- tests/test_ts.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dissect/util/ts.py b/dissect/util/ts.py index 59ab972..1118945 100644 --- a/dissect/util/ts.py +++ b/dissect/util/ts.py @@ -1,9 +1,9 @@ import struct +import sys from datetime import datetime, timedelta, timezone, tzinfo -from platform import system from typing import Dict -if system().lower() in ("windows", "emscripten"): +if sys.platform in ("win32", "emscripten"): _EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc) def _calculate_timestamp(ts: float) -> datetime: diff --git a/tests/test_ts.py b/tests/test_ts.py index cbd98f8..283f46e 100644 --- a/tests/test_ts.py +++ b/tests/test_ts.py @@ -1,5 +1,5 @@ import platform -from datetime import datetime, timezone +from datetime import datetime, timedelta, timezone from importlib import reload from unittest.mock import patch @@ -21,10 +21,14 @@ def ts(): yield reload(ts) -@pytest.mark.skipif(platform.system() == "Windows", reason="Time Calculation error. Needs to be fixed.") def test_now(ts): - assert ts.now() < datetime.now(timezone.utc) - assert ts.now().tzinfo == timezone.utc + ts_now = ts.now() + datetime_now = datetime.now(timezone.utc) + time_diff = datetime_now - ts_now + + # Should be no difference, so only set microseconds equal to remove processing time difference + assert timedelta(microseconds=time_diff.microseconds) == time_diff + assert ts_now.tzinfo == timezone.utc def test_unix_now(imported_ts): @@ -111,7 +115,6 @@ def test_wintimestamp(imported_ts): ) -@pytest.mark.skipif(platform.system() == "Windows", reason="Time Calculation error. Needs to be fixed.") def test_oatimestamp(imported_ts): dt = datetime(2016, 10, 17, 4, 6, 38, 362003, tzinfo=timezone.utc) assert imported_ts.oatimestamp(42660.171277338) == dt @@ -130,7 +133,6 @@ def test_cocoatimestamp(imported_ts): assert imported_ts.cocoatimestamp(622894123.221783) == datetime(2020, 9, 27, 10, 8, 43, 221783, tzinfo=timezone.utc) -@pytest.mark.skipif(platform.system() == "Windows", reason="Time Calculation error. Needs to be fixed.") def test_negative_timestamps(imported_ts): # -5000.0 converted to a int representation assert imported_ts.oatimestamp(13885591609694748672) == datetime(1886, 4, 22, 0, 0, tzinfo=timezone.utc)