def testGetAppendIncremental(oneImageBidsI): run = BidsRun() run.appendIncremental(oneImageBidsI) assert run.getIncremental(0) == oneImageBidsI NUM_APPENDS = 20 for i in range(1, NUM_APPENDS): run.appendIncremental(oneImageBidsI) assert run.getIncremental(i) == oneImageBidsI
def testAppendConflictingEvents(oneImageBidsI, sampleBidsEntities): run = BidsRun() run.appendIncremental(oneImageBidsI) # This should work, as the previous events file is empty so any new data # shouldn't have a conflict newEventsData = [{key: data for key in DEFAULT_EVENTS_HEADERS} for data in range(1)] oneImageBidsI.events = oneImageBidsI.events.append(newEventsData, ignore_index=True) run.appendIncremental(oneImageBidsI) # This should also work, as they share the same starting row, and the new # DataFrame just has 5 additional rows newRowCount = 5 newEventsData = [{key: data for key in DEFAULT_EVENTS_HEADERS} for data in range(1, newRowCount + 1)] oneImageBidsI.events = oneImageBidsI.events.append(newEventsData, ignore_index=True) run.appendIncremental(oneImageBidsI) # This should fail, as rows for same onset times have different values now with pytest.raises(MetadataMismatchError): oneImageBidsI.events.iloc[int(newRowCount / 2):] += 1 run.appendIncremental(oneImageBidsI) assert oneImageBidsI != run.getIncremental(0)
def testAppendConflictingDatasetDescription(oneImageBidsI, sampleBidsEntities): run = BidsRun() run.appendIncremental(oneImageBidsI) oneImageBidsI.datasetDescription["newKey"] = "totally new data" with pytest.raises(MetadataMismatchError): run.appendIncremental(oneImageBidsI) assert oneImageBidsI != run.getIncremental(0)
def testAppendConflictingReadme(oneImageBidsI, sampleBidsEntities): run = BidsRun() run.appendIncremental(oneImageBidsI) oneImageBidsI.readme += "totally new data" with pytest.raises(MetadataMismatchError): run.appendIncremental(oneImageBidsI) assert oneImageBidsI != run.getIncremental(0)
def testGetOutOfBounds(oneImageBidsI): run = BidsRun() NUM_APPENDS = 10 for i in range(NUM_APPENDS): run.appendIncremental(oneImageBidsI) # This is inbounds due to how negative indexing works assert run.getIncremental(0) == run.getIncremental(-1 * NUM_APPENDS) with pytest.raises(IndexError): run.getIncremental(NUM_APPENDS) with pytest.raises(IndexError): run.getIncremental(NUM_APPENDS + 1) with pytest.raises(IndexError): run.getIncremental(-1 * NUM_APPENDS - 1)