@@ -1245,38 +1245,60 @@ def test_get_list_from_multiformat_input(input_value, expected_list, expected_wa
1245
1245
1246
1246
# noinspection PyUnresolvedReferences
1247
1247
@pytest .mark .parametrize (
1248
- "source_path, destination_parent_path , destination_name, expected_destination_path " ,
1249
- [(pathlib . Path ( "foo/source-path" ) ,
1250
- pathlib . Path ( "bar/destination-parent-path" ) ,
1248
+ "source_sub_path, destination_parent_sub_path , destination_name, expected_destination_sub_path " ,
1249
+ [("foo/source-path" ,
1250
+ "bar/destination-parent-path" ,
1251
1251
None ,
1252
- pathlib . Path ( "bar/destination-parent-path/source-path" ) ),
1253
- (pathlib . Path ( "foo/source-path" ) ,
1254
- pathlib . Path ( "bar/destination-parent-path" ) ,
1252
+ "bar/destination-parent-path/source-path" ),
1253
+ ("foo/source-path" ,
1254
+ "bar/destination-parent-path" ,
1255
1255
"destination-name" ,
1256
- pathlib . Path ( "bar/destination-parent-path/destination-name" ) )])
1257
- @pytest .mark .parametrize ("exists" , [True , False ])
1256
+ "bar/destination-parent-path/destination-name" )])
1257
+ @pytest .mark .parametrize ("exists" , ["no" , "yes" , "symlink" , "broken" ])
1258
1258
@pytest .mark .parametrize ("force" , [True , False ])
1259
1259
@pytest .mark .parametrize ("is_dir" , [True , False ])
1260
1260
def test_install_from_path (capsys ,
1261
- mocker ,
1262
- source_path ,
1263
- destination_parent_path ,
1261
+ tmp_path ,
1262
+ source_sub_path ,
1263
+ destination_parent_sub_path ,
1264
1264
destination_name ,
1265
- expected_destination_path ,
1265
+ expected_destination_sub_path ,
1266
1266
exists ,
1267
1267
force ,
1268
1268
is_dir ):
1269
- is_dir = unittest . mock . sentinel . is_dir
1269
+ source_path = tmp_path . joinpath ( source_sub_path )
1270
1270
1271
- compile_sketches = get_compilesketches_object ()
1271
+ # Generate source path
1272
+ if is_dir :
1273
+ source_path .mkdir (parents = True )
1274
+ else :
1275
+ source_path .parent .mkdir (parents = True , exist_ok = True )
1276
+ source_path .touch ()
1272
1277
1273
- mocker .patch .object (pathlib .Path , "exists" , autospec = True , return_value = exists )
1274
- mocker .patch ("shutil.rmtree" , autospec = True )
1275
- mocker .patch .object (pathlib .Path , "mkdir" , autospec = True )
1276
- mocker .patch .object (pathlib .Path , "is_dir" , autospec = True , return_value = is_dir )
1277
- mocker .patch .object (pathlib .Path , "symlink_to" , autospec = True )
1278
+ destination_parent_path = tmp_path .joinpath (destination_parent_sub_path )
1279
+ if destination_name is None :
1280
+ destination_path = destination_parent_path .joinpath (source_path .name )
1281
+ else :
1282
+ destination_path = destination_parent_path .joinpath (destination_name )
1283
+ destination_path .parent .mkdir (parents = True , exist_ok = True )
1278
1284
1279
- if exists and not force :
1285
+ # Generate pre-existing destination path
1286
+ if exists == "yes" :
1287
+ if is_dir :
1288
+ destination_path .mkdir (parents = True )
1289
+ else :
1290
+ # source_path.parent.mkdir(parents=True)
1291
+ destination_path .touch ()
1292
+ elif exists == "symlink" :
1293
+ destination_path .symlink_to (target = source_path , target_is_directory = source_path .is_dir ())
1294
+ elif exists == "broken" :
1295
+ destination_path .symlink_to (target = tmp_path .joinpath ("nonexistent" ), target_is_directory = is_dir )
1296
+
1297
+ expected_destination_path = tmp_path .joinpath (expected_destination_sub_path )
1298
+
1299
+ compile_sketches = get_compilesketches_object ()
1300
+
1301
+ if exists != "no" and not force :
1280
1302
with pytest .raises (expected_exception = SystemExit , match = "1" ):
1281
1303
compile_sketches .install_from_path (source_path = source_path ,
1282
1304
destination_parent_path = destination_parent_path ,
@@ -1291,13 +1313,8 @@ def test_install_from_path(capsys,
1291
1313
destination_parent_path = destination_parent_path ,
1292
1314
destination_name = destination_name ,
1293
1315
force = force )
1294
- if exists and force :
1295
- shutil .rmtree .assert_called_once_with (path = expected_destination_path )
1296
- else :
1297
- shutil .rmtree .assert_not_called ()
1298
1316
1299
- pathlib .Path .symlink_to .assert_called_once_with (expected_destination_path , target = source_path ,
1300
- target_is_directory = is_dir )
1317
+ assert expected_destination_path .resolve () == source_path
1301
1318
1302
1319
1303
1320
def test_install_from_path_functional (tmp_path ):
0 commit comments