Example #1
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()
 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()
Example #3
0
 def test_installer_selects_wllvm(self):
     with mock.patch("lib.configuration.dependencies.Installer.run",
                     lambda x: raise_(Exception(x.conf.get("name")))):
         try:
             lib.configuration.dependencies.install_wllvm(True)
         except Exception as exc:  # pylint: disable=broad-except
             self.assertEqual(str(exc), "wllvm")
Example #4
0
 def test_installer_selects_wllvm(self):
     with mock.patch(
         "lib.configuration.dependencies.Installer.run",
         lambda x: raise_(Exception(x.conf.get("name")))
     ):
         try:
             lib.configuration.dependencies.install_wllvm(True)
         except Exception as exc:  # pylint: disable=broad-except
             self.assertEqual(str(exc), "wllvm")
Example #5
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()
 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()
Example #7
0
"""
Tests for the coredump handling module
"""


from unittest.mock import patch, mock_open

import lib.configuration.coredump
from tests.lib import raise_
from tests.unit_tests import UnitTest


__author__ = "Benjamin Schubert, [email protected]"


@patch("lib.configuration.coredump.launch_and_log_as_root", lambda cmd: raise_(Exception(" ".join(cmd))))
class TestCoredumps(UnitTest):
    call_regexp = r"^echo.*?sysctl.conf$"

    def test_updates_sysctl_if_coredump_not_there(self):
        with patch('lib.configuration.coredump.open', mock_open(), create=True) as mocked:
            mocked.return_value.__iter__ = lambda obj: obj  # this is mandatory, https://bugs.python.org/issue21258
            mocked.return_value.__next__ = lambda obj: obj.readline()
            self.assertRaisesRegex(Exception, self.call_regexp, lib.configuration.coredump.change_coredump_pattern)

    def test_updates_sysctl_if_coredump_commented(self):
        data = "# /tmp/coredumps/%E.core"
        with patch('lib.configuration.coredump.open', mock_open(read_data=data), create=True) as mocked:
            mocked.return_value.__iter__ = lambda obj: obj
            mocked.return_value.__next__ = lambda obj: obj.readline()
            self.assertRaisesRegex(Exception, self.call_regexp, lib.configuration.coredump.change_coredump_pattern)
Example #8
0
 def test_module_handling(self):
     get_global_conf().set("install", "module_handling", "true")
     with \
             mock.patch("lib.configuration.dependencies.install_python_modules", lambda: raise_(Exception("NO"))),\
             mock.patch("lib.configuration.dependencies.install_wllvm", lambda _: 0),\
             mock.patch("lib.configuration.dependencies.get_programs_dependencies", lambda: []):
         try:
             lib.configuration.dependencies.install(True)
         except Exception as exc:  # pylint: disable=broad-except
             self.assertEqual(str(exc), "NO")
Example #9
0
 def test_no_module_handling():
     get_global_conf().set("install", "module_handling", "false")
     with \
             mock.patch("lib.configuration.dependencies.install_python_modules", lambda: raise_(Exception("NO"))),\
             mock.patch("lib.configuration.dependencies.install_wllvm", lambda _: 0),\
             mock.patch("lib.configuration.dependencies.get_programs_dependencies", lambda: []):
         lib.configuration.dependencies.install(True)
Example #10
0
 def test_module_handling(self):
     get_global_conf().set("install", "module_handling", "true")
     with \
             mock.patch("lib.configuration.dependencies.install_python_modules", lambda: raise_(Exception("NO"))),\
             mock.patch("lib.configuration.dependencies.install_wllvm", lambda _: 0),\
             mock.patch("lib.configuration.dependencies.get_programs_dependencies", lambda: []):
         try:
             lib.configuration.dependencies.install(True)
         except Exception as exc:  # pylint: disable=broad-except
             self.assertEqual(str(exc), "NO")
Example #11
0
 def test_no_module_handling():
     get_global_conf().set("install", "module_handling", "false")
     with \
             mock.patch("lib.configuration.dependencies.install_python_modules", lambda: raise_(Exception("NO"))),\
             mock.patch("lib.configuration.dependencies.install_wllvm", lambda _: 0),\
             mock.patch("lib.configuration.dependencies.get_programs_dependencies", lambda: []):
         lib.configuration.dependencies.install(True)