Skip to content

Commit 34921cf

Browse files
committed
Add doctests to test suites and fix them
1 parent e0d7c3b commit 34921cf

13 files changed

Lines changed: 80 additions & 44 deletions

File tree

mingus/core/chords.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def dominant_flat_ninth(note):
396396
"""Build a dominant flat ninth chord on note.
397397
398398
Example:
399-
>>> dominant_ninth('C')
399+
>>> dominant_flat_ninth('C')
400400
['C', 'E', 'G', 'Bb', 'Db']
401401
"""
402402
res = dominant_ninth(note)
@@ -408,7 +408,7 @@ def dominant_sharp_ninth(note):
408408
"""Build a dominant sharp ninth chord on note.
409409
410410
Example:
411-
>>> dominant_ninth('C')
411+
>>> dominant_sharp_ninth('C')
412412
['C', 'E', 'G', 'Bb', 'D#']
413413
"""
414414
res = dominant_ninth(note)
@@ -953,11 +953,11 @@ def determine_triad(triad, shorthand=False, no_inversions=False, placeholder=Non
953953
954954
Examples:
955955
>>> determine_triad(['A', 'C', 'E'])
956-
'A minor triad'
956+
['A minor triad', 'C major sixth, second inversion']
957957
>>> determine_triad(['C', 'E', 'A'])
958-
'A minor triad, first inversion'
958+
['C major sixth', 'A minor triad, first inversion']
959959
>>> determine_triad(['A', 'C', 'E'], True)
960-
'Am'
960+
['Am', 'CM6']
961961
"""
962962
if len(triad) != 3:
963963
# warning: raise exception: not a triad
@@ -1031,7 +1031,7 @@ def determine_seventh(
10311031
10321032
Example:
10331033
>>> determine_seventh(['C', 'E', 'G', 'B'])
1034-
['C major seventh']
1034+
['C major seventh', 'Em|CM']
10351035
"""
10361036
if len(seventh) != 4:
10371037
# warning raise exception: seventh chord is not a seventh chord

mingus/core/intervals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def unison(note, key=None):
6666
>>> unison('C')
6767
'C'
6868
"""
69-
return interval(key, note, 0)
69+
return interval(note, note, 0)
7070

7171

7272
def second(note, key):

mingus/core/meter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def is_compound(meter):
5555
5656
Examples:
5757
>>> is_compound((3,4))
58-
True
58+
False
5959
>>> is_compound((4,4))
6060
False
61+
>>> is_compound((6,8))
62+
True
6163
"""
6264
return is_valid(meter) and meter[0] % 3 == 0 and 6 <= meter[0]
6365

mingus/core/value.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
# mingus - Music theory Python package, value module.
42
# Copyright (C) 2008-2009, Bart Spaans, Javier Palanca
53
#
@@ -36,7 +34,7 @@
3634
3735
Medieval backwards compatibility privided.
3836
"""
39-
from __future__ import absolute_import
37+
from __future__ import absolute_import, division
4038
from six.moves import range
4139

4240
longa = 0.25
@@ -156,12 +154,12 @@ def dots(value, nr=1):
156154
thirty second notes.
157155
158156
Examples:
159-
>>> dots(eighth)
160-
5.3333333333333333
161-
>>> dots(eighth, 2)
162-
4.5714285714285712
163-
>>> dots(quarter)
164-
2.6666666666666665
157+
>>> round(dots(eighth), 6)
158+
5.333333
159+
>>> round(dots(eighth, 2), 6)
160+
4.571429
161+
>>> round(dots(quarter), 6)
162+
2.666667
165163
"""
166164
return (0.5 * value) / (1.0 - 0.5 ** (nr + 1))
167165

@@ -174,9 +172,9 @@ def triplet(value):
174172
175173
Examples:
176174
>>> triplet(eighth)
177-
12
175+
12.0
178176
>>> triplet(4)
179-
6
177+
6.0
180178
"""
181179
return tuplet(value, 3, 2)
182180

@@ -189,9 +187,9 @@ def quintuplet(value):
189187
190188
Examples:
191189
>>> quintuplet(8)
192-
10
190+
10.0
193191
>>> quintuplet(4)
194-
5
192+
5.0
195193
"""
196194
return tuplet(value, 5, 4)
197195

@@ -211,9 +209,9 @@ def septuplet(value, in_fourths=True):
211209
212210
Examples:
213211
>>> septuplet(8)
214-
14
212+
14.0
215213
>>> septuplet(8, False)
216-
7
214+
7.0
217215
"""
218216
if in_fourths:
219217
return tuplet(value, 7, 4)
@@ -231,7 +229,7 @@ def tuplet(value, rat1, rat2):
231229
232230
Example:
233231
>>> tuplet(8, 3, 2)
234-
12
232+
12.0
235233
"""
236234
return (rat1 * value) / float(rat2)
237235

tests/unit/containers/test_note.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import absolute_import
33

4+
import doctest
45
import unittest
56

7+
import mingus.containers.note
68
from mingus.containers.mt_exceptions import NoteFormatError
79
from mingus.containers.note import Note
810

@@ -136,3 +138,8 @@ def test_invalid_velocity(self):
136138
Note("A", 4, {"velocity": 200})
137139
with self.assertRaises(ValueError):
138140
Note("A", 4, {"velocity": -1})
141+
142+
143+
def load_tests(loader, tests, ignore):
144+
tests.addTests(doctest.DocTestSuite(mingus.containers.note))
145+
return tests

tests/unit/containers/test_track.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
from __future__ import absolute_import
32

3+
import doctest
44
import unittest
55

6+
import mingus.containers.track
67
from mingus.containers.instrument import Instrument, Piano, Guitar
78
from mingus.containers.track import Track
89

@@ -26,3 +27,8 @@ def test_transpose(self):
2627
s + "E"
2728
s + "G#"
2829
self.assertEqual(s, t)
30+
31+
32+
def load_tests(loader, tests, ignore):
33+
tests.addTests(doctest.DocTestSuite(mingus.containers.note))
34+
return tests

tests/unit/core/test_chords.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from __future__ import absolute_import
22

3-
# -*- coding: utf-8 -*-
4-
import sys
3+
import doctest
4+
import unittest
55

6-
sys.path = ["../"] + sys.path
76
import mingus.core.chords as chords
8-
from mingus.core.mt_exceptions import RangeError, FormatError, NoteFormatError
9-
import unittest
7+
from mingus.core.mt_exceptions import FormatError, NoteFormatError
108

119

1210
class test_chords(unittest.TestCase):
@@ -468,3 +466,8 @@ def test_determine_polychord(self):
468466
lambda x: chords.determine_polychords(x, True),
469467
"polychord naming",
470468
)
469+
470+
471+
def load_tests(loader, tests, ignore):
472+
tests.addTests(doctest.DocTestSuite(chords))
473+
return tests

