@@ -510,20 +510,48 @@ def test_percent_escape(test_data_dir, tmpdir, helpers):
510510 assert f1 .id == "with%20space.txt"
511511 f2 = crate .add_file (f_path , dest_path = "subdir/with space.txt" )
512512 assert f2 .id == "subdir/with%20space.txt"
513+ f3 = crate .add_file (test_data_dir / "read_crate" / "without%20space.txt" )
514+ assert f3 .id == "without%2520space.txt"
513515 d_path = test_data_dir / "read_crate" / "a b"
514516 d1 = crate .add_dataset (d_path )
515517 assert d1 .id == "a%20b/"
516518 d2 = crate .add_dataset (d_path , dest_path = "subdir/a b" )
517519 assert d2 .id == "subdir/a%20b/"
520+ d3 = crate .add_dataset (test_data_dir / "read_crate" / "j%20k" )
521+ assert d3 .id == "j%2520k/"
518522 out_path = tmpdir / "ro_crate_out"
519523 crate .write (out_path )
520524 json_entities = helpers .read_json_entities (out_path )
521525 assert "with%20space.txt" in json_entities
522526 assert "subdir/with%20space.txt" in json_entities
527+ assert "without%2520space.txt" in json_entities
523528 assert "a%20b/" in json_entities
524529 assert "subdir/a%20b/" in json_entities
530+ assert "j%2520k/" in json_entities
531+ assert (out_path / "with space.txt" ).is_file ()
532+ assert (out_path / "subdir" / "with space.txt" ).is_file ()
533+ assert (out_path / "without%20space.txt" ).is_file ()
525534 assert (out_path / "a b" / "c d.txt" ).is_file ()
526535 assert (out_path / "subdir" / "a b" / "c d.txt" ).is_file ()
536+ assert (out_path / "j%20k" / "l%20m.txt" ).is_file ()
537+ out_zip_path = tmpdir / "ro_crate_out.zip"
538+ crate .write_zip (out_zip_path )
539+ unpack_path = tmpdir / "unpack"
540+ with zipfile .ZipFile (out_zip_path , "r" ) as zf :
541+ zf .extractall (unpack_path )
542+ json_entities = helpers .read_json_entities (unpack_path )
543+ assert "with%20space.txt" in json_entities
544+ assert "subdir/with%20space.txt" in json_entities
545+ assert "without%2520space.txt" in json_entities
546+ assert "a%20b/" in json_entities
547+ assert "subdir/a%20b/" in json_entities
548+ assert "j%2520k/" in json_entities
549+ assert (unpack_path / "with space.txt" ).is_file ()
550+ assert (unpack_path / "subdir" / "with space.txt" ).is_file ()
551+ assert (unpack_path / "without%20space.txt" ).is_file ()
552+ assert (unpack_path / "a b" / "c d.txt" ).is_file ()
553+ assert (unpack_path / "subdir" / "a b" / "c d.txt" ).is_file ()
554+ assert (unpack_path / "j%20k" / "l%20m.txt" ).is_file ()
527555
528556
529557def test_stream_empty_file (test_data_dir , tmpdir ):
@@ -548,3 +576,24 @@ def test_stream_empty_file(test_data_dir, tmpdir):
548576
549577 assert files_in_zip ["empty.txt" ] == 0
550578 assert files_in_zip ["folder/empty_not_listed.txt" ] == 0
579+
580+
581+ def test_write_zip_nested_dest (tmpdir , helpers ):
582+ root = tmpdir / "root"
583+ root .mkdir ()
584+ (root / "a b" ).mkdir ()
585+ (root / "a b" / "c d.txt" ).write_text ("C D\n " )
586+ (root / "a b" / "j k" ).mkdir ()
587+ (root / "a b" / "j k" / "l m.txt" ).write_text ("L M\n " )
588+ crate = ROCrate ()
589+ d1 = crate .add_dataset (root / "a b" , dest_path = "subdir/a b" )
590+ assert d1 .id == "subdir/a%20b/"
591+ out_zip_path = tmpdir / "ro_crate_out.zip"
592+ crate .write_zip (out_zip_path )
593+ unpack_path = tmpdir / "unpack"
594+ with zipfile .ZipFile (out_zip_path , "r" ) as zf :
595+ zf .extractall (unpack_path )
596+ json_entities = helpers .read_json_entities (unpack_path )
597+ assert "subdir/a%20b/" in json_entities
598+ assert (unpack_path / "subdir" / "a b" / "c d.txt" ).is_file ()
599+ assert (unpack_path / "subdir" / "a b" / "j k" / "l m.txt" ).is_file ()
0 commit comments