コード例 #1
0
def test_get_runs_from_db(database_with_three_datasets):
    db_path, datasets = database_with_three_datasets

    # Prepare an expected overview of the created database
    expected_overview = {
        ds.run_id: get_ds_info(ds, get_structure=False)
        for ds in datasets
    }

    # Get the actual overview of the created database
    overview = get_runs_from_db(db_path)  # get_structure=False is the default

    # Finally, assert
    assert overview == expected_overview

    # Prepare an expected overview of the created database WITH STRUCTURE
    expected_overview_with_structure = {
        ds.run_id: get_ds_info(ds, get_structure=True)
        for ds in datasets
    }

    # Get the actual overview of the created database WITH STRUCTURE
    overview_with_structure = get_runs_from_db(db_path, get_structure=True)

    # Finally, assert WITH STRUCTURE
    assert overview_with_structure == expected_overview_with_structure
コード例 #2
0
def test_get_ds_info(experiment):
    N = 5

    m = qc.Measurement(exp=experiment)

    m.register_custom_parameter('x', unit='cm')
    m.register_custom_parameter('y')
    m.register_custom_parameter('foo')
    for n in range(N):
        m.register_custom_parameter(f'z_{n}', setpoints=['x', 'y'])

    with m.run() as datasaver:
        dataset = datasaver.dataset

        ds_info_with_empty_timestamps = get_ds_info(dataset,
                                                    get_structure=False)
        assert ds_info_with_empty_timestamps['completed_date'] == ''
        assert ds_info_with_empty_timestamps['completed_time'] == ''

    # timestamps are difficult to test for, so we will cheat here and
    # instead of hard-coding timestamps we will just get them from the dataset
    # The same applies to the guid as it contains the timestamp
    started_ts = dataset.run_timestamp()
    completed_ts = dataset.completed_timestamp()

    expected_ds_info = {
        'experiment': '2d_softsweep',
        'sample': 'no sample',
        'completed_date': completed_ts[:10],
        'completed_time': completed_ts[11:],
        'started_date': started_ts[:10],
        'started_time': started_ts[11:],
        'name': 'results',
        'structure': None,
        'records': 0,
        'guid': dataset.guid,
        'inspectr_tag': ''
    }

    ds_info = get_ds_info(dataset, get_structure=False)

    assert ds_info == expected_ds_info

    expected_ds_info_with_structure = expected_ds_info.copy()
    expected_ds_info_with_structure['structure'] = get_ds_structure(dataset)

    ds_info_with_structure = get_ds_info(dataset)

    assert ds_info_with_structure == expected_ds_info_with_structure