Skip to content

Commit

Permalink
music21objects must instantiate w/o defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Oct 12, 2022
1 parent d123bcc commit 6cf1a0d
Show file tree
Hide file tree
Showing 22 changed files with 118 additions and 72 deletions.
3 changes: 3 additions & 0 deletions music21/abcFormat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3439,6 +3439,9 @@ def readstr(self, strSrc: str, number: int | None = None) -> ABCHandler:

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testTokenization(self):
from music21.abcFormat import testFiles
Expand Down
4 changes: 4 additions & 0 deletions music21/alpha/analysis/fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ def __init__(self, changes, midiStream, omrStream):
super().__init__(changes, midiStream, omrStream, recognizer)

class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def measuresEqual(self, m1, m2):
'''
Returns a tuple of (True/False, reason)
Expand Down
3 changes: 3 additions & 0 deletions music21/alpha/analysis/hasher.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,9 @@ def __new__(cls, tupEls):


class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def _approximatelyEqual(self, a, b, sig_fig=2):
'''
Expand Down
4 changes: 4 additions & 0 deletions music21/alpha/analysis/ornamentRecognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ def __init__(
self.isInverted = isInverted

class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testRecognizeTurn(self):
# set up experiment
testConditions = []
Expand Down
3 changes: 3 additions & 0 deletions music21/alpha/analysis/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def findConsecutiveScale(source, targetScale, degreesRequired=5,

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testFindConsecutiveScaleA(self):
sc = scale.MajorScale('a4')
Expand Down
3 changes: 3 additions & 0 deletions music21/analysis/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,9 @@ def analysisClassFromMethodName(method: str) -> type[DiscreteAnalysis] | None:


class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testKeyAnalysisKrumhansl(self):
from music21 import converter
Expand Down
3 changes: 3 additions & 0 deletions music21/analysis/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,9 @@ def getGraphHorizontalBarWeightedData(self):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testExtractionA(self):
from music21 import analysis
Expand Down
3 changes: 3 additions & 0 deletions music21/analysis/transposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def getPitchesOfDistinctTranspositions(self):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testConstructTranspositionChecker(self):
p = [pitch.Pitch('D#')]
Expand Down
3 changes: 3 additions & 0 deletions music21/analysis/windowed.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ def process(self, subStream):


class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testBasic(self):
from music21 import corpus
Expand Down
3 changes: 3 additions & 0 deletions music21/articulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,9 @@ class HandbellIndication(TechnicalIndication):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testBasic(self):
a = FretBend()
Expand Down
3 changes: 3 additions & 0 deletions music21/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ def getTextExpression(self, prefix='', postfix='x'):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testSortOrder(self):
from music21 import stream
Expand Down
4 changes: 3 additions & 1 deletion music21/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ def setByNumber(self, number, type, direction=None): # type is okay @ReservedAs


class Test(unittest.TestCase):
pass
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())


# -----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion music21/braille/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class BrailleExplicitNoteExtraSmaller(BrailleExplicitNoteLength):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
pass
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())


if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion music21/features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,6 @@ def getIndex(featureString, extractorType=None):
class Test(unittest.TestCase):

def testStreamFormsA(self):

from music21 import features
self.maxDiff = None

Expand Down
109 changes: 53 additions & 56 deletions music21/humdrum/spineParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ def insertGlobalEvents(self):
Insert the Global Events (GlobalReferenceLines and GlobalCommentLines) into an appropriate
place in the outer Stream.
Run after self.spineCollection.createMusic21Streams().
Is run automatically by self.parse().
uses self.spineCollection.getOffsetsAndPrioritiesByPosition()
Expand Down Expand Up @@ -737,31 +736,31 @@ def insertGlobalEvents(self):
if appendList:
self.stream.coreElementsChanged()

