Skip to content

Commit

Permalink
Allow querying QualityManager supported qualities (yuma-m#74)
Browse files Browse the repository at this point in the history
This supports operations like scanning existing qualities and adding
some related (modified) versions of them.
  • Loading branch information
Jeremy Nickurak committed Dec 4, 2023
1 parent 44d3db5 commit dc1e748
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pychord/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def get_quality(self, name: str, inversion: int = 0) -> Quality:
q.components = q.components[1:] + (n,)
return q

def get_qualities(self):
return dict(self._qualities)

def set_quality(self, name: str, components: Tuple[int, ...]):
""" Set a Quality
Expand Down
23 changes: 23 additions & 0 deletions test/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,28 @@ def test_keep_existing_chord(self):
self.assertEqual(chord.components(), ['C', 'G', 'Bb', 'D', 'F'])


class TestIterateQualities(unittest.TestCase):
def setUp(self):
self.quality_manager = QualityManager()

def tearDown(self):
self.quality_manager.load_default_qualities()

def test_iterate_qualities(self):
assert 'm' in self.quality_manager.get_qualities()

def test_immutable_qualities(self):
qualities = self.quality_manager.get_qualities()
assert 'testquality' not in qualities
qualities['testquality'] = qualities['m']
qualities = self.quality_manager.get_qualities()
assert 'testquality' not in qualities

def test_iterate_added_qualities(self):
self.quality_manager.set_quality('testquality', (0))
qualities = self.quality_manager.get_qualities()
assert 'testquality' in qualities


if __name__ == '__main__':
unittest.main()

0 comments on commit dc1e748

Please sign in to comment.