-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readme updated & added isort, black, flake8, pre-commit, ruff, mypy a…
…dded
- Loading branch information
1 parent
fd886be
commit 3ae90fe
Showing
7 changed files
with
128 additions
and
73 deletions.
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
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,37 +1,56 @@ | ||
from typing import NewType, Union | ||
|
||
# from bee_py.chunk.serialize import serialize_bytes | ||
from pydantic import BaseModel | ||
|
||
from bee_py.chunk.serialize import serialize_bytes | ||
from bee_py.chunk.signer import sign | ||
from bee_py.chunk.soc import download_single_owner_chunk, upload_single_owner_chunk_data | ||
from bee_py.feed.identifiers import make_feed_identifier | ||
from bee_py.feed.type import FeedType | ||
from bee_py.modules.chunk import * | ||
from bee_py.types.type import ( # Reference, | ||
BatchId, | ||
BeeRequestOptions, | ||
FeedReader, | ||
FeedType, | ||
FeedUpdateOptions, | ||
FeedWriter, | ||
JsonFeedOptions, | ||
UploadOptions, | ||
) | ||
from bee_py.utils.collection import assert_collection, make_collection | ||
from bee_py.utils.hash import keccak_hash | ||
from bee_py.utils.hex import bytes_to_hex, hex_to_bytes, make_hex_string | ||
from bee_py.utils.reference import make_bytes_reference | ||
|
||
TIMESTAMP_PAYLOAD_SIZE = 8 | ||
TIMESTAMP_PAYLOAD_SIZE_HEX = 16 | ||
REFERENCE_PAYLOAD_OFFSET = TIMESTAMP_PAYLOAD_SIZE | ||
|
||
|
||
IndexBytes = NewType("IndexBytes", bytes) | ||
|
||
|
||
class Epoch: | ||
def __init__(self, time: int, level: int): | ||
self.time = time | ||
self.level = level | ||
|
||
|
||
class Index: | ||
def __init__(self, value: Union[int, Epoch, bytes, str]): | ||
self._validate(value) | ||
self._value = value | ||
|
||
def _validate(self, value: Union[int, Epoch, bytes, str]): | ||
if not ( | ||
isinstance(value, (int, Epoch)) | ||
or (isinstance(value, bytes) and len(value) == TIMESTAMP_PAYLOAD_SIZE) | ||
or ( | ||
isinstance(value, str) | ||
and len(value) == TIMESTAMP_PAYLOAD_SIZE_HEX | ||
and all(c in "0123456789abcdefABCDEF" for c in value) | ||
) | ||
): | ||
msg = "Index must be an int, Epoch, 8-byte bytes, or a hex string of length 16" | ||
raise ValueError(msg) | ||
|
||
def __str__(self): | ||
return str(self._value) | ||
class Epoch(BaseModel): | ||
""" | ||
Epoch model. | ||
:param time: The time of the epoch. | ||
:type time: int | ||
:param level: The level of the epoch. | ||
:type level: int | ||
""" | ||
|
||
time: int | ||
level: int | ||
|
||
|
||
class Index(BaseModel): | ||
""" | ||
Index model. | ||
:param index: The index can be a number, an epoch, index bytes or a string. | ||
:type index: Union[int, Epoch, bytes, str] | ||
""" | ||
|
||
index: Union[int, Epoch, bytes, str] |
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
File renamed without changes.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
|
||
def is_integer(value): | ||
return isinstance(value, int) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value, expected", | ||
[ | ||
# Wrong values | ||
(lambda: {}, False), | ||
(5.000000000000001, False), | ||
("False", False), | ||
("True", False), | ||
(float("inf"), False), | ||
(float("nan"), False), | ||
([1], False), | ||
# Correct values | ||
(5, True), | ||
(0, True), | ||
(10, True), | ||
(-1, True), | ||
], | ||
) | ||
def test_is_integer(value, expected): | ||
assert is_integer(value) == expected |