# @property
# def stream(self):
# if self._storedStream is not None:
# return self._storedStream
# if self.parsedLines is False:
# self.parse()
#
# if self.spineCollection is None:
# raise HumdrumException('parsing got no spine collections!')
# elif self.spineCollection.spines is None:
# raise HumdrumException('not a single spine in your data... um, not my problem! ' +
# '(well, maybe it is...file a bug report if you ' +
# 'have doubled checked your data)')
# elif self.spineCollection.spines[0].stream is None:
# raise HumdrumException('okay, you got at least one spine, but it ain\'t got ' +
# 'a stream in it; (check your data or file a bug report)')
# else:
# masterStream = stream.Score()
# for thisSpine in self.spineCollection:
# thisSpine.stream.id = 'spine_' + str(thisSpine.id)
# for thisSpine in self.spineCollection:
# if thisSpine.parentSpine is None and thisSpine.spineType == 'kern':
# masterStream.insert(thisSpine.stream)
# self._storedStream = masterStream
# return masterStream
# @property
# def stream(self):
# if self._storedStream is not None:
# return self._storedStream
# if self.parsedLines is False:
# self.parse()
#
# if self.spineCollection is None:
# raise HumdrumException('parsing got no spine collections!')
# elif self.spineCollection.spines is None:
# raise HumdrumException('not a single spine in your data... um, not my problem! ' +
# '(well, maybe it is...file a bug report if you ' +
# 'have doubled checked your data)')
# elif self.spineCollection.spines[0].stream is None:
# raise HumdrumException('okay, you got at least one spine, but it ain\'t got ' +
# 'a stream in it; (check your data or file a bug report)')
# else:
# masterStream = stream.Score()
# for thisSpine in self.spineCollection:
# thisSpine.stream.id = 'spine_' + str(thisSpine.id)
# for thisSpine in self.spineCollection:
# if thisSpine.parentSpine is None and thisSpine.spineType == 'kern':
# masterStream.insert(thisSpine.stream)
# self._storedStream = masterStream
# return masterStream

def parseMetadata(self, s=None):
'''
Expand Down Expand Up @@ -2499,7 +2498,6 @@ def kernTandemToObject(tandem):
This method converts them to music21 objects.
>>> m = humdrum.spineParser.kernTandemToObject('*M3/1')
>>> m
<music21.meter.TimeSignature 3/1>
Expand Down Expand Up @@ -2619,8 +2617,8 @@ def kernTandemToObject(tandem):


class MiscTandem(base.Music21Object):
def __init__(self, tandem=''):
super().__init__()
def __init__(self, tandem='', **keywords):
super().__init__(**keywords)
self.tandem = tandem

def _reprInternal(self):
Expand All @@ -2631,16 +2629,14 @@ class SpineComment(base.Music21Object):
'''
A Music21Object that represents a comment in a single spine.
>>> sc = humdrum.spineParser.SpineComment('! this is a spine comment')
>>> sc
<music21.humdrum.spineParser.SpineComment 'this is a spine comment'>
>>> sc.comment
'this is a spine comment'
'''

def __init__(self, comment=''):
super().__init__()
def __init__(self, comment='', **keywords):
super().__init__(**keywords)
commentPart = re.sub(r'^!+\s?', '', comment)
self.comment = commentPart

Expand All @@ -2652,16 +2648,14 @@ class GlobalComment(base.Music21Object):
'''
A Music21Object that represents a comment for the whole score
>>> sc = humdrum.spineParser.GlobalComment('!! this is a global comment')
>>> sc
<music21.humdrum.spineParser.GlobalComment 'this is a global comment'>
>>> sc.comment
'this is a global comment'
'''

def __init__(self, comment=''):
super().__init__()
def __init__(self, comment='', **keywords):
super().__init__(**keywords)
commentPart = re.sub(r'^!!+\s?', '', comment)
commentPart = commentPart.strip()
self.comment = commentPart
Expand Down Expand Up @@ -2713,8 +2707,8 @@ class GlobalReference(base.Music21Object):
False
'''

def __init__(self, codeOrAll='', valueOrNone=None):
super().__init__()
def __init__(self, codeOrAll='', valueOrNone=None, **keywords):
super().__init__(**keywords)
codeOrAll = re.sub(r'^!!!+', '', codeOrAll)
codeOrAll = codeOrAll.strip()
if valueOrNone is None and ':' in codeOrAll:
Expand Down Expand Up @@ -2816,7 +2810,7 @@ def __init__(self, codeOrAll='', valueOrNone=None):
'EED': 'electronicEditor', # electronic editor
'ENC': 'electronicEncoder', # electronic encoder (person)
'END': '', # encoding date
'EMD': '', # electronic document modification description (one per modificiation)
'EMD': '', # electronic document modification description (one per modification)
'EEV': '', # electronic edition version
'EFL': '', # file number e.g. '1/4' for one of four
'EST': '', # encoding status (free form, normally eliminated prior to distribution)
Expand Down Expand Up @@ -2864,29 +2858,32 @@ def _reprInternal(self):


