def test_fix_dataset_description_reports_good(tmp_path, caplog):
    """Make sure a proper file is logged as being so."""

    caplog.set_level(logging.DEBUG)

    bids_path = tmp_path
    with open(Path(bids_path) / "dataset_description.json", "w") as jfp:
        json.dump(DATASET_DESCRIPTION, jfp)

    fix_dataset_description(bids_path)

    assert len(caplog.records) == 1
    assert "Funding is: <class 'list'>" in caplog.records[0].message
def test_fix_dataset_description_missing_creates(tmp_path, caplog):

    caplog.set_level(logging.DEBUG)

    bids_path = tmp_path

    fix_dataset_description(bids_path)

    with open(Path(bids_path) / "dataset_description.json", "r") as jfp:
        fixed_json = json.load(jfp)

    assert fixed_json == DATASET_DESCRIPTION

    assert len(caplog.records) == 1
    assert "Creating default dataset_description.json file" in caplog.records[0].message
def test_fix_dataset_description_fixes(tmp_path, caplog):
    """Make sure the Funding is changed to be a list."""

    caplog.set_level(logging.DEBUG)

    # mess and fool around like the bids_client used to
    DATASET_DESCRIPTION["Funding"] = ""

    bids_path = tmp_path
    with open(Path(bids_path) / "dataset_description.json", "w") as jfp:
        json.dump(DATASET_DESCRIPTION, jfp)

    fix_dataset_description(bids_path)

    with open(Path(bids_path) / "dataset_description.json", "r") as jfp:
        fixed_json = json.load(jfp)

    assert len(caplog.records) == 3
    assert "is not a list" in caplog.records[1].message

    DATASET_DESCRIPTION["Funding"] = []
    assert fixed_json == DATASET_DESCRIPTION