Skip to content

Commit

Permalink
Make all tests work on Windows (#32)
Browse files Browse the repository at this point in the history
(DIS-2009)
  • Loading branch information
Poeloe authored Sep 8, 2023
1 parent 7326cf6 commit 3b865b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dissect/util/ts.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
14 changes: 8 additions & 6 deletions tests/test_ts.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3b865b7

Please sign in to comment.