Example #1
0
    def system_package_tool_test(self):

        runner = RunnerMock()

        # fake os info to linux debian, default sudo
        os_info = OSInfo()
        os_info.is_linux = True
        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 = "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 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

        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.environ["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 a_package")

        spt.update()
        self.assertEquals(runner.command_called, "apt-get update")

        os_info.is_macos = True
        os_info.is_linux = 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")

        del os.environ["CONAN_SYSREQUIRES_SUDO"]
Example #2
0
    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."')
Example #3
0
    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."'
                )
Example #4
0
    def system_package_tool_test(self):

        runner = RunnerMock()

        # fake os info to linux debian, default sudo
        os_info = OSInfo()
        os_info.is_linux = True
        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 = "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 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

        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.environ["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 a_package")

        spt.update()
        self.assertEquals(runner.command_called, "apt-get update")

        os_info.is_macos = True
        os_info.is_linux = 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")

        del os.environ["CONAN_SYSREQUIRES_SUDO"]