Exemplo n.º 1
0
 def test_requires_command_multipe_args(self, mock_check_call):
     mock_check_call.side_effect = [None]
     file_utils.requires_command_success(
         'foo bar baz').__enter__()
     mock_check_call.assert_called_once_with(
         ['foo', 'bar', 'baz'],
         stderr=subprocess.PIPE, stdout=subprocess.PIPE)
Exemplo n.º 2
0
 def test_requires_command_multipe_args(self, mock_check_call):
     mock_check_call.side_effect = [None]
     file_utils.requires_command_success(
         'foo bar baz').__enter__()
     mock_check_call.assert_called_once_with(
         ['foo', 'bar', 'baz'],
         stderr=subprocess.PIPE, stdout=subprocess.PIPE)
Exemplo n.º 3
0
    def test_requires_command_success_error(self, mock_check_call):
        mock_check_call.side_effect = [subprocess.CalledProcessError(1, 'x')]

        with self.assertRaises(RequiredCommandFailure) as raised:
            file_utils.requires_command_success('foo').__enter__()

        self.assertIsInstance(raised.exception, SnapcraftError)
        self.assertEqual("'foo' failed.", str(raised.exception))
Exemplo n.º 4
0
    def test_requires_command_success_not_found(self, mock_check_call):
        mock_check_call.side_effect = [FileNotFoundError()]

        with self.assertRaises(RequiredCommandNotFound) as raised:
            file_utils.requires_command_success('foo').__enter__()

        self.assertIsInstance(raised.exception, SnapcraftError)
        self.assertEqual("'foo' not found.", str(raised.exception))
Exemplo n.º 5
0
    def test_requires_command_success_broken(self):
        raised = self.assertRaises(
            TypeError,
            file_utils.requires_command_success(1).__enter__)

        self.assertThat(
            str(raised), Equals('command must be a string.'))
Exemplo n.º 6
0
    def test_requires_command_success_broken(self):
        raised = self.assertRaises(
            TypeError,
            file_utils.requires_command_success(1).__enter__)

        self.assertThat(
            str(raised), Equals('command must be a string.'))
Exemplo n.º 7
0
def requires_travis_preconditions():
    """Verify all Travis CI integration preconditions."""
    required = (
        requires_command_success(
            "travis settings",
            not_found_fmt=(
                "Travis CLI (`{cmd_list[0]}`) is not available.\n"
                "Please install it before trying this command again:\n\n"
                "    $ sudo apt install ruby-dev ruby-ffi libffi-dev\n"
                "    $ sudo gem install travis\n"
            ),
            failure_fmt=(
                "Travis CLI (`{command}`) is not functional or you are not "
                "allowed to access this repository settings.\n"
                "Make sure it works correctly in your system before trying "
                "this command again."
            ),
        ),
        requires_command_success(
            "git status",
            not_found_fmt=(
                "Git (`{cmd_list[0]}`) is not available, this tool cannot "
                "verify its prerequisites.\n"
                "Please install it before trying this command again:\n\n"
                "    $ sudo apt install git\n"
            ),
            failure_fmt=(
                "The current directory is not a Git repository.\n"
                "Please switch to the desired project repository where "
                "Travis should be enabled."
            ),
        ),
        requires_path_exists(
            TRAVIS_CONFIG_FILENAME,
            error_fmt=(
                "Travis project is not initialized for the current "
                "directory.\n"
                "Please initialize Travis project (e.g. `travis init`) with "
                "appropriate parameters."
            ),
        ),
    )
    with ExitStack() as cm:
        [cm.enter_context(c) for c in required]
        yield
Exemplo n.º 8
0
    def test_requires_command_success_not_found(self, mock_check_call):
        mock_check_call.side_effect = [FileNotFoundError()]

        raised = self.assertRaises(
            RequiredCommandNotFound,
            file_utils.requires_command_success('foo').__enter__)

        self.assertIsInstance(raised, SnapcraftError)
        self.assertThat(str(raised), Equals("'foo' not found."))
Exemplo n.º 9
0
    def test_requires_command_success_error(self, mock_check_call):
        mock_check_call.side_effect = [subprocess.CalledProcessError(1, 'x')]

        raised = self.assertRaises(
            RequiredCommandFailure,
            file_utils.requires_command_success('foo').__enter__)

        self.assertIsInstance(raised, SnapcraftError)
        self.assertThat(str(raised), Equals("'foo' failed."))
Exemplo n.º 10
0
    def test_requires_command_success_error(self, mock_check_call):
        mock_check_call.side_effect = [subprocess.CalledProcessError(1, "x")]

        raised = self.assertRaises(
            RequiredCommandFailure, file_utils.requires_command_success("foo").__enter__
        )

        self.assertIsInstance(raised, SnapcraftError)
        self.assertThat(str(raised), Equals("'foo' failed."))
