From 4360d6a3617f3fc03a554587a843fdfa99a86903 Mon Sep 17 00:00:00 2001 From: hjpotter92 Date: Thu, 24 Jun 2021 18:25:34 +0530 Subject: [PATCH] Setup project for next minor release. * Add couple test cases. * Update generation of version string for custom suffix. * Merge PEP-561 changes from @ZipFile. --- docs/src/changelog.md | 3 ++- sonyflake/about.py | 2 +- tests/test_sonyflake.py | 25 ++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 8b1ada6..e94370a 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -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) diff --git a/sonyflake/about.py b/sonyflake/about.py index db2e733..f4eaa09 100644 --- a/sonyflake/about.py +++ b/sonyflake/about.py @@ -16,6 +16,6 @@ __version__: str = f"{MAJOR}.{MINOR}.{PATCH}" if SUFFIX: - __version__ += SUFFIX + __version__ += f"-{SUFFIX}" VERSION = __version__ diff --git a/tests/test_sonyflake.py b/tests/test_sonyflake.py index 699894d..e9d4ba1 100644 --- a/tests/test_sonyflake.py +++ b/tests/test_sonyflake.py @@ -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): @@ -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)