From 5c0f3ca30f1b1a84f88f1aa185909b7f42be6c8c Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Thu, 13 Aug 2020 17:52:55 -0700 Subject: [PATCH 1/2] Handle file not found exceptions on Python 2.7 --- msal_extensions/token_cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msal_extensions/token_cache.py b/msal_extensions/token_cache.py index bf55448..d425c4d 100644 --- a/msal_extensions/token_cache.py +++ b/msal_extensions/token_cache.py @@ -35,7 +35,7 @@ def _reload_if_necessary(self): if self._last_sync < self._persistence.time_last_modified(): self.deserialize(self._persistence.load()) self._last_sync = time.time() - except IOError as exp: + except EnvironmentError as exp: if exp.errno != errno.ENOENT: raise # Otherwise, from cache's perspective, a nonexistent file is a NO-OP From 2ec6924129495f265d91d50162646c3fe25f7764 Mon Sep 17 00:00:00 2001 From: Abhidnya Date: Tue, 25 Aug 2020 15:57:55 -0700 Subject: [PATCH 2/2] Adding test case for this scenario --- tests/test_agnostic_backend.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_agnostic_backend.py b/tests/test_agnostic_backend.py index 4619391..29ca8a0 100644 --- a/tests/test_agnostic_backend.py +++ b/tests/test_agnostic_backend.py @@ -44,3 +44,8 @@ def test_current_platform_cache_roundtrip_with_alias_class(temp_location): def test_persisted_token_cache(temp_location): _test_token_cache_roundtrip(PersistedTokenCache(FilePersistence(temp_location))) +def test_file_not_found_error_is_not_raised(): + persistence = FilePersistence('non_existing_file') + cache = PersistedTokenCache(persistence=persistence) + # An exception raised here will fail the test case as it is supposed to be a NO-OP + cache.find('')