diff --git a/src/remoting/python-remoting/nexus_remoting/_encoder.py b/src/remoting/python-remoting/nexus_remoting/_encoder.py index f559f6c..002ce99 100644 --- a/src/remoting/python-remoting/nexus_remoting/_encoder.py +++ b/src/remoting/python-remoting/nexus_remoting/_encoder.py @@ -47,7 +47,7 @@ def _try_encode(value: Any, options: JsonEncoderOptions) -> Any: # None if value is None: - return typing.cast(T, None) + return None # list/tuple elif isinstance(value, list) or isinstance(value, tuple): @@ -192,7 +192,7 @@ def _decode_timedelta(value: str): seconds = int(match.group(4)) microseconds = int(match.group(5)) / 10.0 if match.group(5) else 0 - return typing.cast(T, timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds)) + return timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds, microseconds=microseconds) else: raise Exception(f"Unable to decode {value} into value of type timedelta.") diff --git a/tests/Nexus.Sources.Remote.Tests/python/remote.py b/tests/Nexus.Sources.Remote.Tests/python/remote.py index 92f3337..a14e751 100644 --- a/tests/Nexus.Sources.Remote.Tests/python/remote.py +++ b/tests/Nexus.Sources.Remote.Tests/python/remote.py @@ -15,13 +15,20 @@ class PythonDataSource(IDataSource): + _root: str + async def set_context(self, context, logger): self._context: DataSourceContext = context + if (context.resource_locator is None or context.resource_locator.path is None): + raise Exception(f"No resource locator provided.") + if (context.resource_locator.scheme != "file"): raise Exception(f"Expected 'file' URI scheme, but got '{context.resource_locator.scheme}'.") + self._root = context.resource_locator.path + logger.log(LogLevel.Information, "Logging works!") async def get_catalog_registrations(self, path: str): @@ -85,7 +92,7 @@ async def get_time_range(self, catalog_id: str): if catalog_id != "/A/B/C": raise Exception("Unknown catalog identifier.") - file_paths = glob.glob(url2pathname(self._context.resource_locator.path) + "/**/*.dat", recursive=True) + file_paths = glob.glob(url2pathname(self._root) + "/**/*.dat", recursive=True) file_names = [os.path.basename(file_path) for file_path in file_paths] date_times = sorted([datetime.strptime(fileName, '%Y-%m-%d_%H-%M-%S.dat') for fileName in file_names]) begin = date_times[0].replace(tzinfo = timezone.utc) @@ -100,7 +107,7 @@ async def get_availability(self, catalog_id: str, begin: datetime, end: datetime period_per_file = timedelta(minutes = 10) max_file_count = (end - begin).total_seconds() / period_per_file.total_seconds() - file_paths = glob.glob(url2pathname(self._context.resource_locator.path) + "/**/*.dat", recursive=True) + file_paths = glob.glob(url2pathname(self._root) + "/**/*.dat", recursive=True) file_names = [os.path.basename(file_path) for file_path in file_paths] date_times = [datetime.strptime(fileName, '%Y-%m-%d_%H-%M-%S.dat') for fileName in file_names] filtered_date_times = [current for current in date_times if current >= begin and current < end] @@ -152,7 +159,7 @@ async def _read_local_files( while current_begin < end: # find files - search_pattern = url2pathname(self._context.resource_locator.path) + \ + search_pattern = url2pathname(self._root) + \ f"/{current_begin.strftime('%Y-%m')}/{current_begin.strftime('%Y-%m-%d')}/*.dat" file_paths = glob.glob(search_pattern, recursive=True)