@@ -70,6 +70,27 @@ def test_datasets_create_clean_with_datadir(runner, project, client, load_datase
7070 assert not client .repository .is_dirty (untracked_files = True )
7171
7272
73+ def test_datasets_create_with_datadir_with_files (runner , project , client , load_dataset_with_injection ):
74+ """Test creating a dataset in clean repository."""
75+
76+ datadir = Path ("my/data/dir" )
77+ datadir .mkdir (parents = True , exist_ok = True )
78+
79+ file = datadir / "my_file"
80+ file .write_text ("content" )
81+
82+ result = runner .invoke (cli , ["dataset" , "create" , "--datadir" , datadir , "dataset" ])
83+ assert 0 == result .exit_code , format_result_exception (result )
84+ assert "OK" in result .output
85+
86+ dataset = load_dataset_with_injection ("dataset" , client )
87+ assert isinstance (dataset , Dataset )
88+ assert datadir == dataset .get_datadir (client )
89+ assert dataset .find_file (file )
90+
91+ assert not client .repository .is_dirty (untracked_files = True )
92+
93+
7394def test_datasets_create_dirty (runner , project , client , load_dataset_with_injection ):
7495 """Test creating a dataset in a dirty repository."""
7596 (client .path / "untracked" ).write_text ("untracked" )
@@ -475,6 +496,13 @@ def test_add_and_create_dataset(
475496 assert 1 == result .exit_code
476497 assert 'Dataset "new-dataset" does not exist.' in result .output
477498
499+ existing_file = client .path / datadir / "myfolder" / "myfile"
500+ existing_file .parent .mkdir (parents = True , exist_ok = True )
501+ existing_file .write_text ("content" )
502+
503+ existing_folder = client .path / datadir / "my_other_folder"
504+ existing_folder .mkdir (parents = True , exist_ok = True )
505+
478506 # Add succeeds with --create
479507 result = runner .invoke (
480508 cli ,
@@ -491,7 +519,9 @@ def test_add_and_create_dataset(
491519 assert os .stat (path2 )
492520 assert os .stat (path3 )
493521 dataset = load_dataset_with_injection ("new-dataset" , client )
494- assert {os .path .relpath (p , client .path ) for p in [path1 , path2 , path3 ]} == {f .entity .path for f in dataset .files }
522+ assert {os .path .relpath (p , client .path ) for p in [path1 , path2 , path3 , existing_file ]} == {
523+ f .entity .path for f in dataset .files
524+ }
495525
496526 # Further, add with --create fails
497527 result = runner .invoke (cli , ["dataset" , "add" , "--copy" , "--create" , "new-dataset" , str (directory_tree )])
0 commit comments