Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | for k in keys_to_check: | ||||
assert actual_list == expected_list, k | assert actual_list == expected_list, k | ||||
def round_to_milliseconds(date): | def round_to_milliseconds(date): | ||||
"""Round datetime to milliseconds before insertion, so equality doesn't fail after a | """Round datetime to milliseconds before insertion, so equality doesn't fail after a | ||||
round-trip through a DB (eg. Cassandra) | round-trip through a DB (eg. Cassandra) | ||||
""" | """ | ||||
return date.replace(microsecond=round(date.microsecond, -3)) | return date.replace(microsecond=date.microsecond // 1000000) | ||||
olasd: Dividing date.microsecond by 1_000_000 will always return 0, as date.microsecond is 0 < x <… | |||||
olasdUnsubmitted Not Done Inline Actions(Of course, this should read 0 <= x < 1_000_000.) olasd: (Of course, this should read `0 <= x < 1_000_000`.) | |||||
ardumontAuthorUnsubmitted Done Inline Actionsd'oh lol, yeah thanks. ardumont: d'oh lol, yeah
thanks. | |||||
class LazyContent(Content): | class LazyContent(Content): | ||||
def with_data(self): | def with_data(self): | ||||
return Content.from_dict({**self.to_dict(), "data": data.cont["data"]}) | return Content.from_dict({**self.to_dict(), "data": data.cont["data"]}) | ||||
class TestStorage: | class TestStorage: | ||||
▲ Show 20 Lines • Show All 3,971 Lines • Show Last 20 Lines |
Dividing date.microsecond by 1_000_000 will always return 0, as date.microsecond is 0 < x < 1_000_000.
To truncate to milliseconds, you need to (integer) divide by 1000, then multiply the result by 1000.
(so, (date.microsecond // 1000) * 1000).
I suggest adding tests for the edge cases, that is, microsecond=0, microsecond=1000, and microsecond=999500.