def test_exec_cmd_iterator(self): cmd = "some command" process_mock = self.make_process_mock() with mock.patch.object(subprocess, "Popen", return_value=process_mock) as popen_mock: for line in utils.exec_cmd_iterator(cmd): self.assertTrue(line.startswith("Stdout line ")) popen_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
def test_exec_cmd_iterator_raises_error(self): cmd = 'some command' return_code = 1 process_mock = self.make_process_mock(return_code=return_code) with mock.patch.object(subprocess, 'Popen', return_value=process_mock): with self.assertRaisesRegexp( error.ExecutedErrorNonZeroExitCode, 'Shell command executed with "{0}" ' 'exit code: {1} '.format(return_code, cmd)): for line in utils.exec_cmd_iterator(cmd): self.assertTrue(line.startswith('Stdout line '))
def version_from_file(cls, file_path): """Retrieves plugin version from RPM. :param str file_path: path to rpm file :returns: version of the plugin """ for line in utils.exec_cmd_iterator( "rpm -qp --queryformat '%{{version}}' {0}".format(file_path)): version = line break return version
def test_exec_cmd_iterator(self): cmd = 'some command' process_mock = self.make_process_mock() with mock.patch.object(subprocess, 'Popen', return_value=process_mock) as popen_mock: for line in utils.exec_cmd_iterator(cmd): self.assertTrue(line.startswith('Stdout line ')) popen_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
def name_from_file(cls, file_path): """Retrieves plugin name from RPM. RPM name contains the version of the plugin, which should be removed. :param str file_path: path to rpm file :returns: name of the plugin """ for line in utils.exec_cmd_iterator( "rpm -qp --queryformat '%{{name}}' {0}".format(file_path)): name = line break return cls._remove_major_plugin_version(name)