Skip to content

Commit

Permalink
fix tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Mar 18, 2024
1 parent 1bba09f commit 4c1a1ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions berserk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class Game(Model):

class GameState(Model):
createdAt = utils.datetime_from_millis
wtime = utils.timedelta_from_milis
btime = utils.timedelta_from_milis
wtime = utils.timedelta_from_millis
btime = utils.timedelta_from_millis
winc = utils.datetime_from_millis
binc = utils.datetime_from_millis

Expand Down
2 changes: 2 additions & 0 deletions berserk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def timedelta_from_millis(millis: float) -> timedelta:
for a given milliseconds.
"""
return timedelta(milliseconds=millis)


def datetime_from_seconds(ts: float) -> datetime:
"""Return the datetime for the given seconds since the epoch.
Expand Down
11 changes: 5 additions & 6 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from berserk import models
from berserk import models, utils


def test_conversion():
Expand All @@ -9,17 +9,16 @@ class Example(models.Model):
modified = {"foo": 5, "bar": 3, "baz": "4"}
assert Example.convert(original) == modified


def test_time_delta():
"""test timedelta_from millis"""
test_data = 1000.0
dt1 = datetime_from_millis(test_data)
dt2 = datetime_from_millis(2 * test_data)
dt1 = utils.datetime_from_millis(test_data)
dt2 = utils.datetime_from_millis(2 * test_data)

delta_1 = timedelta_from_millis(test_data)
delta_1 = utils.timedelta_from_millis(test_data)

# time delta dt1 dt2
delta_2 = dt2 - dt1

assert delta_1 == delta_2


0 comments on commit 4c1a1ce

Please sign in to comment.