Code Duplication    Length = 20-22 lines in 5 locations

elodie/tests/filesystem_test.py 5 locations

@@ 1083-1104 (lines=22) @@
1080
    if hasattr(load_config, 'config'):
1081
        del load_config.config
1082
1083
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1084
def test_get_folder_path_definition_with_more_than_two_levels():
1085
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1086
        f.write("""
1087
[Directory]
1088
year=%Y
1089
month=%m
1090
day=%d
1091
full_path=%year/%month/%day
1092
        """)
1093
1094
    if hasattr(load_config, 'config'):
1095
        del load_config.config
1096
    filesystem = FileSystem()
1097
    path_definition = filesystem.get_folder_path_definition()
1098
    expected = [
1099
        [('year', '%Y')], [('month', '%m')], [('day', '%d')]
1100
    ]
1101
    if hasattr(load_config, 'config'):
1102
        del load_config.config
1103
1104
    assert path_definition == expected, path_definition
1105
1106
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1107
def test_get_folder_path_definition_with_only_one_level():
@@ 1024-1044 (lines=21) @@
1021
1022
    assert path_definition == expected, path_definition
1023
1024
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1025
def test_get_folder_path_definition_location_date():
1026
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1027
        f.write("""
1028
[Directory]
1029
date=%Y-%m-%d
1030
location=%country
1031
full_path=%location/%date
1032
        """)
1033
1034
    if hasattr(load_config, 'config'):
1035
        del load_config.config
1036
    filesystem = FileSystem()
1037
    path_definition = filesystem.get_folder_path_definition()
1038
    expected = [
1039
        [('location', '%country')], [('date', '%Y-%m-%d')]
1040
    ]
1041
    if hasattr(load_config, 'config'):
1042
        del load_config.config
1043
1044
    assert path_definition == expected, path_definition
1045
1046
@mock.patch('elodie.config.config_file', '%s/config.ini-cached' % gettempdir())
1047
def test_get_folder_path_definition_cached():
@@ 1002-1022 (lines=21) @@
999
1000
    assert path_definition == [[('date', '%Y-%m-%b')], [('album', ''), ('location', '%city'), ('"Unknown Location"', '')]], path_definition
1001
1002
@mock.patch('elodie.config.config_file', '%s/config.ini-date-location' % gettempdir())
1003
def test_get_folder_path_definition_date_location():
1004
    with open('%s/config.ini-date-location' % gettempdir(), 'w') as f:
1005
        f.write("""
1006
[Directory]
1007
date=%Y-%m-%d
1008
location=%country
1009
full_path=%date/%location
1010
        """)
1011
1012
    if hasattr(load_config, 'config'):
1013
        del load_config.config
1014
    filesystem = FileSystem()
1015
    path_definition = filesystem.get_folder_path_definition()
1016
    expected = [
1017
        [('date', '%Y-%m-%d')], [('location', '%country')]
1018
    ]
1019
    if hasattr(load_config, 'config'):
1020
        del load_config.config
1021
1022
    assert path_definition == expected, path_definition
1023
1024
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1025
def test_get_folder_path_definition_location_date():
@@ 1127-1146 (lines=20) @@
1124
1125
    assert path_definition == expected, path_definition
1126
1127
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1128
def test_get_folder_path_definition_multi_level_custom():
1129
    with open('%s/config.ini-multi-level-custom' % gettempdir(), 'w') as f:
1130
        f.write("""
1131
[Directory]
1132
year=%Y
1133
month=%M
1134
full_path=%year/%album|%month|%"foo"/%month
1135
        """)
1136
1137
    if hasattr(load_config, 'config'):
1138
        del load_config.config
1139
    filesystem = FileSystem()
1140
    path_definition = filesystem.get_folder_path_definition()
1141
    
1142
    expected = [[('year', '%Y')], [('album', ''), ('month', '%M'), ('"foo"', '')], [('month', '%M')]]
1143
    if hasattr(load_config, 'config'):
1144
        del load_config.config
1145
1146
    assert path_definition == expected, path_definition
1147
@@ 1106-1125 (lines=20) @@
1103
1104
    assert path_definition == expected, path_definition
1105
1106
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1107
def test_get_folder_path_definition_with_only_one_level():
1108
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1109
        f.write("""
1110
[Directory]
1111
year=%Y
1112
full_path=%year
1113
        """)
1114
1115
    if hasattr(load_config, 'config'):
1116
        del load_config.config
1117
    filesystem = FileSystem()
1118
    path_definition = filesystem.get_folder_path_definition()
1119
    expected = [
1120
        [('year', '%Y')]
1121
    ]
1122
    if hasattr(load_config, 'config'):
1123
        del load_config.config
1124
1125
    assert path_definition == expected, path_definition
1126
1127
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1128
def test_get_folder_path_definition_multi_level_custom():