# Path: peachbox/utils/test_helper.py
# class TestHelper(object):
#     @staticmethod
#     def mkdir_tmp():
#         dir_name = '/tmp/' + TestHelper.random_name() 
#         call(['mkdir', dir_name])
#         return dir_name
# 
#     @staticmethod
#     def touch(path):
#         call(['touch', path])
#     
#     @staticmethod
#     def mkdir(path):
#         TestHelper.mkdir_p(path)
# 
#     @staticmethod
#     def mkdir_p(path):
#         call(['mkdir', '-p', path])
# 
#     @staticmethod
#     def rm_r(dir_name):
#         call(['rm', '-fr', dir_name])
# 
#     @staticmethod
#     def write_json(filename, json_input, dir_name=''):
#         if not dir_name: dir_name = TestHelper.mkdir_tmp()
# 
#         if( not os.path.exists(dir_name)): call(['mkdir', '-p', dir_name]) 
# 
#         filename = dir_name + '/' + filename
#         
#         base_filename = filename[0:-3] if filename.endswith('.gz') else filename
# 
#         f = open(base_filename, 'w')
#         for line in json_input:
#             f.write(json.dumps(line) + '\n')
#         f.close()
# 
#         if filename.endswith('.gz'):
#             call(['gzip', filename])
# 
#         return filename
# 
#     @staticmethod
#     def random_name():
#         return str(int(random()*1000000000))
# 
#     @staticmethod
#     def read_spark_result(dir_name):
#         result = glob.glob(os.path.join(dir_name, '*/part*'))[0]
#         with open(result) as f:
#             content = f.readlines()
#         j = [json.loads(line) for line in content]
#         return j
# 
#     @staticmethod
#     def write_string(filename, input):
#         with open(filename, 'w') as f:
#             f.write(input)
# 
# Path: peachbox/utils/date.py
# class Date(object):
# 
#     @staticmethod
#     def tz_berlin(year, month, day):
#         return Date(date=datetime(year, month, day), timezone=pytz.timezone('Europe/Berlin'))
# 
#     @staticmethod
#     def from_utc_utime(timezone, seconds):
#         d = datetime.fromtimestamp(float(seconds))
#         d = d.replace(tzinfo=pytz.utc)
#         d.astimezone(timezone)
#         return Date(timezone=timezone, date=d)
# 
#     def __init__(self, timezone=None, date=None):
#         self.timezone  = timezone
#         self._datetime = self.localize(date)
#         self.start_epoch  = datetime(1970,1,1, tzinfo=pytz.utc)
# 
#     def localize(self, _datetime):
#         dt = None
#         if _datetime is None:
#             dt = None
#         elif _datetime.tzinfo is not None:
#             dt = _datetime
#         elif self.timezone:
#             dt = self.timezone.localize(_datetime, is_dst=True)
#         else:
#             raise Exception('Date.localize: datetime has no tz or Date has no timezone information')
#         return dt
# 
#     # @parameter string: YYYYMMDD
#     def parse(self, string):
#         dt = parser.parse(string)
#         self._datetime = self.localize(dt)
#         return self
# 
#     def datetime(self):
#         if not self._datetime.tzinfo:
#             raise 'datetime does not have timezone information'
#         return self._datetime
# 
#     def seconds(self):
#         return int((self.datetime()-self.start_epoch).total_seconds())


import unittest
import peachbox.fs
from peachbox.utils.test_helper import TestHelper
from peachbox.utils.date import Date


class TestLocal(unittest.TestCase):
    def setUp(self):
        self.fs = peachbox.fs.Local()

    def test_ls_a(self):
        mart = TestHelper.random_name()
        TestHelper.mkdir('/tmp/' + mart)
        TestHelper.touch('/tmp/' + mart + '/filename')
        self.assertEqual('/tmp/' + mart + '/filename', self.fs.ls_a('/tmp/' + mart)[1][0])

    def test_ls(self):
        mart = TestHelper.random_name()
        TestHelper.mkdir('/tmp/' + mart)
        TestHelper.touch('/tmp/' + mart + '/filename')
        self.assertEqual('/tmp/' + mart + '/filename', self.fs.ls(mart, '')[0])

    def test_dirs_in_period(self):
        mart = TestHelper.random_name()
        date1 = Date.tz_berlin(2014,4,1)

