"""
Simple MODFLOW test with actual execution
"""

def test_modflow_simple():
    """Test actual MODFLOW execution with minimal setup"""
    
    import numpy as np
    import flopy
    import os
    
    print("Testing actual MODFLOW execution...")
    
    # Create simple model
    mf = flopy.modflow.Modflow("simple_test", model_ws=".", exe_name="mf2005.exe")
    
    # Minimal packages
    dis = flopy.modflow.ModflowDis(mf, nlay=1, nrow=10, ncol=10, 
                                   delr=50, delc=50, top=10, botm=0)
    
    bas = flopy.modflow.ModflowBas(mf, ibound=1, strt=5.0)
    
    lpf = flopy.modflow.ModflowLpf(mf, hk=10.0, vka=1.0)
    
    pcg = flopy.modflow.ModflowPcg(mf)
    
    oc = flopy.modflow.ModflowOc(mf, stress_period_data={(0,0): ['save head']})
    
    # Write and run
    print("Writing MODFLOW input files...")
    mf.write_input()
    
    print("Running MODFLOW...")
    success, buff = mf.run_model(silent=True)
    
    if success:
        print("✓ MODFLOW ran successfully!")
        
        # Read results
        if os.path.exists("simple_test.hds"):
            hds = flopy.utils.HeadFile("simple_test.hds")
            heads = hds.get_data()
            print(f"✓ Head results shape: {heads.shape}")
            print(f"✓ Mean head: {np.mean(heads):.3f} m")
            hds.close()
            return True
    else:
        print("✗ MODFLOW failed")
        print(buff)
        return False

if __name__ == "__main__":
    test_modflow_simple()