@@ -366,10 +366,13 @@ def setUp(self):
366366 self .orig_is_readable = st .is_readable
367367 self .orig_read_file = st .read_file
368368 self .orig_run_cmd = st .run_cmd
369+ self .orig_platform_dist = st .platform .dist if hasattr (st .platform , 'dist' ) else None
369370 self .orig_platform_uname = st .platform .uname
370371 self .orig_get_tool_version = st .get_tool_version
371372 self .orig_sys_version_info = st .sys .version_info
372373 self .orig_HAVE_ARCHSPEC = st .HAVE_ARCHSPEC
374+ self .orig_HAVE_DISTRO = st .HAVE_DISTRO
375+ self .orig_ETC_OS_RELEASE = st .ETC_OS_RELEASE
373376 if hasattr (st , 'archspec_cpu_host' ):
374377 self .orig_archspec_cpu_host = st .archspec_cpu_host
375378 else :
@@ -383,10 +386,14 @@ def tearDown(self):
383386 st .get_os_name = self .orig_get_os_name
384387 st .get_os_type = self .orig_get_os_type
385388 st .run_cmd = self .orig_run_cmd
389+ if self .orig_platform_dist is not None :
390+ st .platform .dist = self .orig_platform_dist
386391 st .platform .uname = self .orig_platform_uname
387392 st .get_tool_version = self .orig_get_tool_version
388393 st .sys .version_info = self .orig_sys_version_info
389394 st .HAVE_ARCHSPEC = self .orig_HAVE_ARCHSPEC
395+ st .HAVE_DISTRO = self .orig_HAVE_DISTRO
396+ st .ETC_OS_RELEASE = self .orig_ETC_OS_RELEASE
390397 if self .orig_archspec_cpu_host is not None :
391398 st .archspec_cpu_host = self .orig_archspec_cpu_host
392399 super (SystemToolsTest , self ).tearDown ()
@@ -738,6 +745,21 @@ def test_os_version(self):
738745 os_version = get_os_version ()
739746 self .assertTrue (isinstance (os_version , string_type ) or os_version == UNKNOWN )
740747
748+ # make sure that bug fixed in https://github.com/easybuilders/easybuild-framework/issues/3952
749+ # does not surface again, by mocking what's needed to make get_os_version fall into SLES-specific path
750+
751+ if hasattr (st .platform , 'dist' ):
752+ st .platform .dist = lambda : (None , None )
753+ st .HAVE_DISTRO = False
754+
755+ st .get_os_name = lambda : 'SLES'
756+ fake_etc_os_release = os .path .join (self .test_prefix , 'os-release' )
757+ write_file (fake_etc_os_release , 'VERSION="15-SP1"' )
758+ st .ETC_OS_RELEASE = fake_etc_os_release
759+
760+ os_version = get_os_version ()
761+ self .assertEqual (os_version , '15-SP1' )
762+
741763 def test_gcc_version_native (self ):
742764 """Test getting gcc version."""
743765 gcc_version = get_gcc_version ()
0 commit comments