def run(self, runWithEnviron=True): ''' Main code runner for testing. To set a new test, update the self.callTest attribute in __init__(). Note that the default of runWithEnviron imports music21.environment. That might skew results ''' suffix = '.svg' outputFormat = suffix[1:] _MOD = "test.timeGraphs.py" if runWithEnviron: from music21 import environment environLocal = environment.Environment(_MOD) fp = environLocal.getTempFile(suffix) # manually get a temporary file else: import tempfile import os import sys if os.name in ['nt'] or sys.platform.startswith('win'): platform = 'win' else: platform = 'other' tempdir = os.path.join(tempfile.gettempdir(), 'music21') if platform != 'win': fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix) if isinstance(fd, int): # on MacOS, fd returns an int, like 3, when this is called # in some context (specifically, programmatically in a # TestExternal class. the fp is still valid and works # TODO: this did not work on MacOS 10.6.8 w/ py 2.7 pass else: fd.close() else: tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix) fp = tf.name tf.close() if self.includeList is not None: gf = pycallgraph.GlobbingFilter(include=self.includeList, exclude=self.excludeList) else: gf = pycallgraph.GlobbingFilter(exclude=self.excludeList) # create instance; will call setup routines ct = self.callTest() # start timer print('%s starting test' % _MOD) t = Timer() t.start() pycallgraph.start_trace(filter_func=gf) ct.testFocus() # run routine pycallgraph.stop_trace() pycallgraph.make_dot_graph(fp, format=outputFormat, tool='/usr/local/bin/dot') print('elapsed time: %s' % t) # open the completed file print('file path: ' + fp) try: environLocal = environment.Environment(_MOD) environLocal.launch(outputFormat, fp) except NameError: pass
def run(self, runWithEnviron=True): ''' Main code runner for testing. To set a new test, update the self.callTest attribute in __init__(). Note that the default of runWithEnviron imports music21.environment. That might skew results ''' suffix = '.png' # '.svg' outputFormat = suffix[1:] _MOD = "test.timeGraphs.py" if runWithEnviron: from music21 import environment environLocal = environment.Environment(_MOD) fp = environLocal.getTempFile(suffix) # manually get a temporary file else: import tempfile import os import sys if os.name in ['nt'] or sys.platform.startswith('win'): platform = 'win' else: platform = 'other' tempdir = os.path.join(tempfile.gettempdir(), 'music21') if platform != 'win': fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix) if isinstance(fd, int): # on MacOS, fd returns an int, like 3, when this is called # in some context (specifically, programmatically in a # TestExternal class. the fp is still valid and works # TODO: this did not work on MacOS 10.6.8 w/ py 2.7 pass else: fd.close() else: tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix) fp = tf.name tf.close() if self.includeList is not None: gf = pycallgraph.GlobbingFilter(include=self.includeList, exclude=self.excludeList) else: gf = pycallgraph.GlobbingFilter(exclude=self.excludeList) # create instance; will call setup routines ct = self.callTest() # start timer print('%s starting test' % _MOD) t = Timer() t.start() graphviz = pycallgraph.output.GraphvizOutput(output_file=fp) graphviz.tool = '/usr/local/bin/dot' config = pycallgraph.Config() config.trace_filter = gf from music21 import meter from music21 import note #from music21 import converter #from music21 import common #beeth = common.getCorpusFilePath() + '/beethoven/opus133.mxl' #s = converter.parse(beeth, forceSource=True) #beeth = common.getCorpusFilePath() + '/bach/bwv66.6.mxl' #s = converter.parse(beeth, forceSource=True) with pycallgraph.PyCallGraph(output=graphviz, config=config): note.Note() meter.TimeSignature('4/4') ct.testFocus() # run routine pass print('elapsed time: %s' % t) # open the completed file print('file path: ' + fp) try: environLocal = environment.Environment(_MOD) environLocal.launch(outputFormat, fp) except NameError: pass
def run(self, runWithEnviron=True): ''' Main code runner for testing. To set a new test, update the self.callTest attribute in __init__(). Note that the default of runWithEnviron imports music21.environment. That might skew results ''' from music21 import environment suffix = '.png' # '.svg' outputFormat = suffix[1:] _MOD = "test.timeGraphs" if runWithEnviron: environLocal = environment.Environment(_MOD) fp = environLocal.getTempFile(suffix) # manually get a temporary file else: import tempfile import os import sys if os.name in ['nt'] or sys.platform.startswith('win'): platform = 'win' else: platform = 'other' tempdir = os.path.join(tempfile.gettempdir(), 'music21') if platform != 'win': fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix) if isinstance(fd, int): # on MacOS, fd returns an int, like 3, when this is called # in some context (specifically, programmatically in a # TestExternal class. the fp is still valid and works # TODO: this did not work on MacOS 10.6.8 w/ py 2.7 pass else: fd.close() else: tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix) fp = tf.name tf.close() if self.includeList is not None: gf = pycallgraph.GlobbingFilter(include=self.includeList, exclude=self.excludeList) else: gf = pycallgraph.GlobbingFilter(exclude=self.excludeList) # create instance; will call setup routines ct = self.callTest() # start timer print('%s starting test' % _MOD) t = Timer() t.start() graphviz = pycallgraph.output.GraphvizOutput(output_file=fp) graphviz.tool = '/usr/local/bin/dot' config = pycallgraph.Config() config.trace_filter = gf from music21 import meter from music21 import note #from music21 import converter #from music21 import common #beeth = common.getCorpusFilePath() + '/beethoven/opus133.mxl' #s = converter.parse(beeth, forceSource=True) #beeth = common.getCorpusFilePath() + '/bach/bwv66.6.mxl' #s = converter.parse(beeth, forceSource=True) with pycallgraph.PyCallGraph(output=graphviz, config=config): note.Note() meter.TimeSignature('4/4') ct.testFocus() # run routine pass print('elapsed time: %s' % t) # open the completed file print('file path: ' + fp) try: environLocal = environment.Environment(_MOD) environLocal.launch(outputFormat, fp) except NameError: pass
def run(self, runWithEnviron=True): ''' Main code runner for testing. To set a new test, update the self.callTest attribute in __init__(). Note that the default of runWithEnviron imports music21.environment. That might skew results ''' suffix = '.svg' outputFormat = suffix[1:] _MOD = "test.timeGraphs.py" if runWithEnviron: from music21 import environment environLocal = environment.Environment(_MOD) fp = environLocal.getTempFile(suffix) # manually get a temporary file else: import tempfile import os import sys if os.name in ['nt'] or sys.platform.startswith('win'): platform = 'win' else: platform = 'other' tempdir = os.path.join(tempfile.gettempdir(), 'music21') if platform != 'win': fd, fp = tempfile.mkstemp(dir=tempdir, suffix=suffix) if isinstance(fd, int): # on MacOS, fd returns an int, like 3, when this is called # in some context (specifically, programmatically in a # TestExternal class. the fp is still valid and works # TODO: this did not work on MacOS 10.6.8 w/ py 2.7 pass else: fd.close() else: tf = tempfile.NamedTemporaryFile(dir=tempdir, suffix=suffix) fp = tf.name tf.close() if self.includeList is not None: gf = pycallgraph.GlobbingFilter(include=self.includeList, exclude=self.excludeList) else: gf = pycallgraph.GlobbingFilter(exclude=self.excludeList) # create instance; will call setup routines ct = self.callTest() # start timer print('%s starting test' % _MOD) t = Timer() t.start() pycallgraph.start_trace(filter_func = gf) ct.testFocus() # run routine pycallgraph.stop_trace() pycallgraph.make_dot_graph(fp, format=outputFormat, tool='/usr/local/bin/dot') print('elapsed time: %s' % t) # open the completed file print('file path: ' + fp) try: environLocal = environment.Environment(_MOD) environLocal.launch(outputFormat, fp) except NameError: pass