Skip to content

Commit 2da9d9a

Browse files
committed
rm dependency from arrow and fixed tests
1 parent 87f69e6 commit 2da9d9a

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/common-library/src/common_library/error_codes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ def _create_fingerprint(exc: BaseException) -> str:
4141
return hashlib.sha256(fingerprint.encode()).hexdigest()[:_LEN]
4242

4343

44-
_MILISECONDS: Final[int] = 1000
44+
_SECS_TO_MILISECS: Final[int] = 1000 # ms
4545

4646

4747
def _create_timestamp() -> int:
4848
"""Timestamp as milliseconds since epoch
4949
NOTE: this reduces the precission to milliseconds but it is good enough for our purpose
5050
"""
51-
ts = datetime.now(UTC).timestamp() * _MILISECONDS
51+
ts = datetime.now(UTC).timestamp() * _SECS_TO_MILISECS
5252
return int(ts)
5353

5454

@@ -79,5 +79,7 @@ def parse_error_code_parts(oec: ErrorCodeStr) -> tuple[str, datetime]:
7979
msg = f"Invalid error code format: {oec}"
8080
raise ValueError(msg)
8181
fingerprint = match.group("fingerprint")
82-
timestamp = arrow.get(int(match.group("timestamp")) / _MILISECONDS).datetime
82+
timestamp = datetime.fromtimestamp(
83+
float(match.group("timestamp")) / _SECS_TO_MILISECS, tz=UTC
84+
)
8385
return fingerprint, timestamp

packages/common-library/tests/test_error_codes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test_exception_fingerprint_consistency():
3636
# emulates different runs of the same function (e.g. different sessions)
3737
try:
3838
_level_one(v) # same even if different value!
39-
time.sleep(0.1)
4039
except Exception as err:
40+
time.sleep(1)
4141
error_code = create_error_code(err)
4242
error_codes.append(error_code)
4343

@@ -51,11 +51,11 @@ def test_exception_fingerprint_consistency():
5151
assert fingerprints[0] == fingerprints[1]
5252
assert timestamps[0] < timestamps[1]
5353

54-
time.sleep(0.1)
5554
try:
5655
# Same function but different location
5756
_level_one(0)
5857
except Exception as e2:
58+
time.sleep(1)
5959
error_code_2 = create_error_code(e2)
6060
fingerprint_2, timestamp_2 = parse_error_code_parts(error_code_2)
6161

0 commit comments

Comments
 (0)