Пример #1
0
 def test_give_up_after_second_error(self):
     """ Checks that the installer gives up after 2 tries """
     with mock.patch(
             "lib.installer.dependency_installer.AptBasedInstaller.get_missing_packages",
             lambda x, y: ["1", "2", "3"]
     ), mock.patch(
             'lib.installer.dependency_installer.AptBasedInstaller.install',
             lambda x, y: raise_(
                 subprocess.CalledProcessError(2, "just a test"))
     ), mock.patch(
             'lib.installer.dependency_installer.AptBasedInstaller.update_sources',
             lambda x: 0):
         with self.assertRaises(subprocess.CalledProcessError):
             DependenciesInstaller.factory([]).run()
Пример #2
0
 def test_retries_with_update_on_error(self):
     """ Checks that the installer will try a second time on error """
     with mock.patch(
             "lib.installer.dependency_installer.AptBasedInstaller.get_missing_packages",
             lambda x, y: [1, 2, 3]
     ), mock.patch(
             'lib.installer.dependency_installer.AptBasedInstaller.install',
             lambda x, y: raise_(
                 subprocess.CalledProcessError(2, "just a test"))
     ), mock.patch(
             'lib.installer.dependency_installer.AptBasedInstaller.update_sources',
             lambda x: raise_(subprocess.SubprocessError)):
         with self.assertRaises(subprocess.SubprocessError):
             DependenciesInstaller.factory([]).run()
Пример #3
0
 def test_give_up_after_second_error(self):
     """ Checks that the installer gives up after 2 tries """
     with mock.patch(
         "lib.installer.dependency_installer.AptBasedInstaller.get_missing_packages",
         lambda x, y: ["1", "2", "3"]
     ), mock.patch(
         'lib.installer.dependency_installer.AptBasedInstaller.install',
         lambda x, y: raise_(subprocess.CalledProcessError(2, "just a test"))
     ), mock.patch(
         'lib.installer.dependency_installer.AptBasedInstaller.update_sources',
         lambda x: 0
     ):
         with self.assertRaises(subprocess.CalledProcessError):
             DependenciesInstaller.factory([]).run()
Пример #4
0
 def test_retries_with_update_on_error(self):
     """ Checks that the installer will try a second time on error """
     with mock.patch(
         "lib.installer.dependency_installer.AptBasedInstaller.get_missing_packages",
         lambda x, y: [1, 2, 3]
     ), mock.patch(
         'lib.installer.dependency_installer.AptBasedInstaller.install',
         lambda x, y: raise_(subprocess.CalledProcessError(2, "just a test"))
     ), mock.patch(
         'lib.installer.dependency_installer.AptBasedInstaller.update_sources',
         lambda x: raise_(subprocess.SubprocessError)
     ):
         with self.assertRaises(subprocess.SubprocessError):
             DependenciesInstaller.factory([]).run()
Пример #5
0
 def factory(conf: SectionProxy, force_installation: bool):
     """
     Parses the configuration and returns the correct Installer
     :param conf: the configuration of the program to install
     :param force_installation: if reinstalling is enabled or not
     :return: an Installer instance
     """
     if "git_repo" in conf:
         return GitInstaller(conf, force_installation)
     elif "svn_repo" in conf:
         return SVNInstaller(conf, force_installation)
     elif conf.get("system_package", False):
         return DependenciesInstaller.factory([conf.get("name")])
     elif conf.getboolean("license", False):
         return LicensedSourceInstaller(conf, force_installation)
     elif conf.get("url", None):
         return DownloadableSourceInstaller(conf, force_installation)
     elif conf.get("source", None):
         return SourceInstaller(conf, force_installation)
     else:
         raise RuntimeError("There was an error while configuring the Installer to use")
Пример #6
0
 def factory(conf: SectionProxy, force_installation: bool):
     """
     Parses the configuration and returns the correct Installer
     :param conf: the configuration of the program to install
     :param force_installation: if reinstalling is enabled or not
     :return: an Installer instance
     """
     if "git_repo" in conf:
         return GitInstaller(conf, force_installation)
     elif "svn_repo" in conf:
         return SVNInstaller(conf, force_installation)
     elif conf.get("system_package", False):
         return DependenciesInstaller.factory([conf.get("name")])
     elif conf.getboolean("license", False):
         return LicensedSourceInstaller(conf, force_installation)
     elif conf.get("url", None):
         return DownloadableSourceInstaller(conf, force_installation)
     elif conf.get("source", None):
         return SourceInstaller(conf, force_installation)
     else:
         raise RuntimeError(
             "There was an error while configuring the Installer to use")
Пример #7
0
 def test_unsupported_distro_raises_exception(self):
     """ Checks that using an unsupported distribution will raise an exception and not return """
     with mock.patch('platform.dist', lambda: ("Goat", "13.37", "tsy")):
         with self.assertRaises(
                 lib.exceptions.DistributionNotSupportedException):
             DependenciesInstaller.factory([])
Пример #8
0
 def test_unsupported_distro_raises_exception(self):
     """ Checks that using an unsupported distribution will raise an exception and not return """
     with mock.patch('platform.dist', lambda: ("Goat", "13.37", "tsy")):
         with self.assertRaises(lib.exceptions.DistributionNotSupportedException):
             DependenciesInstaller.factory([])