# Path: tests/utils.py
# def in_temporary_directory(f):
#     @functools.wraps(f)
#     def decorated(*args, **kwds):
#         with temporary_directory() as directory:
#             from inspect import getargspec
#             # If it takes directory of kwargs and kwds does already have
#             # directory, inject it
#             if 'directory' not in kwds and 'directory' in getargspec(f)[0]:
#                 kwds['directory'] = directory
#             return f(*args, **kwds)
#     decorated.__name__ = f.__name__
#     return decorated
# 
# Path: tests/utils.py
# def assert_files_exist(prefix, files):
#     """
#     Assert that all files exist in the prefix.
#     """
#     for f in files:
#         p = os.path.join(prefix, f)
#         print("Checking for", p)
#         assert os.path.exists(p), "%s doesn't exist" % p
# 
# Path: tests/utils.py
# def catkin_success(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#         if ret != 0:
#             import traceback
#             traceback.print_exc()
#     finally:
#         os.environ = orig_environ
#     return ret == 0
# 
# Path: tests/utils.py
# class redirected_stdio(object):
# 
#     def __enter__(self):
#         self.original_stdout = sys.stdout
#         self.original_stderr = sys.stderr
#         self.out = StringIO()
#         self.err = StringIO()
#         sys.stdout = self.out
#         sys.stderr = self.err
#         return self.out, self.err
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         sys.stdout = self.original_stdout
#         sys.stderr = self.original_stderr
# 
#         print(self.out.getvalue())
# 
# Path: tests/workspace_assertions.py
# def assert_workspace_initialized(path):
#     assert_files_exist(path, ['.catkin_tools'])
# 
# Path: tests/workspace_assertions.py
# def assert_no_warnings(out_str):
#     """
#     Assert that the stdout returned from a call contains a catkin_tools
#     warning.
#     """
#     out_str_stripped = ' '.join(str(out_str).splitlines())
#     found = re.findall('WARNING:', out_str_stripped)
#     assert len(found) == 0


import os
from ....utils import in_temporary_directory
from ....utils import assert_files_exist
from ....utils import catkin_success
from ....utils import redirected_stdio
from ....workspace_assertions import assert_workspace_initialized
from ....workspace_assertions import assert_no_warnings




TEST_DIR = os.path.dirname(__file__)
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')


@in_temporary_directory
def test_build_eclipse():
    cwd = os.getcwd()
    source_space = os.path.join(cwd, 'src')
    print("Creating source directory: %s" % source_space)
    os.mkdir(source_space)
    with redirected_stdio() as (out, err):
        assert catkin_success(
            ['create', 'pkg', '--rosdistro', 'hydro', '-p', source_space, 'pkg_a']), 'create pkg'

# Path: tests/utils.py
# def in_temporary_directory(f):
#     @functools.wraps(f)
#     def decorated(*args, **kwds):
#         with temporary_directory() as directory:
#             from inspect import getargspec
#             # If it takes directory of kwargs and kwds does already have
#             # directory, inject it
#             if 'directory' not in kwds and 'directory' in getargspec(f)[0]:
#                 kwds['directory'] = directory
#             return f(*args, **kwds)
#     decorated.__name__ = f.__name__
#     return decorated
# 
# Path: tests/utils.py
# def assert_files_exist(prefix, files):
#     """
#     Assert that all files exist in the prefix.
#     """
#     for f in files:
#         p = os.path.join(prefix, f)
#         print("Checking for", p)
#         assert os.path.exists(p), "%s doesn't exist" % p
# 
# Path: tests/utils.py
# def catkin_success(args, env={}):
#     orig_environ = dict(os.environ)
#     try:
#         os.environ.update(env)
#         catkin_main(args)
#     except SystemExit as exc:
#         ret = exc.code
#         if ret != 0:
#             import traceback
#             traceback.print_exc()
#     finally:
#         os.environ = orig_environ
#     return ret == 0
# 
# Path: tests/utils.py
# class redirected_stdio(object):
# 
#     def __enter__(self):
#         self.original_stdout = sys.stdout
#         self.original_stderr = sys.stderr
#         self.out = StringIO()
#         self.err = StringIO()
#         sys.stdout = self.out
#         sys.stderr = self.err
#         return self.out, self.err
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         sys.stdout = self.original_stdout
#         sys.stderr = self.original_stderr
# 
#         print(self.out.getvalue())
# 
# Path: tests/workspace_assertions.py
# def assert_workspace_initialized(path):
#     assert_files_exist(path, ['.catkin_tools'])
# 
# Path: tests/workspace_assertions.py
# def assert_no_warnings(out_str):
#     """
#     Assert that the stdout returned from a call contains a catkin_tools
#     warning.
#     """
#     out_str_stripped = ' '.join(str(out_str).splitlines())
#     found = re.findall('WARNING:', out_str_stripped)
#     assert len(found) == 0


# Path: tests/system/verbs/catkin_build/test_eclipse.py
import os
from ....utils import in_temporary_directory
from ....utils import assert_files_exist
from ....utils import catkin_success
from ....utils import redirected_stdio
from ....workspace_assertions import assert_workspace_initialized
from ....workspace_assertions import assert_no_warnings





TEST_DIR = os.path.dirname(__file__)
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'resources')


@in_temporary_directory
def test_build_eclipse():
    cwd = os.getcwd()
    source_space = os.path.join(cwd, 'src')
    print("Creating source directory: %s" % source_space)
    os.mkdir(source_space)
    with redirected_stdio() as (out, err):
        assert catkin_success(
            ['create', 'pkg', '--rosdistro', 'hydro', '-p', source_space, 'pkg_a']), 'create pkg'

        assert catkin_success(