def test_parameters(
  generator: random_log_database_generator.RandomLogDatabaseGenerator,
  run_id: run_id_lib.RunId,
  max_param_count: int,
  db_session: log_database.Database.SessionType,
):
  """Black-box test of generator properties."""
  logs = generator.CreateRandomRunLogs(
    run_id=run_id, max_param_count=max_param_count
  )
  # We can't test on max_param_count as an upper bound because the log generator
  # can add additional graph_db parameters.
  assert 1 <= len(logs.parameters)
  for param in logs.parameters:
    assert isinstance(param, log_database.Parameter)
    assert param.run_id == run_id

  db_session.add_all(logs.all)
  db_session.commit()
Пример #2
0
def test_Parameter_CreateManyFromDict(
  empty_db_session: log_database.Database.SessionType,
):
  """Test batch-creation of parameters."""
  run = run_id.RunId.GenerateUnique("test")
  params = log_database.Parameter.CreateManyFromDict(
    run_id=run,
    type=log_database.ParameterType.BUILD_INFO,
    parameters={"a": 1, "b": "foo",},
  )

  assert len(params) == 2
  for param in params:
    assert param.run_id == run
    assert param.type == log_database.ParameterType.BUILD_INFO
    assert param.name in {"a", "b"}
    assert param.value in {1, "foo"}
  empty_db_session.add_all([log_database.RunId(run_id=str(run))] + params)
  empty_db_session.commit()
def test_batches(
  generator: random_log_database_generator.RandomLogDatabaseGenerator,
  run_id: run_id_lib.RunId,
  max_epoch_count: int,
  max_batch_count: int,
  db_session: log_database.Database.SessionType,
):
  """Black-box test of generator properties."""
  logs = generator.CreateRandomRunLogs(
    run_id=run_id,
    max_epoch_count=max_epoch_count,
    max_batch_count=max_batch_count,
  )
  assert 2 <= len(logs.batches) <= 3 * max_epoch_count * max_batch_count
  for batch in logs.batches:
    assert isinstance(batch, log_database.Batch)
    assert batch.run_id == run_id

  db_session.add_all(logs.all)
  db_session.commit()
Пример #4
0
def test_RunId_add_one(empty_db_session: log_database.Database.SessionType):
  """Test adding a run ID to the database."""
  run = run_id.RunId.GenerateUnique("test")
  empty_db_session.add(log_database.RunId(run_id=str(run)))
  empty_db_session.commit()