tests/unit/core/test_intervals.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
from __future__ import absolute_import
32

3+
import doctest
44
import unittest
55

66
import mingus.core.intervals as intervals
@@ -394,3 +394,8 @@ def test_is_dissonant(self):
394394
self.assertTrue(intervals.is_dissonant("C", "F#"))
395395
self.assertTrue(intervals.is_dissonant("C", "Bb"))
396396
self.assertTrue(intervals.is_dissonant("C", "B"))
397+
398+
399+
def load_tests(loader, tests, ignore):
400+
tests.addTests(doctest.DocTestSuite(intervals))
401+
return tests

tests/unit/core/test_keys.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
from __future__ import absolute_import
32

3+
import doctest
44
import unittest
55

66
import mingus.core.keys as keys
@@ -68,3 +68,8 @@ def test_relative_minor(self):
6868
"The minor of %s is not %s, expecting %s"
6969
% (k, keys.relative_minor(k), known[k]),
7070
)
71+
72+
73+
def load_tests(loader, tests, ignore):
74+
tests.addTests(doctest.DocTestSuite(keys))
75+
return tests

tests/unit/core/test_meter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# -*- coding: utf-8 -*-
21
from __future__ import absolute_import
32

3+
import doctest
44
import unittest
55

66
from six.moves import range
@@ -95,3 +95,8 @@ def test_is_asymmetrical(self):
9595

9696
def test_is_full(self):
9797
pass
98+
99+
100+
def load_tests(loader, tests, ignore):
101+
tests.addTests(doctest.DocTestSuite(meter))
102+
return tests

0 commit comments

Comments
 (0)