code: def test_experiment_group(engine: Engine):
      def verify_xg(session):
          xg = session.query(ExperimentGroup).all()
          assert len(xg) == 1
          xg = xg[0]
          return xg
  
      # basic creation
      with session_scope(engine) as session:
          xg = ExperimentGroup.get_or_create(session=session)
          session.add(xg)
  
      test_timestamp = datetime.now()
  
      # test experiment group addition/peristence, test duplicate
      with session_scope(engine) as session:
          xg = verify_xg(session)
          assert xg.created < test_timestamp
          new_xg = ExperimentGroup.get_or_create(session=session)
  
      # test get_or_create, then create new xg
      with session_scope(engine) as session:
          xg = verify_xg(session)
          new_xg = ExperimentGroup.get_or_create(
              session=session, name="new-xgroup"
          )
          session.add(new_xg)
  
      # test getting recent experiment groups
      with session_scope(engine) as session:
          xg = (
              session.query(ExperimentGroup)
              .filter(ExperimentGroup.created > test_timestamp)
              .all()
          )
          assert len(xg) == 1
          xg = xg[0]
          assert xg.name == "new-xgroup"
  
file_path: caliban/tests/caliban/history/test_history.py
imports: from datetime import datetime
  from sqlalchemy.engine.base import Engine
  import pytest
  from caliban.history.types import ContainerSpec, Experiment, ExperimentGroup, Job, JobSpec, Platform
  from caliban.history.util import get_mem_engine, session_scope
  from caliban.util import current_user
label_desc: Use image node_id 2 for calling a global function with example usage: test_experiment_group(engine) and returns: xg