# Path: peru/compat.py
# def makedirs(path):
#     '''os.makedirs() has an exist_ok param, but it still throws errors when the
#     path exists with non-default permissions. This isn't fixed until 3.4.
#     Pathlib won't be getting an exist_ok param until 3.5.'''
#     path = str(path)  # compatibility with pathlib
#     # Use isdir to avoid silently returning if the path exists but isn't a dir.
#     if not os.path.isdir(path):
#         os.makedirs(path)
# 
# Path: peru/runtime.py
# class CommandLineError(PrintableError):
#     pass


import os
import shutil
import textwrap
import shared
from peru.compat import makedirs
from peru.runtime import CommandLineError
                foo: ./
            cp module foo:
                # relative paths should always be interpreted from the dir
                # containing peru.yaml, even if that's not the sync dir.
                path: ../foo
            ''')
        shared.write_files(self.project_dir, {'peru.yaml': self.yaml})
        self.peru_file = os.path.join(self.project_dir, 'peru.yaml')

        self.foo_dir = os.path.join(self.test_root, 'foo')
        shared.write_files(self.foo_dir, {'bar': 'baz'})

        # We'll run tests from this inner subdirectory, so that we're more
        # likely to catch places where we're using the cwd incorrectly.
        self.cwd = os.path.join(self.project_dir, 'cwd', 'in', 'here')
        makedirs(self.cwd)

    def assert_success(self, sync_dir, state_dir, cache_dir, more_excludes=[]):
        shared.assert_contents(
            sync_dir, {'bar': 'baz'},
            excludes=['.peru', 'peru.yaml'] + more_excludes)
        assert os.path.isfile(os.path.join(state_dir, 'lastimports'))
        assert os.path.isdir(os.path.join(cache_dir, 'trees'))

    def test_unmodified_sync(self):
        shared.run_peru_command(['sync'], self.cwd)
        self.assert_success(self.project_dir, self.state_dir, self.cache_dir)

    def test_peru_file_and_sync_dir_must_be_set_together(self):
        for command in [['--sync-dir=junk', 'sync'], ['--file=junk', 'sync']]:

# Path: peru/compat.py
# def makedirs(path):
#     '''os.makedirs() has an exist_ok param, but it still throws errors when the
#     path exists with non-default permissions. This isn't fixed until 3.4.
#     Pathlib won't be getting an exist_ok param until 3.5.'''
#     path = str(path)  # compatibility with pathlib
#     # Use isdir to avoid silently returning if the path exists but isn't a dir.
#     if not os.path.isdir(path):
#         os.makedirs(path)
# 
# Path: peru/runtime.py
# class CommandLineError(PrintableError):
#     pass


# Path: tests/test_paths.py
import os
import shutil
import textwrap
import shared
from peru.compat import makedirs
from peru.runtime import CommandLineError

                foo: ./
            cp module foo:
                # relative paths should always be interpreted from the dir
                # containing peru.yaml, even if that's not the sync dir.
                path: ../foo
            ''')
        shared.write_files(self.project_dir, {'peru.yaml': self.yaml})
        self.peru_file = os.path.join(self.project_dir, 'peru.yaml')

        self.foo_dir = os.path.join(self.test_root, 'foo')
        shared.write_files(self.foo_dir, {'bar': 'baz'})

        # We'll run tests from this inner subdirectory, so that we're more
        # likely to catch places where we're using the cwd incorrectly.
        self.cwd = os.path.join(self.project_dir, 'cwd', 'in', 'here')
        makedirs(self.cwd)

    def assert_success(self, sync_dir, state_dir, cache_dir, more_excludes=[]):
        shared.assert_contents(
            sync_dir, {'bar': 'baz'},
            excludes=['.peru', 'peru.yaml'] + more_excludes)
        assert os.path.isfile(os.path.join(state_dir, 'lastimports'))
        assert os.path.isdir(os.path.join(cache_dir, 'trees'))

    def test_unmodified_sync(self):
        shared.run_peru_command(['sync'], self.cwd)
        self.assert_success(self.project_dir, self.state_dir, self.cache_dir)

    def test_peru_file_and_sync_dir_must_be_set_together(self):
        for command in [['--sync-dir=junk', 'sync'], ['--file=junk', 'sync']]:

            with self.assertRaises(CommandLineError):