# Path: peachbox/utils/test_helper.py
# class TestHelper(object):
#     @staticmethod
#     def mkdir_tmp():
#         dir_name = '/tmp/' + TestHelper.random_name() 
#         call(['mkdir', dir_name])
#         return dir_name
# 
#     @staticmethod
#     def touch(path):
#         call(['touch', path])
#     
#     @staticmethod
#     def mkdir(path):
#         TestHelper.mkdir_p(path)
# 
#     @staticmethod
#     def mkdir_p(path):
#         call(['mkdir', '-p', path])
# 
#     @staticmethod
#     def rm_r(dir_name):
#         call(['rm', '-fr', dir_name])
# 
#     @staticmethod
#     def write_json(filename, json_input, dir_name=''):
#         if not dir_name: dir_name = TestHelper.mkdir_tmp()
# 
#         if( not os.path.exists(dir_name)): call(['mkdir', '-p', dir_name]) 
# 
#         filename = dir_name + '/' + filename
#         
#         base_filename = filename[0:-3] if filename.endswith('.gz') else filename
# 
#         f = open(base_filename, 'w')
#         for line in json_input:
#             f.write(json.dumps(line) + '\n')
#         f.close()
# 
#         if filename.endswith('.gz'):
#             call(['gzip', filename])
# 
#         return filename
# 
#     @staticmethod
#     def random_name():
#         return str(int(random()*1000000000))
# 
#     @staticmethod
#     def read_spark_result(dir_name):
#         result = glob.glob(os.path.join(dir_name, '*/part*'))[0]
#         with open(result) as f:
#             content = f.readlines()
#         j = [json.loads(line) for line in content]
#         return j
# 
#     @staticmethod
#     def write_string(filename, input):
#         with open(filename, 'w') as f:
#             f.write(input)
# 
# Path: peachbox/utils/date.py
# class Date(object):
# 
#     @staticmethod
#     def tz_berlin(year, month, day):
#         return Date(date=datetime(year, month, day), timezone=pytz.timezone('Europe/Berlin'))
# 
#     @staticmethod
#     def from_utc_utime(timezone, seconds):
#         d = datetime.fromtimestamp(float(seconds))
#         d = d.replace(tzinfo=pytz.utc)
#         d.astimezone(timezone)
#         return Date(timezone=timezone, date=d)
# 
#     def __init__(self, timezone=None, date=None):
#         self.timezone  = timezone
#         self._datetime = self.localize(date)
#         self.start_epoch  = datetime(1970,1,1, tzinfo=pytz.utc)
# 
#     def localize(self, _datetime):
#         dt = None
#         if _datetime is None:
#             dt = None
#         elif _datetime.tzinfo is not None:
#             dt = _datetime
#         elif self.timezone:
#             dt = self.timezone.localize(_datetime, is_dst=True)
#         else:
#             raise Exception('Date.localize: datetime has no tz or Date has no timezone information')
#         return dt
# 
#     # @parameter string: YYYYMMDD
#     def parse(self, string):
#         dt = parser.parse(string)
#         self._datetime = self.localize(dt)
#         return self
# 
#     def datetime(self):
#         if not self._datetime.tzinfo:
#             raise 'datetime does not have timezone information'
#         return self._datetime
# 
#     def seconds(self):
#         return int((self.datetime()-self.start_epoch).total_seconds())


# Path: peachbox/fs/tests/test_local.py
import unittest
import peachbox.fs
from peachbox.utils.test_helper import TestHelper
from peachbox.utils.date import Date



class TestLocal(unittest.TestCase):
    def setUp(self):
        self.fs = peachbox.fs.Local()

    def test_ls_a(self):
        mart = TestHelper.random_name()
        TestHelper.mkdir('/tmp/' + mart)
        TestHelper.touch('/tmp/' + mart + '/filename')
        self.assertEqual('/tmp/' + mart + '/filename', self.fs.ls_a('/tmp/' + mart)[1][0])

    def test_ls(self):
        mart = TestHelper.random_name()
        TestHelper.mkdir('/tmp/' + mart)
        TestHelper.touch('/tmp/' + mart + '/filename')
        self.assertEqual('/tmp/' + mart + '/filename', self.fs.ls(mart, '')[0])

    def test_dirs_in_period(self):
        mart = TestHelper.random_name()
        date1 = Date.tz_berlin(2014,4,1)

        date2 = Date.tz_berlin(2014,4,2)