From d43273fa4bc02dff91c44abfe86deddc2781610f Mon Sep 17 00:00:00 2001 From: BryanFauble <17128019+BryanFauble@users.noreply.github.com> Date: Wed, 20 Dec 2023 11:53:19 -0700 Subject: [PATCH] Correct a few piece sonar flagged --- synapseclient/core/utils.py | 20 +++++++++++++++---- synapseutils/sync.py | 2 +- .../unit_test_synapseutils_sync.py | 1 - 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/synapseclient/core/utils.py b/synapseclient/core/utils.py index b352a3656..352c07134 100644 --- a/synapseclient/core/utils.py +++ b/synapseclient/core/utils.py @@ -551,10 +551,22 @@ def from_unix_epoch_time(ms) -> datetime.datetime: return from_unix_epoch_time_secs(ms / 1000.0) -def datetime_to_iso(dt, sep="T", include_milliseconds=True) -> str: - # Round microseconds to milliseconds (as expected by older clients) - # and add back the "Z" at the end. - # see: http://stackoverflow.com/questions/30266188/how-to-convert-date-string-to-iso8601-standard +def datetime_to_iso( + dt: datetime.datetime, sep: str = "T", include_milliseconds: bool = True +) -> str: + """ + Round microseconds to milliseconds (as expected by older clients) and add back + the "Z" at the end. + See: http://stackoverflow.com/questions/30266188/how-to-convert-date-string-to-iso8601-standard + + Args: + dt: The datetime to convert + sep: Seperator character to use. + include_milliseconds: Whether or not to include millseconds in this result. + + Returns: + The formatted string. + """ fmt = ( "{time.year:04}-{time.month:02}-{time.day:02}" "{sep}{time.hour:02}:{time.minute:02}:{time.second:02}.{millisecond:03}{tz}" diff --git a/synapseutils/sync.py b/synapseutils/sync.py index 1f11f0b17..f9cc4dac0 100644 --- a/synapseutils/sync.py +++ b/synapseutils/sync.py @@ -854,7 +854,7 @@ def _convert_manifest_data_items_to_string_list( return items_to_write -def _convert_manifest_data_row_to_dict(row: dict, keys: typing.List[str]) -> str: +def _convert_manifest_data_row_to_dict(row: dict, keys: typing.List[str]) -> dict: """ Convert a row of data to a dict that can be written to a manifest file. diff --git a/tests/unit/synapseutils/unit_test_synapseutils_sync.py b/tests/unit/synapseutils/unit_test_synapseutils_sync.py index b95fb57af..0439e3602 100644 --- a/tests/unit/synapseutils/unit_test_synapseutils_sync.py +++ b/tests/unit/synapseutils/unit_test_synapseutils_sync.py @@ -1004,7 +1004,6 @@ def test_abort(self): future_3.cancel.assert_called_once_with() @pytest.mark.flaky(reruns=3, only_rerun=["AssertionError"]) - @pytest.mark.skip # TODO: Remove me. Just for local def test_upload_error(self, syn): """Verify that if an item upload fails the error is raised in the main thread and any running Futures are cancelled"""