Esempio n. 1
0
 def test_return_false(self):
     """Assert false is returned if Called process Error Exception is thrown."""
     with mock.patch.object(cli, 'Client') as client:
         client.side_effect = exceptions.CalledProcessError(
             ('arg', 'arg'), 1, 'stdout', 'stderr')
         response = utils.fips_is_supported(mock.Mock())
     self.assertFalse(response)
Esempio n. 2
0
    def check_returncode(self):
        """Raise an exception if ``returncode`` is non-zero.

        Raise :class:`pulp_smash.exceptions.CalledProcessError` if
        ``returncode`` is non-zero.

        Why not raise ``subprocess.CalledProcessError``? Because stdout and
        stderr are not included when str() is called on a CalledProcessError
        object. A typical message is::

            "Command '('ls', 'foo')' returned non-zero exit status 2"

        This information is valuable. One could still make
        ``subprocess.CalledProcessError`` work by overloading ``args``:

        >>> if isinstance(args, (str, bytes)):
        ...     custom_args = (args, stdout, stderr)
        ... else:
        ...     custom_args = tuple(args) + (stdout, stderr)
        >>> subprocess.CalledProcessError(args, returncode)

        But this seems like a hack.

        In addition, it's generally good for an application to raise expected
        exceptions from its own namespace, so as to better abstract away
        dependencies.
        """
        if self.returncode != 0:
            raise exceptions.CalledProcessError(self.args, self.returncode,
                                                self.stdout, self.stderr)
Esempio n. 3
0
 def test_return_false(self):
     """Assert false if Called process Error Exception is thrown."""
     with mock.patch.object(cli, "Client") as client:
         client.side_effect = exceptions.CalledProcessError(
             ("arg", "arg"), 1, "stdout", "stderr")
         response = utils.fips_is_supported(mock.Mock())
     self.assertFalse(response)