Skip to content

Commit

Permalink
Setup project for next minor release.
Browse files Browse the repository at this point in the history
 * Add couple test cases.
 * Update generation of version string for custom suffix.
 * Merge PEP-561 changes from @ZipFile.
  • Loading branch information
hjpotter92 committed Jun 24, 2021
1 parent c56ad0a commit 4360d6a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Changelog and release history
-----------------------------

## latest
## [1.3.0](https://pypi.org/project/sonyflake-py/1.3.0/) (2021-06-24)

- Fix timezone usage inconsistencies.
- Make a package PEP-561 compliant.
- Add test case for initialisation using `SONYFLAKE_EPOCH` constant.

## [1.2.1](https://pypi.org/project/sonyflake-py/1.2.1/) (2021-03-20)

Expand Down
2 changes: 1 addition & 1 deletion sonyflake/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
__version__: str = f"{MAJOR}.{MINOR}.{PATCH}"

if SUFFIX:
__version__ += SUFFIX
__version__ += f"-{SUFFIX}"

VERSION = __version__
25 changes: 24 additions & 1 deletion tests/test_sonyflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from time import sleep
from unittest import TestCase

from sonyflake.sonyflake import BIT_LEN_SEQUENCE, SonyFlake, lower_16bit_private_ip
from sonyflake.sonyflake import (
BIT_LEN_SEQUENCE,
SONYFLAKE_EPOCH,
SonyFlake,
lower_16bit_private_ip,
)


class SonyFlakeTestCase(TestCase):
Expand All @@ -22,6 +27,24 @@ def _current_time():
def _sleep(duration):
return sleep(duration / 100)

def test_sonyflake_epoch(self):
sf = SonyFlake(start_time=SONYFLAKE_EPOCH)
self.assertEqual(sf.start_time, 140952960000)
next_id = sf.next_id()
parts = SonyFlake.decompose(next_id)
self.assertEqual(parts["msb"], 0)
self.assertEqual(parts["machine_id"], self.machine_id)
self.assertEqual(parts["sequence"], 0)

def test_sonyflake_custom_machine_id(self):
machine_id = randint(1, 255 ** 2)
def get_machine_id():
return machine_id
sf = SonyFlake(machine_id=get_machine_id)
next_id = sf.next_id()
parts = SonyFlake.decompose(next_id)
self.assertEqual(parts["machine_id"], machine_id)

def test_sonyflake_once(self):
sleep_time = randint(1, 50)
self._sleep(sleep_time)
Expand Down

0 comments on commit 4360d6a

Please sign in to comment.