def test_events():
    d = Dataset(ns2_file)
    create_empty_annotations(annot_file, d)

    annot = Annotations(annot_file)
    with raises(IndexError):
        annot.add_event_type('spindle')

    annot.add_rater('test')
    annot.add_event_type('spindle')
    annot.add_event_type('spindle')

    assert len(annot.event_types) == 1

    annot.add_event('slowwave', (1, 2), chan=('FP1', ))
    annot.add_event('spindle', (3, 4))
    assert len(annot.event_types) == 2
    assert len(annot.get_events()) == 2

    annot.remove_event_type('spindle')
    assert len(annot.event_types) == 1
    assert len(annot.get_events()) == 1

    annot.remove_event('slowwave')
    assert len(annot.event_types) == 1
    assert len(annot.get_events()) == 0
def test_epochs():
    d = Dataset(ns2_file)
    create_empty_annotations(annot_file, d)

    annot = Annotations(annot_file)
    annot.add_rater('test')

    assert len(annot.get_epochs()) == 50
    assert len(annot.get_epochs(time=(1000, 2000))) == 16
def test_bookmarks():
    d = Dataset(ns2_file)
    create_empty_annotations(annot_file, d)

    annot = Annotations(annot_file)

    with raises(IndexError):
        annot.current_rater

    with raises(IndexError):
        annot.add_bookmark('bookmark', (1, 2), ('Fpz', ))

    annot.add_rater('test')
    annot.add_bookmark('bookmark', (1, 2), ('Fpz', ))
    assert len(annot.get_bookmarks()) == 1
    annot.remove_bookmark('bookmark')
    assert len(annot.get_bookmarks()) == 0
def test_get_cycles():
    d = Dataset(ns2_file)
    create_empty_annotations(annot_file, d)

    annot = Annotations(annot_file)
    annot.add_rater('test')

    annot.set_cycle_mrkr(510)
    annot.set_cycle_mrkr(540)
    annot.set_cycle_mrkr(570)
    annot.set_cycle_mrkr(600, end=True)

    cycles = annot.get_cycles()
    assert len(cycles) == 3
    assert cycles[2] == (570, 600, 3)

    annot.remove_cycle_mrkr(510)
    annot.clear_cycles()

    cycles = annot.get_cycles()
    assert cycles is None
def test_create_annot():
    d = Dataset(ns2_file)
    create_empty_annotations(annot_file, d)