def system_package_tool_fail_when_not_0_returned_test(self): def get_linux_error_message(): """ Get error message for Linux platform if distro is supported, None otherwise """ os_info = OSInfo() update_command = None if os_info.with_apt: update_command = "sudo apt-get update" elif os_info.with_yum: update_command = "sudo yum check-update" elif os_info.with_zypper: update_command = "sudo zypper --non-interactive ref" elif os_info.with_pacman: update_command = "sudo pacman -Syyu --noconfirm" return "Command '{0}' failed".format(update_command) if update_command is not None else None platform_update_error_msg = { "Linux": get_linux_error_message(), "Darwin": "Command 'brew update' failed", "Windows": "Command 'choco outdated' failed" if which("choco.exe") else None, } runner = RunnerMock(return_ok=False) pkg_tool = ChocolateyTool() if which("choco.exe") else None spt = SystemPackageTool(runner=runner, tool=pkg_tool) msg = platform_update_error_msg.get(platform.system(), None) if msg is not None: with self.assertRaisesRegexp(ConanException, msg): spt.update() else: spt.update() # Won't raise anything because won't do anything
def system_package_tool_fail_when_not_0_returned_test(self): runner = RunnerMock(return_ok=False) spt = SystemPackageTool(runner=runner) platforms = {"Linux": "sudo apt-get update", "Darwin": "brew update"} if platform.system() in platforms: msg = "Command '%s' failed" % platforms[platform.system()] with self.assertRaisesRegexp(ConanException, msg): spt.update() elif platform.system() == "Windows" and which("choco.exe"): spt = SystemPackageTool(runner=runner, tool=ChocolateyTool()) with self.assertRaisesRegexp(ConanException, "Command 'choco outdated' failed"): spt.update() else: spt.update() # Won't raise anything because won't do anything
def system_package_tool_installed_test(self): if platform.system() != "Linux" and platform.system() != "Macos" and platform.system() != "Windows": return if platform.system() == "Windows" and not which("choco.exe"): return spt = SystemPackageTool() expected_package = "git" if platform.system() == "Windows" and which("choco.exe"): spt = SystemPackageTool(tool=ChocolateyTool()) # Git is not installed by default on Chocolatey expected_package = "chocolatey" # The expected should be installed on development/testing machines self.assertTrue(spt._tool.installed(expected_package)) # This package hopefully doesn't exist self.assertFalse(spt._tool.installed("oidfjgesiouhrgioeurhgielurhgaeiorhgioearhgoaeirhg"))
def system_package_tool_test(self): with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): runner = RunnerMock() # fake os info to linux debian, default sudo os_info = OSInfo() os_info.is_macos = False os_info.is_linux = True os_info.is_windows = False os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "knoppix" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo apt-get update") os_info.linux_distro = "fedora" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo yum check-update") os_info.linux_distro = "opensuse" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo zypper --non-interactive ref") os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=False) self.assertEquals(runner.command_called, "rpm -q a_package") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "sudo yum install -y a_package") os_info.linux_distro = "debian" spt = SystemPackageTool(runner=runner, os_info=os_info) with self.assertRaises(ConanException): runner.return_ok = False spt.install("a_package") self.assertEquals( runner.command_called, "sudo apt-get install -y --no-install-recommends a_package" ) runner.return_ok = True spt.install("a_package", force=False) self.assertEquals(runner.command_called, "dpkg -s a_package") os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "sudo pkg update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "sudo pkg install -y a_package") spt.install("a_package", force=False) self.assertEquals(runner.command_called, "pkg info a_package") # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_freebsd = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, tool=ChocolateyTool()) spt.update() self.assertEquals(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEquals( runner.command_called, 'choco search --local-only --exact a_package | findstr /c:"1 packages installed."' ) with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}): os_info = OSInfo() os_info.is_linux = True os_info.linux_distro = "redhat" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=True) self.assertEquals(runner.command_called, "yum install -y a_package") spt.update() self.assertEquals(runner.command_called, "yum check-update") os_info.linux_distro = "ubuntu" spt = SystemPackageTool(runner=runner, os_info=os_info) spt.install("a_package", force=True) self.assertEquals( runner.command_called, "apt-get install -y --no-install-recommends a_package") spt.update() self.assertEquals(runner.command_called, "apt-get update") os_info.is_macos = True os_info.is_linux = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "brew update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "brew install a_package") os_info.is_freebsd = True os_info.is_macos = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "pkg update") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "pkg install -y a_package") spt.install("a_package", force=False) self.assertEquals(runner.command_called, "pkg info a_package") os_info.is_solaris = True os_info.is_freebsd = False os_info.is_windows = False spt = SystemPackageTool(runner=runner, os_info=os_info) spt.update() self.assertEquals(runner.command_called, "pkgutil --catalog") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "pkgutil --install --yes a_package") with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}): # Chocolatey is an optional package manager on Windows if platform.system() == "Windows" and which("choco.exe"): os_info.is_solaris = False os_info.is_windows = True spt = SystemPackageTool(runner=runner, os_info=os_info, tool=ChocolateyTool()) spt.update() self.assertEquals(runner.command_called, "choco outdated") spt.install("a_package", force=True) self.assertEquals(runner.command_called, "choco install --yes a_package") spt.install("a_package", force=False) self.assertEquals( runner.command_called, 'choco search --local-only --exact a_package | findstr /c:"1 packages installed."' )
def system_requirements(self): if self.settings.os == "Windows": pack_name = "winflexbison3" installer = SystemPackageTool(tool=ChocolateyTool()) installer.install(pack_name)