Skip to content

Commit

Permalink
Add tests to reproduce error when source path has folder component of…
Browse files Browse the repository at this point in the history
… numbers #239 (#241)
  • Loading branch information
jmathai authored Nov 1, 2017
1 parent fd3cab4 commit 362b1b1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
32 changes: 32 additions & 0 deletions elodie/tests/filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,38 @@ def test_get_folder_path_with_location():

assert path == os.path.join('2015-12-Dec','Sunnyvale'), path

def test_get_folder_path_with_int_in_source_path():
# gh-239
filesystem = FileSystem()
temporary_folder, folder = helper.create_working_folder('int')

origin = os.path.join(folder,'plain.jpg')
shutil.copyfile(helper.get_file('plain.jpg'), origin)

media = Photo(origin)
path = filesystem.get_folder_path(media.get_metadata())

assert path == os.path.join('2015-12-Dec','Unknown Location'), path

@mock.patch('elodie.config.config_file', '%s/config.ini-int-in-path' % gettempdir())
def test_get_folder_path_with_int_in_config_component():
# gh-239
with open('%s/config.ini-int-in-path' % gettempdir(), 'w') as f:
f.write("""
[Directory]
date=%Y
full_path=%date
""")
if hasattr(load_config, 'config'):
del load_config.config
filesystem = FileSystem()
media = Photo(helper.get_file('plain.jpg'))
path = filesystem.get_folder_path(media.get_metadata())
if hasattr(load_config, 'config'):
del load_config.config

assert path == os.path.join('2015'), path

@mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir())
def test_get_folder_path_with_original_default_unknown_location():
with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f:
Expand Down
14 changes: 10 additions & 4 deletions elodie/tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def checksum(file_path, blocksize=65536):
return hasher.hexdigest()
return None

def create_working_folder():
def create_working_folder(format=None):
temporary_folder = tempfile.gettempdir()
folder = os.path.join(temporary_folder, random_string(10), random_string(10))
folder = os.path.join(temporary_folder, random_string(10, format), random_string(10, format))
os.makedirs(folder)

return (temporary_folder, folder)
Expand Down Expand Up @@ -81,8 +81,14 @@ def populate_folder(number_of_files, include_invalid=False):

return folder

def random_string(length):
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(length))
def random_string(length, format=None):
format_choice = string.ascii_uppercase + string.digits
if format == 'int':
format_choice = string.digits
elif format == 'str':
format_choice = string.asci_uppercase

return ''.join(random.SystemRandom().choice(format_choice) for _ in range(length))

def random_decimal():
return random.random()
Expand Down

0 comments on commit 362b1b1

Please sign in to comment.