@@ -406,6 +406,47 @@ def _import_mock(name, *args):
406406 assert not has_error
407407
408408
409+ @pytest .mark .skip_unless_on_linux
410+ @pytest .mark .skipif (
411+ sys .version_info < (3 , 10 ),
412+ reason = "platform.freedesktop_os_release not available in Python < 3.10" ,
413+ )
414+ def test__freedesktop_os_release_cache_is_invalidated ():
415+ OS_RELEASE_DATA = {
416+ "NAME" : "openSUSE Leap" ,
417+ "ID" : "opensuse-leap" ,
418+ "PRETTY_NAME" : "openSUSE Leap 15.6" ,
419+ "VERSION" : "15.6" ,
420+ "ID_LIKE" : "suse opensuse" ,
421+ "VERSION_ID" : "15.6" ,
422+ "ANSI_COLOR" : "0;32" ,
423+ "CPE_NAME" : "cpe:/o:opensuse:leap:15.6" ,
424+ "BUG_REPORT_URL" : "https://bugs.opensuse.org" ,
425+ "HOME_URL" : "https://www.opensuse.org/" ,
426+ "DOCUMENTATION_URL" : "https://en.opensuse.org/Portal:Leap" ,
427+ "LOGO" : "distributor-logo-Leap" ,
428+ }
429+
430+ class FreeDesktopOSReleaseMock :
431+ def __call__ (self ):
432+ if hasattr (platform , "_os_release_cache" ):
433+ assert platform ._os_release_cache is None
434+ return OS_RELEASE_DATA
435+
436+ with patch .object (
437+ core , "_linux_lsb_distrib_data" , MagicMock (return_value = ({}, None ))
438+ ), patch .object (
439+ core , "_freedesktop_os_release" , FreeDesktopOSReleaseMock ()
440+ ), patch .object (
441+ core ,
442+ "_legacy_linux_distribution_data" ,
443+ MagicMock (return_value = {"osrelease" : "15.6" }),
444+ ):
445+ platform ._os_release_cache = {"this-cache-should-be-invalidated" : "foobar" }
446+ ret = core ._linux_distribution_data ()
447+ assert ret == {"osrelease" : "15.6" }
448+
449+
409450@pytest .mark .skip_unless_on_linux
410451def test_gnu_slash_linux_in_os_name ():
411452 """
0 commit comments