예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
def _check_key_str_parse(key):
    eq_(key, Key.parse(key.text()))
예제 #7
0
def invalid_key_parse(key):
    ''' Helper for expenting to fail parses '''
    Key.parse(key)
예제 #8
0
def _keys():
    ''' Parse all valid keys '''
    return [Key.parse(k) for k in _KEYS]
예제 #9
0
def key_eq_test():
    ''' Check different parses of the same key are equal '''
    for key in _KEYS:
        eq_(Key.parse(key), Key.parse(key))
예제 #10
0
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)