def keyoctave_parse_test(): ''' Check valid KeyOctave parses ''' for key in _KEYS: for octave in xrange(10): keyoctave = KeyOctave.parse("{}{}".format(key, octave)) eq_(keyoctave.key, Key.parse(key)) eq_(keyoctave.octave, octave)
def note_parse_test(): ''' Basic note parsing test ''' for note in _NOTES: parsed = Key.parse(note) eq_(parsed.note, note) eq_(parsed.accidental, None) _check_key_str_parse(parsed)
def key_normalization_test(): ''' Check equal keys are parsed to equal Keys ''' for skey, fkey in [('A#', 'Bb'), ('C#', 'Db'), ('D#', 'Eb'), ('F#', 'Gb'), ('G#', 'Ab'), ]: return Key.parse(skey) == Key.parse(fkey)
def flat_parse_test(): ''' Check flat parsing ''' for note in _NOTES: parsed = Key.parse(note + "b") eq_(Key.parse(note).transpose(-1), parsed) _check_key_str_parse(parsed)
def sharp_parse_test(): ''' Check sharp parsing ''' for note in _NOTES: parsed = Key.parse(note + "#") eq_(Key.parse(note).transpose(1), parsed) _check_key_str_parse(parsed)
def _check_key_str_parse(key): eq_(key, Key.parse(key.text()))
def invalid_key_parse(key): ''' Helper for expenting to fail parses ''' Key.parse(key)
def _keys(): ''' Parse all valid keys ''' return [Key.parse(k) for k in _KEYS]
def key_eq_test(): ''' Check different parses of the same key are equal ''' for key in _KEYS: eq_(Key.parse(key), Key.parse(key))
import random from nose.tools import eq_ from chorddb.chords import Chord from chorddb.notes import Key __KEYS = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"] _KEYS = [Key.parse(k) for k in __KEYS] _VARIATIONS = ["m", "7", "m7", "maj7"] def _check_text_parsing(chord): eq_(Chord.parse(chord.text()), chord) def basic_chord_parse_test(): """ Parse chords with no variations """ for key in _KEYS: parsed = Chord.parse(key.text()) eq_(parsed.key, key) eq_(parsed.variation, None) eq_(parsed.bass, key) _check_text_parsing(parsed) def variation_chord_parse_test(): """ Parse chords with variations """ for key in _KEYS: for variation in _VARIATIONS: parsed = Chord.parse(key.text() + variation) eq_(parsed.key, key)