# Path: servi/config.py
# def find_master_dir(start_dir, fail_ok=False):
#     """
#     finds Servifile.yml at or above start_dir
#     returns MasterNotFound or None (if fail_ok)
#     """
#     master_dir = find_ancestor_servifile(start_dir)
#     if not master_dir:
#         if not fail_ok:
#             raise MasterNotFound()
#         else:
#             return None
#     else:
#         return os.path.abspath(master_dir)
# 
# Path: servi/exceptions.py
# class MasterNotFound(Exception):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             'Master directory not found at or above current directory.\n'
#             'Looking for: <master>/ServiFile.yml\n'
#             'Above cwd: {0}\n'
#             'Run "servi init <dirname>"\n'
#             '\n**Servi Aborting**'.format(os.getcwd()))


from servi.config import find_master_dir
from tests.fixtures import *
from servi.exceptions import MasterNotFound


def test_find_master_dir(fake_master):
    """
    parent
        /master
            /servi
                \servi_templates
    """

    master, nonmaster = fake_master

    assert find_master_dir('master/servi/servi_templates') == master
    assert find_master_dir('master/servi') == master
    assert find_master_dir('master') == master

    with pytest.raises(MasterNotFound):
        find_master_dir(os.path.join(master, '..'))


# Path: servi/config.py
# def find_master_dir(start_dir, fail_ok=False):
#     """
#     finds Servifile.yml at or above start_dir
#     returns MasterNotFound or None (if fail_ok)
#     """
#     master_dir = find_ancestor_servifile(start_dir)
#     if not master_dir:
#         if not fail_ok:
#             raise MasterNotFound()
#         else:
#             return None
#     else:
#         return os.path.abspath(master_dir)
# 
# Path: servi/exceptions.py
# class MasterNotFound(Exception):
#     def __init__(self):
#         pass
# 
#     def __str__(self):
#         return (
#             '\n***** ERROR *****\n'
#             'Master directory not found at or above current directory.\n'
#             'Looking for: <master>/ServiFile.yml\n'
#             'Above cwd: {0}\n'
#             'Run "servi init <dirname>"\n'
#             '\n**Servi Aborting**'.format(os.getcwd()))


# Path: tests/test_utils.py
from servi.config import find_master_dir
from tests.fixtures import *
from servi.exceptions import MasterNotFound



def test_find_master_dir(fake_master):
    """
    parent
        /master
            /servi
                \servi_templates
    """

    master, nonmaster = fake_master

    assert find_master_dir('master/servi/servi_templates') == master
    assert find_master_dir('master/servi') == master
    assert find_master_dir('master') == master

    with pytest.raises(MasterNotFound):
        find_master_dir(os.path.join(master, '..'))


    with pytest.raises(MasterNotFound):