Code Duplication    Length = 20-22 lines in 5 locations

elodie/tests/filesystem_test.py 5 locations

@@ 1251-1272 (lines=22) @@
1248
    if hasattr(load_config, 'config'):
1249
        del load_config.config
1250
1251
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1252
def test_get_folder_path_definition_with_more_than_two_levels():
1253
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1254
        f.write("""
1255
[Directory]
1256
year=%Y
1257
month=%m
1258
day=%d
1259
full_path=%year/%month/%day
1260
        """)
1261
1262
    if hasattr(load_config, 'config'):
1263
        del load_config.config
1264
    filesystem = FileSystem()
1265
    path_definition = filesystem.get_folder_path_definition()
1266
    expected = [
1267
        [('year', '%Y')], [('month', '%m')], [('day', '%d')]
1268
    ]
1269
    if hasattr(load_config, 'config'):
1270
        del load_config.config
1271
1272
    assert path_definition == expected, path_definition
1273
1274
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1275
def test_get_folder_path_definition_with_only_one_level():
@@ 1192-1212 (lines=21) @@
1189
1190
    assert path_definition == expected, path_definition
1191
1192
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1193
def test_get_folder_path_definition_location_date():
1194
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1195
        f.write("""
1196
[Directory]
1197
date=%Y-%m-%d
1198
location=%country
1199
full_path=%location/%date
1200
        """)
1201
1202
    if hasattr(load_config, 'config'):
1203
        del load_config.config
1204
    filesystem = FileSystem()
1205
    path_definition = filesystem.get_folder_path_definition()
1206
    expected = [
1207
        [('location', '%country')], [('date', '%Y-%m-%d')]
1208
    ]
1209
    if hasattr(load_config, 'config'):
1210
        del load_config.config
1211
1212
    assert path_definition == expected, path_definition
1213
1214
@mock.patch('elodie.config.config_file', '%s/config.ini-cached' % gettempdir())
1215
def test_get_folder_path_definition_cached():
@@ 1170-1190 (lines=21) @@
1167
1168
    assert path_definition == [[('date', '%Y-%m-%b')], [('album', ''), ('location', '%city'), ('"Unknown Location"', '')]], path_definition
1169
1170
@mock.patch('elodie.config.config_file', '%s/config.ini-date-location' % gettempdir())
1171
def test_get_folder_path_definition_date_location():
1172
    with open('%s/config.ini-date-location' % gettempdir(), 'w') as f:
1173
        f.write("""
1174
[Directory]
1175
date=%Y-%m-%d
1176
location=%country
1177
full_path=%date/%location
1178
        """)
1179
1180
    if hasattr(load_config, 'config'):
1181
        del load_config.config
1182
    filesystem = FileSystem()
1183
    path_definition = filesystem.get_folder_path_definition()
1184
    expected = [
1185
        [('date', '%Y-%m-%d')], [('location', '%country')]
1186
    ]
1187
    if hasattr(load_config, 'config'):
1188
        del load_config.config
1189
1190
    assert path_definition == expected, path_definition
1191
1192
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1193
def test_get_folder_path_definition_location_date():
@@ 1295-1314 (lines=20) @@
1292
1293
    assert path_definition == expected, path_definition
1294
1295
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1296
def test_get_folder_path_definition_multi_level_custom():
1297
    with open('%s/config.ini-multi-level-custom' % gettempdir(), 'w') as f:
1298
        f.write("""
1299
[Directory]
1300
year=%Y
1301
month=%M
1302
full_path=%year/%album|%month|%"foo"/%month
1303
        """)
1304
1305
    if hasattr(load_config, 'config'):
1306
        del load_config.config
1307
    filesystem = FileSystem()
1308
    path_definition = filesystem.get_folder_path_definition()
1309
    
1310
    expected = [[('year', '%Y')], [('album', ''), ('month', '%M'), ('"foo"', '')], [('month', '%M')]]
1311
    if hasattr(load_config, 'config'):
1312
        del load_config.config
1313
1314
    assert path_definition == expected, path_definition
1315
@@ 1274-1293 (lines=20) @@
1271
1272
    assert path_definition == expected, path_definition
1273
1274
@mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir())
1275
def test_get_folder_path_definition_with_only_one_level():
1276
    with open('%s/config.ini-location-date' % gettempdir(), 'w') as f:
1277
        f.write("""
1278
[Directory]
1279
year=%Y
1280
full_path=%year
1281
        """)
1282
1283
    if hasattr(load_config, 'config'):
1284
        del load_config.config
1285
    filesystem = FileSystem()
1286
    path_definition = filesystem.get_folder_path_definition()
1287
    expected = [
1288
        [('year', '%Y')]
1289
    ]
1290
    if hasattr(load_config, 'config'):
1291
        del load_config.config
1292
1293
    assert path_definition == expected, path_definition
1294
1295
@mock.patch('elodie.config.config_file', '%s/config.ini-multi-level-custom' % gettempdir())
1296
def test_get_folder_path_definition_multi_level_custom():