# Path: tests/helpers.py
# class YodaTestHelper(unittest.TestCase):
#     """Yoda test helper class.
#     This class provides custom assertions for yoda's tests suite.
#     """
#     sandbox = None
# 
#     def setUp(self):
#         """Setup sandbox."""
#         self.sandbox = Sandbox()
# 
#     def tearDown(self):
#         """Destroy sandbox."""
#         self.sandbox.destroy()
# 
#     def assert_config_file_contains(self, config_file, expected):
#         """Custom assert to check content of config_file."""
#         file = open(config_file)
#         config = yaml.safe_load(file.read())
#         file.close()
#         self.assertEqual(config, expected)
# 
# Path: yoda/adapter/abstract.py
# class Abstract:
#     """SCM Adapter interface."""
#     __metaclass__ = ABCMeta
# 
#     path = None
#     executable = None
# 
#     def __init__(self, path):
#         self.path = path
# 
#     def execute(self, command, path=None):
#         """Execute command with os.popen and return output."""
#         logger = logging.getLogger(__name__)
# 
#         self.check_executable()
#         logger.debug("Executing command `%s` (cwd: %s)" % (command, path))
#         process = subprocess.Popen(
#             command,
#             shell=True,
#             cwd=path,
#             stdout=subprocess.PIPE,
#             stderr=subprocess.PIPE
#         )
#         stdout, stderr = process.communicate()
#         exit_code = process.wait()
# 
#         if stdout:
#             logger.info(stdout.decode("utf-8"))
# 
#         if stderr:
#             if exit_code != 0:
#                 logger.error(stderr.decode("utf-8"))
#             else:
#                 logger.info(stderr.decode("utf-8"))
# 
#         return process
# 
#     def exec_on_path(self, command):
#         """Execute command in repository path."""
#         self.execute("%s" % command, self.path)
# 
#     def check_executable(self):
#         """Check adapter executable exists."""
#         if not find_executable(self.executable):
#             raise ExecutableNotFoundException(
#                 "Executable %s not found" % self.executable
#             )
# 
#     @abstractmethod
#     def status(self):
#         pass
# 
#     @abstractmethod
#     def update(self):
#         pass
# 
#     @abstractmethod
#     def show(self):
#         pass
# 
#     @abstractmethod
#     def clone(self):
#         pass
# 
# Path: yoda/adapter/abstract.py
# class ExecutableNotFoundException(OSError):
#     pass


import mock
import os
import subprocess
from mock import patch
from testfixtures import LogCapture
from tests.helpers import YodaTestHelper
from yoda.adapter import Abstract
from yoda.adapter import ExecutableNotFoundException

    @patch("yoda.adapter.abstract.subprocess.Popen",
           return_value=mock.create_autospec(
               subprocess.Popen, return_value=mock.Mock()))
    def test_execute_failure(self, mock_proc):
        """Test execute with error."""
        mock_com = mock_proc.return_value.communicate
        mock_com.return_value = [b"Yoda", b"Rosk"]
        mock_wait = mock_proc.return_value.wait
        mock_wait.return_value = 1
        with patch("yoda.adapter.abstract.find_executable",
                   return_value=True):
            with LogCapture() as lcap:
                self.assertEqual(
                    self.adapter.execute("git log"),
                    mock_proc.return_value)

        lcap.check(("yoda.adapter.abstract", "DEBUG",
                    "Executing command `git log` (cwd: None)"),
                   ("yoda.adapter.abstract", "INFO",
                    "Yoda"),
                   ("yoda.adapter.abstract", "ERROR",
                    "Rosk"))

    def test_check_executable_with_wrong_executable(self):
        """Test check executable with wrong command."""
        self.adapter.executable = "wrong_executable"
        with patch("yoda.adapter.abstract.find_executable",
                   return_value=False):
            self.assertRaises(

# Path: tests/helpers.py
# class YodaTestHelper(unittest.TestCase):
#     """Yoda test helper class.
#     This class provides custom assertions for yoda's tests suite.
#     """
#     sandbox = None
# 
#     def setUp(self):
#         """Setup sandbox."""
#         self.sandbox = Sandbox()
# 
#     def tearDown(self):
#         """Destroy sandbox."""
#         self.sandbox.destroy()
# 
#     def assert_config_file_contains(self, config_file, expected):
#         """Custom assert to check content of config_file."""
#         file = open(config_file)
#         config = yaml.safe_load(file.read())
#         file.close()
#         self.assertEqual(config, expected)
# 
# Path: yoda/adapter/abstract.py
# class Abstract:
#     """SCM Adapter interface."""
#     __metaclass__ = ABCMeta
# 
#     path = None
#     executable = None
# 
#     def __init__(self, path):
#         self.path = path
# 
#     def execute(self, command, path=None):
#         """Execute command with os.popen and return output."""
#         logger = logging.getLogger(__name__)
# 
#         self.check_executable()
#         logger.debug("Executing command `%s` (cwd: %s)" % (command, path))
#         process = subprocess.Popen(
#             command,
#             shell=True,
#             cwd=path,
#             stdout=subprocess.PIPE,
#             stderr=subprocess.PIPE
#         )
#         stdout, stderr = process.communicate()
#         exit_code = process.wait()
# 
#         if stdout:
#             logger.info(stdout.decode("utf-8"))
# 
#         if stderr:
#             if exit_code != 0:
#                 logger.error(stderr.decode("utf-8"))
#             else:
#                 logger.info(stderr.decode("utf-8"))
# 
#         return process
# 
#     def exec_on_path(self, command):
#         """Execute command in repository path."""
#         self.execute("%s" % command, self.path)
# 
#     def check_executable(self):
#         """Check adapter executable exists."""
#         if not find_executable(self.executable):
#             raise ExecutableNotFoundException(
#                 "Executable %s not found" % self.executable
#             )
# 
#     @abstractmethod
#     def status(self):
#         pass
# 
#     @abstractmethod
#     def update(self):
#         pass
# 
#     @abstractmethod
#     def show(self):
#         pass
# 
#     @abstractmethod
#     def clone(self):
#         pass
# 
# Path: yoda/adapter/abstract.py
# class ExecutableNotFoundException(OSError):
#     pass


# Path: tests/adapter/abstract_test.py
import mock
import os
import subprocess
from mock import patch
from testfixtures import LogCapture
from tests.helpers import YodaTestHelper
from yoda.adapter import Abstract
from yoda.adapter import ExecutableNotFoundException


    @patch("yoda.adapter.abstract.subprocess.Popen",
           return_value=mock.create_autospec(
               subprocess.Popen, return_value=mock.Mock()))
    def test_execute_failure(self, mock_proc):
        """Test execute with error."""
        mock_com = mock_proc.return_value.communicate
        mock_com.return_value = [b"Yoda", b"Rosk"]
        mock_wait = mock_proc.return_value.wait
        mock_wait.return_value = 1
        with patch("yoda.adapter.abstract.find_executable",
                   return_value=True):
            with LogCapture() as lcap:
                self.assertEqual(
                    self.adapter.execute("git log"),
                    mock_proc.return_value)

        lcap.check(("yoda.adapter.abstract", "DEBUG",
                    "Executing command `git log` (cwd: None)"),
                   ("yoda.adapter.abstract", "INFO",
                    "Yoda"),
                   ("yoda.adapter.abstract", "ERROR",
                    "Rosk"))

    def test_check_executable_with_wrong_executable(self):
        """Test check executable with wrong command."""
        self.adapter.executable = "wrong_executable"
        with patch("yoda.adapter.abstract.find_executable",
                   return_value=False):
            self.assertRaises(

                ExecutableNotFoundException,