# Path: tests/system/workspace_factory.py
# class workspace_factory(temporary_directory):
# 
#     def __init__(self, source_space='src', prefix=''):
#         super(workspace_factory, self).__init__(prefix=prefix)
#         self.source_space = source_space
# 
#     def __enter__(self):
#         self.temporary_directory = super(workspace_factory, self).__enter__()
#         self.workspace_factory = WorkspaceFactory(self.temporary_directory, self.source_space)
#         return self.workspace_factory
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         super(workspace_factory, self).__exit__(exc_type, exc_value, traceback)
# 
# 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_cmd_success(cmd, **kwargs):
#     """
#     Asserts that running a command returns zero.
# 
#     returns: stdout
#     """
#     print(">>>", cmd, kwargs)
#     (r, out, err) = run(cmd, **kwargs)
#     print("<<<", str(out))
#     assert r == 0, "cmd failed with result %s:\n %s " % (r, str(cmd))
#     return out
# 
# Path: tests/workspace_assertions.py
# def assert_workspace_initialized(path):
#     assert_files_exist(path, ['.catkin_tools'])
# 
# Path: tests/workspace_assertions.py
# def assert_warning_message(out_str, pattern=''):
#     """
#     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
# 
#     if pattern:
#         found = re.findall(pattern, out_str_stripped)
#         assert len(found) > 0
# 
# 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/workspace_assertions.py
# def assert_in_config(workspace, profile, key, value):
#     with open(os.path.join(workspace, '.catkin_tools', 'profiles', profile, 'config.yaml')) as f:
#         config = yaml.safe_load(f)
# 
#     assert config.get(key, None) == value


import os
from ...workspace_factory import workspace_factory
from ....utils import in_temporary_directory
from ....utils import assert_cmd_success
from ....workspace_assertions import assert_workspace_initialized
from ....workspace_assertions import assert_warning_message
from ....workspace_assertions import assert_no_warnings
from ....workspace_assertions import assert_in_config




@in_temporary_directory
def test_config_no_ws():
    out = assert_cmd_success(['catkin', 'config'])
    assert_warning_message(out, 'Workspace .+ is not yet initialized')


@in_temporary_directory
def test_init_local_empty_src():
    cwd = os.getcwd()
    os.mkdir(os.path.join(cwd, 'src'))
    out = assert_cmd_success(['catkin', 'config', '--init'])
    assert_no_warnings(out)
    assert_workspace_initialized('.')


@in_temporary_directory
def test_config_non_bare():
    out = assert_cmd_success(['catkin', 'config', '--install'])
    assert_workspace_initialized('.')

# Path: tests/system/workspace_factory.py
# class workspace_factory(temporary_directory):
# 
#     def __init__(self, source_space='src', prefix=''):
#         super(workspace_factory, self).__init__(prefix=prefix)
#         self.source_space = source_space
# 
#     def __enter__(self):
#         self.temporary_directory = super(workspace_factory, self).__enter__()
#         self.workspace_factory = WorkspaceFactory(self.temporary_directory, self.source_space)
#         return self.workspace_factory
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         super(workspace_factory, self).__exit__(exc_type, exc_value, traceback)
# 
# 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_cmd_success(cmd, **kwargs):
#     """
#     Asserts that running a command returns zero.
# 
#     returns: stdout
#     """
#     print(">>>", cmd, kwargs)
#     (r, out, err) = run(cmd, **kwargs)
#     print("<<<", str(out))
#     assert r == 0, "cmd failed with result %s:\n %s " % (r, str(cmd))
#     return out
# 
# Path: tests/workspace_assertions.py
# def assert_workspace_initialized(path):
#     assert_files_exist(path, ['.catkin_tools'])
# 
# Path: tests/workspace_assertions.py
# def assert_warning_message(out_str, pattern=''):
#     """
#     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
# 
#     if pattern:
#         found = re.findall(pattern, out_str_stripped)
#         assert len(found) > 0
# 
# 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/workspace_assertions.py
# def assert_in_config(workspace, profile, key, value):
#     with open(os.path.join(workspace, '.catkin_tools', 'profiles', profile, 'config.yaml')) as f:
#         config = yaml.safe_load(f)
# 
#     assert config.get(key, None) == value


# Path: tests/system/verbs/catkin_config/test_config.py
import os
from ...workspace_factory import workspace_factory
from ....utils import in_temporary_directory
from ....utils import assert_cmd_success
from ....workspace_assertions import assert_workspace_initialized
from ....workspace_assertions import assert_warning_message
from ....workspace_assertions import assert_no_warnings
from ....workspace_assertions import assert_in_config





@in_temporary_directory
def test_config_no_ws():
    out = assert_cmd_success(['catkin', 'config'])
    assert_warning_message(out, 'Workspace .+ is not yet initialized')


@in_temporary_directory
def test_init_local_empty_src():
    cwd = os.getcwd()
    os.mkdir(os.path.join(cwd, 'src'))
    out = assert_cmd_success(['catkin', 'config', '--init'])
    assert_no_warnings(out)
    assert_workspace_initialized('.')


@in_temporary_directory
def test_config_non_bare():
    out = assert_cmd_success(['catkin', 'config', '--install'])
    assert_workspace_initialized('.')

    assert_warning_message(out, 'Source space .+ does not yet exist')