# Path: hoplite/client/status_updater.py
# class MockStatusUpdater(object):
#     """
#     For use while developing a job
#     """
#     def __init__(self, addr="0.0.0.0:5000", uuid="{0}", api_key=""):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Prints the status to stdout for debugging and sets the
#         member variable status for use in testing status updates
# 
#         :param status: status dictionary
#         """
#         self.status = status
#         print(self.status)
# 
# Path: hoplite/builtin_plugins/constants.py
# class InstallPythonPackageJobConstants(object):
#     LOCAL_PATH = "LOCAL_PATH"
#     PIP_CMD = "PIP_CMD"
# 
# Path: hoplite/builtin_plugins/install_python_package_job.py
# def install_package_with_pip(pip_cmd):
# def uninstall_package_with_pip(package_name):
# def run(config, status):


import unittest2
import os
import tempfile
import shutil
import pip
import pip.basecommand
                import poopy
from hoplite.client.status_updater import MockStatusUpdater
from hoplite.builtin_plugins.constants import InstallPythonPackageJobConstants as KEYS
from hoplite.builtin_plugins import install_python_package_job
from httmock import urlmatch, response, HTTMock
            shutil.rmtree(tempdir)

    def test_install_fails_success_false_stdout_info(self):
        setup_str = "raise ValueError('I FAILED!')"
        tempdir = tempfile.mkdtemp()
        try:
            setup_py = open(os.path.join(tempdir, "setup.py"), 'w')
            setup_py.write(setup_str)
            setup_py.close()

            config = {KEYS.LOCAL_PATH: tempdir}
            status = MockStatusUpdater()


            install_python_package_job.run(config, status)

            self.assertFalse(status.status["succeeded"])

            # Because we monkey patch pip so it doesn't mess up nose xunit logging, the traceback info goes to the
            # console rather than to status.status.stdout
            #self.assertRegexpMatches(status.status["stdout"], "Traceback")

            self.assertIn("Pip returned a non-zero error code", status.status["errors"])
        finally:
            shutil.rmtree(tempdir)

    def test_missing_local_path_returns_errors(self):
        config = {}
        status = MockStatusUpdater()


# Path: hoplite/client/status_updater.py
# class MockStatusUpdater(object):
#     """
#     For use while developing a job
#     """
#     def __init__(self, addr="0.0.0.0:5000", uuid="{0}", api_key=""):
#         self.addr = addr
#         self._uuid = uuid
#         self._daemon_addr = 'http://{0}'.format(self.addr)
#         self._api_key = api_key
#         self.status = {}
# 
#     def update(self, status):
#         """
#         Prints the status to stdout for debugging and sets the
#         member variable status for use in testing status updates
# 
#         :param status: status dictionary
#         """
#         self.status = status
#         print(self.status)
# 
# Path: hoplite/builtin_plugins/constants.py
# class InstallPythonPackageJobConstants(object):
#     LOCAL_PATH = "LOCAL_PATH"
#     PIP_CMD = "PIP_CMD"
# 
# Path: hoplite/builtin_plugins/install_python_package_job.py
# def install_package_with_pip(pip_cmd):
# def uninstall_package_with_pip(package_name):
# def run(config, status):


# Path: tests/builtin_plugins/test_install_python_package_job.py
import unittest2
import os
import tempfile
import shutil
import pip
import pip.basecommand
                import poopy
from hoplite.client.status_updater import MockStatusUpdater
from hoplite.builtin_plugins.constants import InstallPythonPackageJobConstants as KEYS
from hoplite.builtin_plugins import install_python_package_job
from httmock import urlmatch, response, HTTMock

            shutil.rmtree(tempdir)

    def test_install_fails_success_false_stdout_info(self):
        setup_str = "raise ValueError('I FAILED!')"
        tempdir = tempfile.mkdtemp()
        try:
            setup_py = open(os.path.join(tempdir, "setup.py"), 'w')
            setup_py.write(setup_str)
            setup_py.close()

            config = {KEYS.LOCAL_PATH: tempdir}
            status = MockStatusUpdater()


            install_python_package_job.run(config, status)

            self.assertFalse(status.status["succeeded"])

            # Because we monkey patch pip so it doesn't mess up nose xunit logging, the traceback info goes to the
            # console rather than to status.status.stdout
            #self.assertRegexpMatches(status.status["stdout"], "Traceback")

            self.assertIn("Pip returned a non-zero error code", status.status["errors"])
        finally:
            shutil.rmtree(tempdir)

    def test_missing_local_path_returns_errors(self):
        config = {}
        status = MockStatusUpdater()


        install_python_package_job.run(config, status)