def create_quality(self, notation, capital_note=True): """Create a `Quality`. Create a `Quality` from its notation and whether the `root` of the `Chord` was uppercase. Parameters ---------- notation : str The `Quality`'s notation. *capital_note : boolean, Optional Selector for the case of the `root` of the `Chord`. Default True when optional. Returns ------- Quality The created `Quality`. Examples -------- >>> QE = QualityEditor() >>> QE.create_quality("sus4") sus4 quality >>> QE.create_quality("maj7") major seventh quality """ if notation is None: if capital_note: return Quality("major") return Quality("minor") rgx = re.match(QualityEditor.quality_pattern, notation, re.UNICODE) if rgx.group(2): # power return Quality("power") alt5 = self._parse_alt5(rgx.group(20)) quality_str = self._parse_base(rgx, alt5, capital_note) ext_str = self._parse_ext(rgx, alt5, capital_note) flat_ext = self._parse_flat_ext(rgx.group(13)) return Quality(quality_str, ext_str, flat_ext)
def test_sym_base(quality, ext, sym): q = Quality(quality, ext) assert sym == q.base_symbols
def test_sym(quality, ext, sym): q = Quality(quality, ext) assert sym == q.symbols
def test_degree(quality, ext, degree): q = Quality(quality, ext) assert degree == q.degrees
def test_check_major(): with pytest.raises(ValueError): Quality("major", "seventh")
def test_interval(quality, ext, interval): q = Quality(quality, ext) assert interval == q.intervals
def test_check_diminished(): with pytest.raises(ValueError): Quality("diminished", "seventh")
def test_short_halfdim(): q = Quality("half-diminished", "eleventh") assert "m11\u266d5" == str(q)
def test_check_flat_sevenths(): with pytest.raises(ValueError): Quality("major", "major seventh", True)
def test_check_diminished_2(): with pytest.raises(ValueError): Quality("minor", "diminished seventh")
def test_equality(): q1 = Quality("major", "major seventh") q2 = Quality("major", "major seventh") assert q1 == q2
def test_equality_not_implemented(): q = Quality("major") assert q != len
def test_str(): q = Quality("major", "major seventh") assert "maj7" == str(q)
def test_long_repr_with_flat_ext(quality, ext, name): q = Quality(quality, ext, True) assert name + " quality" == repr(q)
def test_long_repr(quality, name): q = Quality(quality) assert name + " quality" == repr(q)
def test_short(): q = Quality("diminished") assert "dim" == str(q)
def test_short_flat(): q = Quality("minor", "ninth", True) assert "m\u266d9" == str(q)
def test_base_interval(quality, interval): q = Quality(quality) assert interval == q.base_intervals
def test_short_sus(): q = Quality("sus4", "seventh") assert "7sus" == str(q)
def test_base_degree(quality, degree): q = Quality(quality) assert degree == q.base_degrees