source: tests/python/examples/aubiopitch.py @ 1294862

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

examples/aubiopitch.py: also print line number and write output file if exception

  • Property mode set to 100644
File size: 2.4 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  progname = "PYTHONPATH=../../python:../../python/aubio/.libs " + \
48              os.path.join('..','..','python','aubiopitch')
49  options  = " -m yinfft -t 0.75 "
50
51  def test_aubiopitch(self):
52    """ test aubiopitch with default parameters """
53    self.getOutput()
54    expected_output = open(os.path.join('examples','aubiopitch','yinfft'+'.'+os.path.basename(self.filename)+'.txt')).read()
55    lines = 0
56    for line_out, line_exp in zip(self.output.split('\n'), expected_output.split('\n')):
57      try:
58        assert line_exp == line_out, line_exp + " vs. " + line_out + " at line " + str(lines)
59      except:
60        open(os.path.join('examples','aubiopitch','yinfft'+'.'+os.path.basename(self.filename)+'.txt.out'),'w').write(self.output)
61        raise
62      lines += 1
63
64if __name__ == '__main__': unittest.main()
Note: See TracBrowser for help on using the repository browser.