def test_longer_progression(): assert ChordProgression.from_string("C Fm C G7").progression == [ ChordWithRoot.from_name("C"), ChordWithRoot.from_name("Fm"), ChordWithRoot.from_name("C"), ChordWithRoot.from_name("G7"), ]
def test_repetition(): assert ChordProgression.from_string("C -- Fm G7").progression == [ ChordWithRoot.from_name("C"), ChordWithRoot.from_name("C"), ChordWithRoot.from_name("Fm"), ChordWithRoot.from_name("G7"), ]
def test_multiline(): assert (ChordProgression.from_string("""C Fm C G7 C E7 Am G""").progression == [ ChordWithRoot.from_name("C"), ChordWithRoot.from_name("Fm"), ChordWithRoot.from_name("C"), ChordWithRoot.from_name("G7"), ChordWithRoot.from_name("C"), ChordWithRoot.from_name("E7"), ChordWithRoot.from_name("Am"), ChordWithRoot.from_name("G"), ])
def _string_to_progression(string: str) -> List[ChordWithRoot]: string = string.strip() if string == "": return [] progression = [] for name in string.split(): name = name.strip() if name == REPETITION_SYMBOL: if not progression: raise InvalidProgression( "Can't repeat before at least one chord has been added") progression.append(progression[-1]) else: progression.append(ChordWithRoot.from_name(name)) return progression
def test_longer_chords(): assert ChordProgression.from_string("C Fm C G7").chords() == { ChordWithRoot.from_name("C"), ChordWithRoot.from_name("Fm"), ChordWithRoot.from_name("G7"), }
def test_single_chords(): assert ChordProgression.from_string("Cm").chords() == { ChordWithRoot.from_name("Cm") }
def test_single_progression(): assert ChordProgression.from_string("Cm").progression == [ ChordWithRoot.from_name("Cm") ]
def test_chord_transpose(name_in, name_out, shift): assert ChordWithRoot.from_name(name_in).transpose( shift) == ChordWithRoot.from_name(name_out)
def test_chord_repr(name_in): assert ChordWithRoot.from_name(name_in) == eval( repr(ChordWithRoot.from_name(name_in)))
def test_chord_note_to_midi(name_in, octave, midi): assert ChordWithRoot.from_name(name_in, octave).midi() == midi
def test_chord_with_root_invalid_name(name_in): with pytest.raises(InvalidChord): assert ChordWithRoot.from_name(name_in)
def test_chord_intervals(name_in, int_out): assert ChordWithRoot.from_name(name_in).intervals() == int_out
def test_chord_with_root(name_in, root_out, semi_out): assert ChordWithRoot.from_name(name_in).semitones == semi_out assert ChordWithRoot.from_name(name_in).root.name == root_out
def test_chord_add_root(name_in, octave): name_then_root = Chord.from_name(name_in).with_root(Note("A#", octave)) name_and_root = ChordWithRoot.from_name("A#" + name_in, octave=octave) print(name_and_root._keys()) assert name_then_root == name_and_root