Beispiel #1
0
def test_remove_note_strict_false():
    c = Chord(Note(name='C'), Note(name='D'))
    c.remove_note(note=Note(name='D'), strict=False)
    assert len(c.notes) == 1
    assert c.notes[0] == Note(name='C')

    c = Chord(Note(name='C'), Note(name='E'))
    c.remove_note(note=Note(name='C'), strict=False)
    assert len(c.notes) == 1
    assert c.notes[0] == Note(name='E')

    try:
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(note=Note(name='A'), strict=False)
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(octave=3, strict=False)
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(octave=4, strict=False)
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(freq=12, strict=False)
    except ChordException:
        pytest.fail('Unexpected ChordException')

    with pytest.raises(AttributeError) as exc:
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(note='invalid', strict=False)

    assert "'str' object has no attribute 'freq'" == str(exc.value)
Beispiel #2
0
def test_remove_note_strict():
    c = Chord(Note(name='C'), Note(name='D'))
    with pytest.raises(ChordException) as exc:
        c.remove_note(note=Note(name='D'))

    assert len(c.notes) == 2
    assert c.notes[0] == Note(name='C')
    assert c.notes[1] == Note(name='D')
    assert 'Invalid Chord.' == str(exc.value)

    c = Chord(Note(name='C'), Note(name='E'))
    with pytest.raises(ChordException) as exc:
        c.remove_note(note=Note(name='C'))

    assert len(c.notes) == 2
    assert c.notes[0] == Note(name='C')
    assert c.notes[1] == Note(name='E')
    assert 'Invalid Chord.' == str(exc.value)

    with pytest.raises(AttributeError) as exc:
        Chord(Note(name='C'), Note(name='E'),
              Note(name='G')).remove_note(note='invalid')

    assert "'str' object has no attribute 'freq'" == str(exc.value)

    with pytest.raises(ChordException) as exc:
        Chord(strict=False).remove_note(note='invalid')

    assert 'Invalid Chord.' == str(exc.value)