From 7ac2cc072ea9a09aff19e37aabc2acc1639cb30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Rami=CC=81rez=20Mondrago=CC=81n?= Date: Mon, 11 Jul 2022 13:27:07 +0200 Subject: [PATCH] docs: Add doctest for `get_starting_timestamp` --- singer_sdk/streams/core.py | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/singer_sdk/streams/core.py b/singer_sdk/streams/core.py index 567d7284d1..74508f195a 100644 --- a/singer_sdk/streams/core.py +++ b/singer_sdk/streams/core.py @@ -272,6 +272,52 @@ def get_starting_timestamp(self, context: dict | None) -> datetime.datetime | No Raises: ValueError: If the replication value is not a valid timestamp. + + >>> from singer_sdk import Tap + + >>> class MyStream(Stream): + >>> name = "my_stream" + >>> replication_key = "updated_at" + ... def get_records(self, context): + ... return [{'id': 1, 'updated_at': '2023-01-01T00:00:00Z'}] + + >>> class MyTap(Tap): + ... name = "my_tap" + ... + ... def discover_streams(self): + ... return [ + ... MyStream( + ... tap=self, + ... schema={ + ... "properties": { + ... "id": {"type": "integer"}, + ... "updated_at": { + ... "type": "string", + ... "format": "date-time", + ... }, + ... } + ... }, + ... ) + ... ] + + >>> tap = MyTap( + ... config={}, + ... state={ + ... "bookmarks": { + ... "my_stream": { + ... "partitions": [], + ... "replication_key": "updated_at", + ... "replication_key_value": "2020-01-01T00:00:00Z", + ... } + ... } + ... }, + ... ) + + >>> tap.streams["my_stream"].is_timestamp_replication_key + True + >>> tap.streams["my_stream"]._write_starting_replication_value(None) + >>> tap.streams["my_stream"].get_starting_timestamp(None) + DateTime(2020, 1, 1, 0, 0, 0, tzinfo=Timezone('UTC')) """ value = self.get_starting_replication_key_value(context)