-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
213b554
commit 3cc5faf
Showing
1 changed file
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,43 @@ | ||
from aleph_message.utils import Gigabytes, gigabyte_to_mebibyte | ||
from datetime import datetime, date, time | ||
|
||
import pytest | ||
from pydantic import BaseModel | ||
|
||
from aleph_message.utils import Gigabytes, gigabyte_to_mebibyte, extended_json_encoder, dump_content | ||
|
||
|
||
def test_gigabyte_to_mebibyte(): | ||
assert gigabyte_to_mebibyte(Gigabytes(1)) == 954 | ||
assert gigabyte_to_mebibyte(Gigabytes(100)) == 95368 | ||
|
||
|
||
def test_extended_json_encoder(): | ||
now = datetime.now() | ||
today = date.today() | ||
now_time = time(hour=1, minute=2, second=3, microsecond=4) | ||
assert extended_json_encoder(now) == now.timestamp() | ||
assert extended_json_encoder(today) == today.toordinal() | ||
assert extended_json_encoder(now_time) == 3723.000004 | ||
|
||
|
||
def test_dump_content(): | ||
class TestModel(BaseModel): | ||
address: str | ||
time: float | ||
|
||
assert dump_content({"address": "0x1", "time": 1.0}) == '{"address":"0x1","time":1.0}' | ||
assert dump_content(TestModel(address="0x1", time=1.0)) == '{"address":"0x1","time":1.0}' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"content", | ||
[ | ||
1, | ||
"test", | ||
None, | ||
True, | ||
], | ||
) | ||
def test_dump_content_invalid(content): | ||
with pytest.raises(TypeError): | ||
dump_content(content) |