def CheckHumdrumFile(hf: HumdrumFile, results: HumdrumFileTestResults):
    assert hf.lineCount == results.lineCount
    assert hf.maxTrack == results.maxTrack
    assert getTokenDataTypes(hf) == results.tokenDataTypes
    assert hf.tpq() == results.tpq
    assert hf.tpq(
    ) == results.tpq  # check it twice, for code coverage of "I already computed that" path

    if results.fileContentsUnmodified:
        if results.fileContents is None:
            assert str(hf) == ''
        else:
            assert str(hf) == results.fileContents

    for lineIdx, line in enumerate(hf.lines()):
        if results.fileContentsUnmodified:  # LATER: keep track of which lines not to check
            assert line.text == results.lines[lineIdx]
            assert str(line) == results.lines[
                lineIdx]  # test HumdrumLine.__str__
            assert hf[lineIdx].text == results.lines[
                lineIdx]  # test HumdrumFile.__getitem__
            assert [tok.text
                    for tok in line.tokens()] == results.tokens[lineIdx]

        assert line.lineNumber == results.lineNumbers[lineIdx]
        assert line.isExclusiveInterpretation == results.isExclusiveInterpretation[
            lineIdx]
        assert line.isManipulator == results.isManipulator[lineIdx]
        assert line.tokenCount == len(results.tokens[lineIdx])
def generateSpineInfoChanges(hf: HumdrumFile) -> dict:
    result = {}
    currSpineInfos: [str] = []
    for line in hf.lines():
        newSpineInfos = [token.spineInfo for token in line.tokens()]
        if newSpineInfos != currSpineInfos:
            result[str(line.lineNumber)] = newSpineInfos
            currSpineInfos = newSpineInfos
    return result
def generateTokenDataTypeChanges(hf: HumdrumFile) -> dict:
    result = {}
    currTokenDataTypes: [str] = []
    for line in hf.lines():
        newTokenDataTypes = [token.dataType.text for token in line.tokens()]
        if newTokenDataTypes != currTokenDataTypes:
            result[str(line.lineNumber)] = newTokenDataTypes
            currTokenDataTypes = newTokenDataTypes
    return result
Beispiel #4
0
def getTokenDataTypes(hf: HumdrumFile) -> [[str]]:
    #returns a '**blah' string for every token in every line in the file
    return [[token.dataType.text for token in line.tokens()] for line in hf.lines()]
def generateManipulatorLineNumbers(hf: HumdrumFile) -> list:
    result = []
    for line in hf.lines():
        if line.isManipulator:
            result.append(line.lineNumber)
    return result
def generateExclusiveInterpretationLineNumbers(hf: HumdrumFile) -> list:
    result = []
    for line in hf.lines():
        if line.isExclusiveInterpretation:
            result.append(line.lineNumber)
    return result
Beispiel #7
0
def test_HumdrumToken_global_param():
    hf = HumdrumFile()
    hf.readString(\
'''**kern
*M4/4
=1-
!!LO:CL:x=3
*clefG2
4c
4d
!!LO:N:vis=1:t=this is a colon::i
.
4e
!!LO:B:i
==
*-''')
    for lineIdx, line in enumerate(hf.lines()):
        #print('line: {}'.format(line.text))
        for tokenIdx, token in enumerate(line.tokens()):
            #print('line[{}]: {}'.format(tokenIdx, token))
            assert tokenIdx == 0 # this file has only one token per line

            if lineIdx == 0:
                # **kern
                CheckHumdrumToken(token,
                                  expectedText='**kern',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_INTERPRETATION,
                                  expectedSpecificType=SPECIFICTYPE_EXINTERP,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 1:
                # *M4/4
                CheckHumdrumToken(token,
                                  expectedText='*M4/4',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_INTERPRETATION,
                                  expectedSpecificType=SPECIFICTYPE_TIMESIGNATURE,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 2:
                # =1-
                CheckHumdrumToken(token,
                                  expectedText='=1-',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_BARLINE,
                                  expectedSpecificType=SPECIFICTYPE_NOTHINGSPECIFIC,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 3:
                # !!LO:CL:x=3
                CheckHumdrumToken(token,
                                  expectedText='!!LO:CL:x=3',
                                  expectedDataType='',
                                  expectedTokenType=TOKENTYPE_GLOBALCOMMENT,
                                  expectedSpecificType=SPECIFICTYPE_NOTHINGSPECIFIC,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 4:
                # *clefG2
                CheckHumdrumToken(token,
                                  expectedText='*clefG2',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_INTERPRETATION,
                                  expectedSpecificType=SPECIFICTYPE_CLEF,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 5:
                # 4c
                CheckHumdrumToken(token,
                                  expectedText='4c',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_DATA,
                                  expectedSpecificType=SPECIFICTYPE_NOTE,
                                  expectedDuration=1, # one quarter-note
                                  )
            elif lineIdx == 6:
                # 4d
                CheckHumdrumToken(token,
                                  expectedText='4d',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_DATA,
                                  expectedSpecificType=SPECIFICTYPE_NOTE,
                                  expectedDuration=1,
                                  )
            elif lineIdx == 7:
                # !!LO:N:vis=1:t=this is a colon::i
                CheckHumdrumToken(token,
                                  expectedText='!!LO:N:vis=1:t=this is a colon::i',
                                  expectedDataType='',
                                  expectedTokenType=TOKENTYPE_GLOBALCOMMENT,
                                  expectedSpecificType=SPECIFICTYPE_NOTHINGSPECIFIC,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 8:
                # .
                CheckHumdrumToken(token,
                                  expectedText='.',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_DATA,
                                  expectedSpecificType=SPECIFICTYPE_NULLDATA,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 9:
                # 4e
                CheckHumdrumToken(token,
                                  expectedText='4e',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_DATA,
                                  expectedSpecificType=SPECIFICTYPE_NOTE,
                                  expectedDuration=1,
                                  )
            elif lineIdx == 10:
                # !!LO:B:i
                CheckHumdrumToken(token,
                                  expectedText='!!LO:B:i',
                                  expectedDataType='',
                                  expectedTokenType=TOKENTYPE_GLOBALCOMMENT,
                                  expectedSpecificType=SPECIFICTYPE_NOTHINGSPECIFIC,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 11:
                # ==
                CheckHumdrumToken(token,
                                  expectedText='==',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_BARLINE,
                                  expectedSpecificType=SPECIFICTYPE_NOTHINGSPECIFIC,
                                  expectedDuration=-1,
                                  )
            elif lineIdx == 12:
                # *-
                CheckHumdrumToken(token,
                                  expectedText='*-',
                                  expectedDataType='**kern',
                                  expectedTokenType=TOKENTYPE_INTERPRETATION,
                                  expectedSpecificType=SPECIFICTYPE_TERMINATE,
                                  expectedDuration=-1,
                                  )
            else:
                assert False # too many lines in file!