@@ -514,6 +514,127 @@ def test_cli_clear(self, capsys):
514514 captured = capsys .readouterr ()
515515 assert "Cleared 1 cached registry" in captured .out
516516
517+ def test_cli_copy (self , tmp_path ):
518+ """Test 'copy' command."""
519+ # Sync a registry first
520+ _DEFAULT_CACHE .clear (source = TEST_MODELS_SOURCE_NAME , ref = TEST_MODELS_REF )
521+ source = ModelSourceRepo (
522+ repo = TEST_MODELS_REPO ,
523+ name = TEST_MODELS_SOURCE_NAME ,
524+ refs = [TEST_MODELS_REF ],
525+ )
526+ result = source .sync (ref = TEST_MODELS_REF )
527+ assert len (result .synced ) == 1
528+
529+ # Load registry and get first model name
530+ registry = _DEFAULT_CACHE .load (TEST_MODELS_SOURCE_NAME , TEST_MODELS_REF )
531+ assert len (registry .models ) > 0
532+ model_name = next (iter (registry .models .keys ()))
533+
534+ # Create workspace
535+ workspace = tmp_path / "test-workspace"
536+
537+ # Copy model
538+ import argparse
539+
540+ from modflow_devtools .models .__main__ import cmd_copy
541+
542+ args = argparse .Namespace (model = model_name , workspace = str (workspace ), verbose = True )
543+ cmd_copy (args )
544+
545+ # Verify workspace was created and contains files
546+ assert workspace .exists ()
547+ assert len (list (workspace .rglob ("*" ))) > 0
548+
549+ def test_cli_copy_nonexistent_model (self , tmp_path , capsys ):
550+ """Test 'copy' command with nonexistent model."""
551+ # Sync a registry first
552+ _DEFAULT_CACHE .clear (source = TEST_MODELS_SOURCE_NAME , ref = TEST_MODELS_REF )
553+ source = ModelSourceRepo (
554+ repo = TEST_MODELS_REPO ,
555+ name = TEST_MODELS_SOURCE_NAME ,
556+ refs = [TEST_MODELS_REF ],
557+ )
558+ result = source .sync (ref = TEST_MODELS_REF )
559+ assert len (result .synced ) == 1
560+
561+ # Try to copy nonexistent model
562+ import argparse
563+
564+ from modflow_devtools .models .__main__ import cmd_copy
565+
566+ workspace = tmp_path / "test-workspace"
567+ args = argparse .Namespace (
568+ model = "nonexistent-model-12345" , workspace = str (workspace ), verbose = False
569+ )
570+
571+ with pytest .raises (SystemExit ):
572+ cmd_copy (args )
573+
574+ captured = capsys .readouterr ()
575+ assert "not in registry" in captured .err .lower ()
576+
577+ def test_cli_cp_alias (self , tmp_path ):
578+ """Test 'cp' alias for 'copy' command."""
579+ # Sync a registry first
580+ _DEFAULT_CACHE .clear (source = TEST_MODELS_SOURCE_NAME , ref = TEST_MODELS_REF )
581+ source = ModelSourceRepo (
582+ repo = TEST_MODELS_REPO ,
583+ name = TEST_MODELS_SOURCE_NAME ,
584+ refs = [TEST_MODELS_REF ],
585+ )
586+ result = source .sync (ref = TEST_MODELS_REF )
587+ assert len (result .synced ) == 1
588+
589+ # Load registry and get first model name
590+ registry = _DEFAULT_CACHE .load (TEST_MODELS_SOURCE_NAME , TEST_MODELS_REF )
591+ assert len (registry .models ) > 0
592+ model_name = next (iter (registry .models .keys ()))
593+
594+ # Create workspace
595+ workspace = tmp_path / "test-workspace-cp"
596+
597+ # Test that cp alias works via command parsing
598+ import argparse
599+
600+ from modflow_devtools .models .__main__ import cmd_copy
601+
602+ # Simulate args as if 'cp' command was used (argparse will set command to 'cp')
603+ args = argparse .Namespace (model = model_name , workspace = str (workspace ), verbose = False )
604+ cmd_copy (args )
605+
606+ # Verify workspace was created and contains files
607+ assert workspace .exists ()
608+ assert len (list (workspace .rglob ("*" ))) > 0
609+
610+ def test_python_cp_alias (self , tmp_path ):
611+ """Test Python API cp() alias for copy_to()."""
612+ # Sync a registry first
613+ _DEFAULT_CACHE .clear (source = TEST_MODELS_SOURCE_NAME , ref = TEST_MODELS_REF )
614+ source = ModelSourceRepo (
615+ repo = TEST_MODELS_REPO ,
616+ name = TEST_MODELS_SOURCE_NAME ,
617+ refs = [TEST_MODELS_REF ],
618+ )
619+ result = source .sync (ref = TEST_MODELS_REF )
620+ assert len (result .synced ) == 1
621+
622+ # Load registry and get first model name
623+ registry = _DEFAULT_CACHE .load (TEST_MODELS_SOURCE_NAME , TEST_MODELS_REF )
624+ assert len (registry .models ) > 0
625+ model_name = next (iter (registry .models .keys ()))
626+
627+ # Test cp() function
628+ from modflow_devtools .models import cp
629+
630+ workspace = tmp_path / "test-workspace-python-cp"
631+ result_path = cp (str (workspace ), model_name , verbose = False )
632+
633+ # Verify workspace was created and contains files
634+ assert result_path is not None
635+ assert workspace .exists ()
636+ assert len (list (workspace .rglob ("*" ))) > 0
637+
517638
518639@pytest .mark .xdist_group ("registry_cache" )
519640class TestIntegration :
0 commit comments