import json
import subprocess

def test_notebook(notebook_path):
    with open(notebook_path, 'r', encoding='utf-8') as f:
        nb = json.load(f)
    
    for i, cell in enumerate(nb['cells']):
        if cell['cell_type'] == 'code':
            code = ''.join(cell['source'])
            try:
                print(f"Executing cell {i+1}...")
                exec(code, globals())
                print(f"Cell {i+1} executed successfully.")
            except Exception as e:
                print(f"Error executing cell {i+1}: {e}")
                return False
    return True

if __name__ == "__main__":
    import sys
    test_notebook(sys.argv[1])
