source: python.old/tests_examples/aubiopitch.py @ 5158c22

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 5158c22 was bea5389, checked in by Paul Brossier <piem@piem.org>, 12 years ago

moved old python stuff out of tests/

  • Property mode set to 100644
File size: 2.7 KB
Line 
1from template import *
2
3import os.path
4
5class aubiopitch_test_case(program_test_case):
6
7  import os.path
8  filename = os.path.join('..','..','sounds','woodblock.aiff')
9  progname = "PYTHONPATH=../../python:../../python/aubio/.libs " + \
10              os.path.join('..','..','python','aubiopitch')
11
12  def test_aubiopitch(self):
13    """ test aubiopitch with default parameters """
14    self.getOutput()
15    # FIXME: useless check
16    self.assertEqual(len(self.output.split('\n')), 1)
17    #self.assertEqual(float(self.output.strip()), 0.)
18
19  def test_aubiopitch_verbose(self):
20    """ test aubiopitch with -v parameter """
21    self.command += " -v "
22    self.getOutput()
23    # FIXME: loose checking: make sure at least 8 lines are printed
24    assert len(self.output) >= 8
25
26  def test_aubiopitch_devnull(self):
27    """ test aubiopitch on /dev/null """
28    self.filename = "/dev/null"
29    # exit status should not be 0
30    self.getOutput(expected_status = 256)
31    # and there should be an error message
32    assert len(self.output) > 0
33    # that looks like this
34    output_lines = self.output.split('\n')
35    #assert output_lines[0] == "Unable to open input file /dev/null."
36    #assert output_lines[1] == "Supported file format but file is malformed."
37    #assert output_lines[2] == "Could not open input file /dev/null."
38
39mode_names = ["yinfft", "yin", "fcomb", "mcomb", "schmitt"]
40for name in mode_names:
41  exec("class aubiopitch_test_case_" + name + "(aubiopitch_test_case):\n\
42    options = \" -m " + name + " \"")
43
44class aubiopitch_test_yinfft(program_test_case):
45
46  filename = os.path.join('..','..','sounds','16568__acclivity__TwoCows.wav')
47  url = "http://www.freesound.org/samplesViewSingle.php?id=16568"
48  progname = "PYTHONPATH=../../python:../../python/aubio/.libs " + \
49              os.path.join('..','..','python','aubiopitch')
50  options  = " -m yinfft -t 0.75 "
51
52  def test_aubiopitch(self):
53    """ test aubiopitch with default parameters """
54    if not os.path.isfile(self.filename):
55      print "Warning: file 16568_acclivity_TwoCows.wav was not found in %s" % os.path.dirname(self.filename) 
56      print "download it from %s to actually run test" % url
57      return
58    self.getOutput()
59    expected_output = open(os.path.join('examples','aubiopitch','yinfft'+'.'+os.path.basename(self.filename)+'.txt')).read()
60    lines = 0
61    for line_out, line_exp in zip(self.output.split('\n'), expected_output.split('\n')):
62      try:
63        assert line_exp == line_out, line_exp + " vs. " + line_out + " at line " + str(lines)
64      except:
65        open(os.path.join('examples','aubiopitch','yinfft'+'.'+os.path.basename(self.filename)+'.txt.out'),'w').write(self.output)
66        raise
67      lines += 1
68
69if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.