Code Duplication    Length = 20-22 lines in 5 locations

elodie/tests/filesystem_test.py 5 locations

@@ 1198-1219 (lines=22) @@
1195
    if hasattr(load_config, 'config'):
1196
        del load_config.config
1197
1198
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1199
def test_get_folder_path_definition_with_more_than_two_levels():
1200
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1201
        f.write("""
1202
[Directory]
1203
year=%Y
1204
month=%m
1205
day=%d
1206
full_path=%year/%month/%day
1207
        """)
1208
1209
    if hasattr(load_config, 'config'):
1210
        del load_config.config
1211
    filesystem = FileSystem()
1212
    path_definition = filesystem.get_folder_path_definition()
1213
    expected = [
1214
        [('year', '%Y')], [('month', '%m')], [('day', '%d')]
1215
    ]
1216
    if hasattr(load_config, 'config'):
1217
        del load_config.config
1218
1219
    assert path_definition == expected, path_definition
1220
1221
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1222
def test_get_folder_path_definition_with_only_one_level():
@@ 1139-1159 (lines=21) @@
1136
1137
    assert path_definition == expected, path_definition
1138
1139
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1140
def test_get_folder_path_definition_location_date():
1141
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1142
        f.write("""
1143
[Directory]
1144
date=%Y-%m-%d
1145
location=%country
1146
full_path=%location/%date
1147
        """)
1148
1149
    if hasattr(load_config, 'config'):
1150
        del load_config.config
1151
    filesystem = FileSystem()
1152
    path_definition = filesystem.get_folder_path_definition()
1153
    expected = [
1154
        [('location', '%country')], [('date', '%Y-%m-%d')]
1155
    ]
1156
    if hasattr(load_config, 'config'):
1157
        del load_config.config
1158
1159
    assert path_definition == expected, path_definition
1160
1161
@mock.patch('elodie.config.config_file', '%s/config.ini-cached' % gettempdir())
1162
def test_get_folder_path_definition_cached():
@@ 1117-1137 (lines=21) @@
1114
1115
    assert path_definition == [[('date', '%Y-%m-%b')], [('album', ''), ('location', '%city'), ('"Unknown Location"', '')]], path_definition
1116
1117
@mock.patch('elodie.config.config_file', '%s/config.ini-date-location' % gettempdir())
1118
def test_get_folder_path_definition_date_location():
1119
    with open('%s/config.ini-date-location' % gettempdir(), 'w') as f:
1120
        f.write("""
1121
[Directory]
1122
date=%Y-%m-%d
1123
location=%country
1124
full_path=%date/%location
1125
        """)
1126
1127
    if hasattr(load_config, 'config'):
1128
        del load_config.config
1129
    filesystem = FileSystem()
1130
    path_definition = filesystem.get_folder_path_definition()
1131
    expected = [
1132
        [('date', '%Y-%m-%d')], [('location', '%country')]
1133
    ]
1134
    if hasattr(load_config, 'config'):
1135
        del load_config.config
1136
1137
    assert path_definition == expected, path_definition
1138
1139
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1140
def test_get_folder_path_definition_location_date():
@@ 1242-1261 (lines=20) @@
1239
1240
    assert path_definition == expected, path_definition
1241
1242
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1243
def test_get_folder_path_definition_multi_level_custom():
1244
    with open('%s/config.ini-multi-level-custom' % gettempdir(), 'w') as f:
1245
        f.write("""
1246
[Directory]
1247
year=%Y
1248
month=%M
1249
full_path=%year/%album|%month|%"foo"/%month
1250
        """)
1251
1252
    if hasattr(load_config, 'config'):
1253
        del load_config.config
1254
    filesystem = FileSystem()
1255
    path_definition = filesystem.get_folder_path_definition()
1256
    
1257
    expected = [[('year', '%Y')], [('album', ''), ('month', '%M'), ('"foo"', '')], [('month', '%M')]]
1258
    if hasattr(load_config, 'config'):
1259
        del load_config.config
1260
1261
    assert path_definition == expected, path_definition
1262
@@ 1221-1240 (lines=20) @@
1218
1219
    assert path_definition == expected, path_definition
1220
1221
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1222
def test_get_folder_path_definition_with_only_one_level():
1223
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1224
        f.write("""
1225
[Directory]
1226
year=%Y
1227
full_path=%year
1228
        """)
1229
1230
    if hasattr(load_config, 'config'):
1231
        del load_config.config
1232
    filesystem = FileSystem()
1233
    path_definition = filesystem.get_folder_path_definition()
1234
    expected = [
1235
        [('year', '%Y')]
1236
    ]
1237
    if hasattr(load_config, 'config'):
1238
        del load_config.config
1239
1240
    assert path_definition == expected, path_definition
1241
1242
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1243
def test_get_folder_path_definition_multi_level_custom():