class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def testLoadMazurka(self):
# hf1 = HumdrumFile('d:/web/eclipse/music21misc/mazurka06-2.krn')

hf1 = HumdrumDataCollection(testFiles.mazurka6)
hf1.parse()

# hf1 = HumdrumFile('d:/web/eclipse/music21misc/ojibway.krn')
# for thisEventCollection in hf1.eventCollections:
# ev = thisEventCollection.getSpineEvent(0).contents
# if ev is not None:
# print(ev)
# else:
# print('NONE')

# for mySpine in hf1.spineCollection:
# print('\n\n***NEW SPINE: No. ' + str(mySpine.id) + ' parentSpine: '
# + str(mySpine.parentSpine) + ' childSpines: ' + str(mySpine.childSpines))
# print(mySpine.spineType)
# for childSpinesSpine in mySpine.childSpinesSpines():
# print(str(childSpinesSpine.id) + ' *** testing spineCollection code ***')
# for thisEvent in mySpine:
# print(thisEvent.contents)
# hf1 = HumdrumFile('d:/web/eclipse/music21misc/ojibway.krn')
# for thisEventCollection in hf1.eventCollections:
# ev = thisEventCollection.getSpineEvent(0).contents
# if ev is not None:
# print(ev)
# else:
# print('NONE')
#
# for mySpine in hf1.spineCollection:
# print('\n\n***NEW SPINE: No. ' + str(mySpine.id) + ' parentSpine: '
# + str(mySpine.parentSpine) + ' childSpines: ' + str(mySpine.childSpines))
# print(mySpine.spineType)
# for childSpinesSpine in mySpine.childSpinesSpines():
# print(str(childSpinesSpine.id) + ' *** testing spineCollection code ***')
# for thisEvent in mySpine:
# print(thisEvent.contents)
spine5 = hf1.spineCollection.getSpineById(5)
self.assertEqual(spine5.id, 5)
self.assertEqual(spine5.parentSpine.id, 1)
Expand Down
4 changes: 4 additions & 0 deletions music21/prebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ def _reprInternal(self) -> str:


class Test(unittest.TestCase):
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def test_reprInternal(self):
from music21.base import Music21Object
b = Music21Object()
Expand Down
4 changes: 2 additions & 2 deletions music21/romanText/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ class RomanTextUnprocessedToken(base.ElementWrapper):


class RomanTextUnprocessedMetadata(base.Music21Object):
def __init__(self, tag='', data=''):
super().__init__()
def __init__(self, tag='', data='', **keywords):
super().__init__(**keywords)
self.tag = tag
self.data = data

Expand Down
4 changes: 2 additions & 2 deletions music21/search/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ class ContiguousSegmentOfNotes(base.Music21Object):
_DOC_ORDER = ['startMeasureNumber', 'startOffset', 'zeroCenteredTransformationsFromMatched',
'originalCenteredTransformationsFromMatched']

def __init__(self, segment=None, containerStream=None, partNumber=0):
super().__init__()
def __init__(self, segment=None, containerStream=None, partNumber=0, **keywords):
super().__init__(**keywords)
self.segment = segment
self.containerStream = containerStream
self.partNumber = partNumber
Expand Down
4 changes: 4 additions & 0 deletions music21/spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,10 @@ def setUp(self):
from music21.musicxml.m21ToXml import GeneralObjectExporter
self.GEX = GeneralObjectExporter()

def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())

def xmlStr(self, obj):
xmlBytes = self.GEX.parse(obj)
return xmlBytes.decode('utf-8')
Expand Down
4 changes: 3 additions & 1 deletion music21/test/commonTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ def testCopyAll(testInstance: unittest.TestCase, globals_: typing.Dict[str, typi

try: # see if obj can be made w/o args
instance = obj()
except TypeError:
except TypeError as te:
if issubclass(obj, music21.base.Music21Object):
raise TypeError('Define Music21Objects to be instantiated without initial args')
continue

try:
Expand Down
4 changes: 3 additions & 1 deletion music21/tie.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ def _reprInternal(self):


class Test(unittest.TestCase):
pass
def testCopyAndDeepcopy(self):
from music21.test.commonTest import testCopyAll
testCopyAll(self, globals())


# ------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6cf1a0d

Please sign in to comment.