Exemplo n.º 11
0
    def test_requires_command_success_not_found(self, mock_check_call):
        mock_check_call.side_effect = [FileNotFoundError()]

        raised = self.assertRaises(
            RequiredCommandNotFound,
            file_utils.requires_command_success('foo').__enter__)

        self.assertIsInstance(raised, SnapcraftError)
        self.assertEqual("'foo' not found.", str(raised))
Exemplo n.º 12
0
    def test_requires_command_success_custom_error(self, mock_check_call):
        mock_check_call.side_effect = [
            FileNotFoundError(),
            subprocess.CalledProcessError(1, 'x')
        ]

        with self.assertRaises(RequiredCommandNotFound) as raised:
            file_utils.requires_command_success(
                'foo',
                not_found_fmt='uhm? {cmd_list!r} -> {command}').__enter__()

        self.assertEqual("uhm? ['foo'] -> foo", str(raised.exception))

        with self.assertRaises(RequiredCommandFailure) as raised:
            file_utils.requires_command_success(
                'foo',
                failure_fmt='failed {cmd_list!r} -> {command}').__enter__()

        self.assertEqual("failed ['foo'] -> foo", str(raised.exception))
Exemplo n.º 13
0
    def test_requires_command_success_custom_error(self, mock_check_call):
        mock_check_call.side_effect = [
            FileNotFoundError(),
            subprocess.CalledProcessError(1, 'x')
        ]

        raised = self.assertRaises(
            RequiredCommandNotFound,
            file_utils.requires_command_success(
                'foo', not_found_fmt='uhm? {cmd_list!r} -> {command}'
            ).__enter__)

        self.assertEqual("uhm? ['foo'] -> foo", str(raised))

        raised = self.assertRaises(
            RequiredCommandFailure,
            file_utils.requires_command_success(
                'foo', failure_fmt='failed {cmd_list!r} -> {command}'
            ).__enter__)

        self.assertEqual("failed ['foo'] -> foo", str(raised))
Exemplo n.º 14
0
    def test_requires_command_success_custom_error(self, mock_check_call):
        mock_check_call.side_effect = [
            FileNotFoundError(),
            subprocess.CalledProcessError(1, 'x')
        ]

        raised = self.assertRaises(
            RequiredCommandNotFound,
            file_utils.requires_command_success(
                'foo',
                not_found_fmt='uhm? {cmd_list!r} -> {command}').__enter__)

        self.assertThat(str(raised), Equals("uhm? ['foo'] -> foo"))

        raised = self.assertRaises(
            RequiredCommandFailure,
            file_utils.requires_command_success(
                'foo',
                failure_fmt='failed {cmd_list!r} -> {command}').__enter__)

        self.assertThat(str(raised), Equals("failed ['foo'] -> foo"))
Exemplo n.º 15
0
    def test_requires_command_success_custom_error(self, mock_check_call):
        mock_check_call.side_effect = [
            FileNotFoundError(),
            subprocess.CalledProcessError(1, "x"),
        ]

        raised = self.assertRaises(
            RequiredCommandNotFound,
            file_utils.requires_command_success(
                "foo", not_found_fmt="uhm? {cmd_list!r} -> {command}"
            ).__enter__,
        )

        self.assertThat(str(raised), Equals("uhm? ['foo'] -> foo"))

        raised = self.assertRaises(
            RequiredCommandFailure,
            file_utils.requires_command_success(
                "foo", failure_fmt="failed {cmd_list!r} -> {command}"
            ).__enter__,
        )

        self.assertThat(str(raised), Equals("failed ['foo'] -> foo"))
Exemplo n.º 16
0
 def test_requires_command_works(self, mock_check_call):
     mock_check_call.side_effect = [None]
     file_utils.requires_command_success("foo").__enter__()
     mock_check_call.assert_called_once_with(["foo"],
                                             stderr=subprocess.PIPE,
                                             stdout=subprocess.PIPE)
Exemplo n.º 17
0
 def test_requires_command_works(self, mock_check_call):
     mock_check_call.side_effect = [None]
     file_utils.requires_command_success("foo").__enter__()
     mock_check_call.assert_called_once_with(
         ["foo"], stderr=subprocess.PIPE, stdout=subprocess.PIPE
     )
Exemplo n.º 18
0
    def test_requires_command_success_broken(self):
        with self.assertRaises(TypeError) as raised:
            file_utils.requires_command_success(1).__enter__()

        self.assertEqual('command must be a string.', str(raised.exception))