def test_windows(self): self._uname = None self._version = None with mock.patch("platform.system", mock.MagicMock(return_value='Windows')): with mock.patch.object(OSInfo, "get_win_version_name", return_value="Windows 98"): with mock.patch.object(OSInfo, "get_win_os_version", return_value="4.0"): with remove_from_path("uname"): with remove_from_path("bash"): # FIXME: bug in environment_append removing variables which aren't exist (another PR) new_env = dict() if 'CONAN_BASH_PATH' in os.environ: new_env['CONAN_BASH_PATH'] = None with environment_append(new_env): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone( OSInfo.detect_windows_subsystem())
def _detect_os_arch(result, output): architectures = { 'i386': 'x86', 'i686': 'x86', 'i86pc': 'x86', 'amd64': 'x86_64', 'aarch64': 'armv8', 'sun4v': 'sparc' } the_os = detected_os() result.append(("os", the_os)) result.append(("os_build", the_os)) platform_machine = platform.machine().lower() if platform_machine: arch = architectures.get(platform_machine, platform_machine) if arch.startswith('arm'): for a in ("armv6", "armv7hf", "armv7", "armv8"): if arch.startswith(a): arch = a break else: output.error( "Your ARM '%s' architecture is probably not defined in settings.yml\n" "Please check your conan.conf and settings.yml files" % arch) elif arch.startswith('e2k'): arch = OSInfo.get_e2k_architecture() or arch elif OSInfo().is_aix: arch = OSInfo.get_aix_architecture() or arch result.append(("arch", arch)) result.append(("arch_build", arch))
def test_msys2(self): self._uname = 'MSYS_NT-10.0' self._version = '1.0.18(0.48/3/2)' with mock.patch("platform.system", mock.MagicMock(return_value=self._uname)): with mock.patch.object(OSInfo, "get_win_version_name", return_value="Windows 98"): with mock.patch.object(OSInfo, "get_win_os_version", return_value="4.0"): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertTrue(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with environment_append( {"CONAN_BASH_PATH": "/fake/bash.exe"}): with mock.patch('subprocess.check_output', new=self.subprocess_check_output_mock): self.assertEqual(OSInfo.uname(), self._uname.lower()) self.assertEqual(OSInfo.detect_windows_subsystem(), MSYS)
def test_solaris(self): with mock.patch("platform.system", mock.MagicMock(return_value='SunOS')): self.assertFalse(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertTrue(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone(OSInfo.detect_windows_subsystem())
def _detect_os_arch(result, output): architectures = {'i386': 'x86', 'i686': 'x86', 'i86pc': 'x86', 'amd64': 'x86_64', 'aarch64': 'armv8', 'sun4v': 'sparc'} the_os = detected_os() result.append(("os", the_os)) result.append(("os_build", the_os)) platform_machine = platform.machine().lower() if platform_machine: arch = architectures.get(platform_machine, platform_machine) if arch.startswith('arm'): for a in ("armv6", "armv7hf", "armv7", "armv8"): if arch.startswith(a): arch = a break else: output.error("Your ARM '%s' architecture is probably not defined in settings.yml\n" "Please check your conan.conf and settings.yml files" % arch) elif the_os == 'AIX': processor = platform.processor() if "powerpc" in processor: kernel_bitness = OSInfo().get_aix_conf("KERNEL_BITMODE") if kernel_bitness: arch = "ppc64" if kernel_bitness == "64" else "ppc32" elif "rs6000" in processor: arch = "ppc32" result.append(("arch", arch)) result.append(("arch_build", arch))
def test_windows(self): self._uname = None self._version = None with mock.patch("platform.system", mock.MagicMock(return_value='Windows')): with remove_from_path("uname"): with remove_from_path("bash"): with environment_append({'CONAN_BASH_PATH': None}): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone(OSInfo.detect_windows_subsystem())
def test_wsl(self): from six.moves import builtins with mock.patch("platform.system", mock.MagicMock(return_value='Linux')): with mock.patch.object(OSInfo, '_get_linux_distro_info'): self.assertFalse(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertTrue(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with self.assertRaises(ConanException): OSInfo.uname() with mock.patch.object(builtins, "open", mock.mock_open(read_data="4.4.0-43-Microsoft")): self.assertEqual(OSInfo.detect_windows_subsystem(), WSL)
def test_cygwin(self): self._uname = 'CYGWIN_NT-10.0' self._version = '2.11.2(0.329/5/3)' with mock.patch("platform.system", mock.MagicMock(return_value=self._uname)): self.assertTrue(OSInfo().is_windows) self.assertTrue(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) self.assertFalse(OSInfo().is_aix) with environment_append({"CONAN_BASH_PATH": "/fake/bash.exe"}): with mock.patch('conans.client.tools.oss.check_output', new=self.subprocess_check_output_mock): self.assertEqual(OSInfo.uname(), self._uname.lower()) self.assertEqual(OSInfo.detect_windows_subsystem(), CYGWIN)
def test_mingw64(self): self._uname = 'MINGW64_NT-10.0' self._version = '2.4.0(0.292/5/3)' with mock.patch("platform.system", mock.MagicMock(return_value=self._uname)): self.assertTrue(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertTrue(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) with environment_append({"CONAN_BASH_PATH": "/fake/bash.exe"}): with mock.patch('subprocess.check_output', new=self.subprocess_check_output_mock): self.assertEqual(OSInfo.uname(), self._uname.lower()) self.assertEqual(OSInfo.detect_windows_subsystem(), MSYS2)
self.assertEqual(generator.env["BASE_VAR"], 'baseValue') self.assertEqual(generator.env["BCKW_SLASH"], 'dummy\\value') self.assertEqual(generator.env["CPPFLAGS"], ['-flag1', '-flag2', '-baseFlag1', '-baseFlag2']) self.assertEqual( generator.env["LD_LIBRARY_PATH"], [os.path.join("dummydir", "lib"), os.path.join("basedir", "lib")]) self.assertEqual(generator.env["PATH"], [ os.path.join("dummydir", "bin"), os.path.join("basedir", "bin"), 'samebin' ]) self.assertEqual(generator.env["SPECIAL_VAR"], 'dummyValue') os_info = OSInfo() def _load_env_file(filename): return dict(l.split("=", 1) for l in load(filename).splitlines()) class PosixShellCommands(object): id = shell = "sh" activate = ". ./activate.sh" deactivate = ". ./deactivate.sh" dump_env = "env > {filename}" find_program = "echo {variable}=$(which {program})" @property def skip(self):
def test_aix(self): self._uname = 'AIX' self._version = '7.1.0.0' with mock.patch("platform.system", mock.MagicMock(return_value='AIX')), \ mock.patch('conans.client.tools.oss.check_output', new=self.subprocess_check_output_mock): self.assertFalse(OSInfo().is_windows) self.assertFalse(OSInfo().is_cygwin) self.assertFalse(OSInfo().is_msys) self.assertFalse(OSInfo().is_linux) self.assertFalse(OSInfo().is_freebsd) self.assertFalse(OSInfo().is_macos) self.assertFalse(OSInfo().is_solaris) self.assertTrue(OSInfo().is_aix) self.assertEqual(OSInfo().os_version_name, 'AIX 7.1') with self.assertRaises(ConanException): OSInfo.uname() self.assertIsNone(OSInfo.detect_windows_subsystem())