From 582d6090238d95e73098b1b67a64d1e90584eccb Mon Sep 17 00:00:00 2001 From: zserg Date: Wed, 27 Jan 2016 18:28:18 +0400 Subject: [PATCH] windows timezone problem in filesystem test fixed --- elodie/media/media.py | 3 ++- elodie/tests/filesystem_test.py | 34 ++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/elodie/media/media.py b/elodie/media/media.py index 31e2a0d..cb7971a 100644 --- a/elodie/media/media.py +++ b/elodie/media/media.py @@ -225,7 +225,8 @@ class Media(object): if(constants.debug is True): print '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % (exiftool, exiftool_config, name, source) # noqa process_output = subprocess.Popen( - [exiftool, '-config', exiftool_config, '-xmp-elodie:Album=%s'%(name),source], + '%s -config "%s" -xmp-elodie:Album="%s" "%s"' % + (exiftool, exiftool_config, name, source), stdout=subprocess.PIPE, shell=True ) diff --git a/elodie/tests/filesystem_test.py b/elodie/tests/filesystem_test.py index bfe05b1..875b7b4 100644 --- a/elodie/tests/filesystem_test.py +++ b/elodie/tests/filesystem_test.py @@ -4,6 +4,9 @@ import sys import re import shutil +from datetime import datetime +from datetime import timedelta +import time sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))) @@ -12,9 +15,22 @@ from elodie.filesystem import FileSystem from elodie.media.media import Media from elodie.media.photo import Photo from elodie.media.video import Video +from nose.plugins.skip import SkipTest os.environ['TZ'] = 'GMT' +if os.name == 'nt': + tz_shift = (datetime.fromtimestamp(0) - + datetime.utcfromtimestamp(0)).seconds/3600 +else: + tz_shift = 0 + +def path_tz_fix(s_path): + #some_prefix2015-12-05_00-59-26-with-title-some-title.jpg + m = re.search('(\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2})',s_path) + t_date = datetime.fromtimestamp(time.mktime(time.strptime(m.group(0), '%Y-%m-%d_%H-%M-%S'))) + s_date_fix = (t_date-timedelta(hours=tz_shift)).strftime('%Y-%m-%d_%H-%M-%S') + return re.sub('\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}',s_date_fix,s_path) def test_create_directory_success(): filesystem = FileSystem() @@ -128,14 +144,14 @@ def test_get_file_name_plain(): media = Photo(helper.get_file('plain.jpg')) file_name = filesystem.get_file_name(media) - assert file_name == '2015-12-05_00-59-26-plain.jpg', file_name + assert file_name == path_tz_fix('2015-12-05_00-59-26-plain.jpg'), file_name def test_get_file_name_with_title(): filesystem = FileSystem() media = Photo(helper.get_file('with-title.jpg')) file_name = filesystem.get_file_name(media) - assert file_name == '2015-12-05_00-59-26-with-title-some-title.jpg', file_name + assert file_name == path_tz_fix('2015-12-05_00-59-26-with-title-some-title.jpg'), file_name def test_get_folder_name_by_date(): filesystem = FileSystem() @@ -195,7 +211,7 @@ def test_process_file_plain(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo.jpg')) in destination, destination def test_process_file_with_title(): filesystem = FileSystem() @@ -215,7 +231,7 @@ def test_process_file_with_title(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo-some-title.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Unknown Location','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination def test_process_file_with_location(): filesystem = FileSystem() @@ -235,7 +251,7 @@ def test_process_file_with_location(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo.jpg')) in destination, destination def test_process_file_with_location_and_title(): filesystem = FileSystem() @@ -255,7 +271,7 @@ def test_process_file_with_location_and_title(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo-some-title.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Sunnyvale','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination def test_process_file_with_album(): filesystem = FileSystem() @@ -275,7 +291,7 @@ def test_process_file_with_album(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo.jpg')) in destination, destination def test_process_file_with_album_and_title(): filesystem = FileSystem() @@ -295,7 +311,7 @@ def test_process_file_with_album_and_title(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination def test_process_file_with_album_and_title_and_location(): filesystem = FileSystem() @@ -315,4 +331,4 @@ def test_process_file_with_album_and_title_and_location(): assert origin_checksum is not None, origin_checksum assert origin_checksum == destination_checksum, destination_checksum - assert os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg') in destination, destination + assert path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination