# Path: ice/filesystem.py
# class RealFilesystem(object):
# class FakeFilesystem(object):
#   def create_directories(self, path):
#   def path_exists(self, path):
#   def is_directory(self, path):
#   def is_file(self, path):
#   def is_writable(self, path):
#   def _paths_in_directory(self, directory, incl_subdirs=False):
#   def files_in_directory(self, directory, include_subdirectories=False):
#   def subdirectories_of_directory(self, directory, recursive=False):
#   def __init__(self, root):
#   def adjusted_path(self, path):
#   def create_directories(self, path):
#   def path_exists(self, path):
#   def is_directory(self, path):
#   def is_file(self, path):
#   def is_writable(self, path):
#   def files_in_directory(self, directory, include_subdirectories=False):
#   def subdirectories_of_directory(self, directory, recursive=False):


import os
import shutil
import sys
import tempfile
import unittest
from nose_parameterized import parameterized
from ice import filesystem
    os.mkdir(dir1)
    file2 = os.path.join(dir1, "file2")
    self.touch_file(file2)

    result = self.filesystem.files_in_directory(self.tempdir, include_subdirectories=True)

    self.assertEquals(set([file1, file2]), set(result))

  def test_subdirectories_of_directory_should_return_subdirectories_of_subdirectories_when_recursive_is_true(self):
    dir1 = os.path.join(self.tempdir, "dir1")
    dir11 = os.path.join(dir1, "dir11")
    dir2 = os.path.join(self.tempdir, "dir2")
    dir21 = os.path.join(dir2, "dir21")
    dirs = [dir1, dir2, dir11, dir21]
    map(os.mkdir, dirs)

    result = self.filesystem.subdirectories_of_directory(self.tempdir, recursive=True)

    self.assertEquals(set(dirs), set(result))

  @parameterized.expand([
    ('/tmp/dir',  '/some/other/dir',  '/tmp/dir/some/other/dir'),
    ('/tmp/dir/', '/some/other/dir',  '/tmp/dir/some/other/dir'),
    ('/tmp/dir',  '/some/other/dir/', '/tmp/dir/some/other/dir'),
    ('/tmp/dir/', '/some/other/dir/', '/tmp/dir/some/other/dir'),
    # Test that it doesn't adjust the path if the path already contains the root
    ('/tmp/dir', '/tmp/dir/random/addition', '/tmp/dir/random/addition')
  ])
  @unittest.skipIf(sys.platform.startswith('win'), "Example test data is Posix specific")
  def test_fake_filesystem_adjusts_path_relative_to_root(self, root, path, expected):

# Path: ice/filesystem.py
# class RealFilesystem(object):
# class FakeFilesystem(object):
#   def create_directories(self, path):
#   def path_exists(self, path):
#   def is_directory(self, path):
#   def is_file(self, path):
#   def is_writable(self, path):
#   def _paths_in_directory(self, directory, incl_subdirs=False):
#   def files_in_directory(self, directory, include_subdirectories=False):
#   def subdirectories_of_directory(self, directory, recursive=False):
#   def __init__(self, root):
#   def adjusted_path(self, path):
#   def create_directories(self, path):
#   def path_exists(self, path):
#   def is_directory(self, path):
#   def is_file(self, path):
#   def is_writable(self, path):
#   def files_in_directory(self, directory, include_subdirectories=False):
#   def subdirectories_of_directory(self, directory, recursive=False):


# Path: tests/filesystem_tests.py
import os
import shutil
import sys
import tempfile
import unittest
from nose_parameterized import parameterized
from ice import filesystem

    os.mkdir(dir1)
    file2 = os.path.join(dir1, "file2")
    self.touch_file(file2)

    result = self.filesystem.files_in_directory(self.tempdir, include_subdirectories=True)

    self.assertEquals(set([file1, file2]), set(result))

  def test_subdirectories_of_directory_should_return_subdirectories_of_subdirectories_when_recursive_is_true(self):
    dir1 = os.path.join(self.tempdir, "dir1")
    dir11 = os.path.join(dir1, "dir11")
    dir2 = os.path.join(self.tempdir, "dir2")
    dir21 = os.path.join(dir2, "dir21")
    dirs = [dir1, dir2, dir11, dir21]
    map(os.mkdir, dirs)

    result = self.filesystem.subdirectories_of_directory(self.tempdir, recursive=True)

    self.assertEquals(set(dirs), set(result))

  @parameterized.expand([
    ('/tmp/dir',  '/some/other/dir',  '/tmp/dir/some/other/dir'),
    ('/tmp/dir/', '/some/other/dir',  '/tmp/dir/some/other/dir'),
    ('/tmp/dir',  '/some/other/dir/', '/tmp/dir/some/other/dir'),
    ('/tmp/dir/', '/some/other/dir/', '/tmp/dir/some/other/dir'),
    # Test that it doesn't adjust the path if the path already contains the root
    ('/tmp/dir', '/tmp/dir/random/addition', '/tmp/dir/random/addition')
  ])
  @unittest.skipIf(sys.platform.startswith('win'), "Example test data is Posix specific")
  def test_fake_filesystem_adjusts_path_relative_to_root(self, root, path, expected):

    fs = filesystem.FakeFilesystem(root = root)