source: tests/python/template.py @ b14107f

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

tests/python/template.py: also print the command when failing

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[038852a]1import unittest
[874ed55]2from commands import getstatusoutput
[f603b57]3from numpy import array
[038852a]4
5class aubio_unit_template(unittest.TestCase):
[f603b57]6  """ a class derivated from unittest.TestCase """
[038852a]7 
8  def assertCloseEnough(self, first, second, places=5, msg=None):
[8987df1]9    """Fail if the two objects are unequal as determined by their
10       *relative* difference rounded to the given number of decimal places
11       (default 7) and comparing to zero.
12    """
13    if round(first, places) == 0:
14      if round(second-first, places) != 0:
15        raise self.failureException, \
16              (msg or '%r != %r within %r places' % (first, second, places))
17    else:
18      if round((second-first)/first, places) != 0:
19        raise self.failureException, \
20              (msg or '%r != %r within %r places' % (first, second, places))
[f603b57]21
[874ed55]22class program_test_case(unittest.TestCase):
23
24  filename = "/dev/null"
25  progname = "UNDEFINED"
26  command = ""
27  options = ""
28
29  def getOutput(self, expected_status = 0):
30    self.command = self.progname + ' -i ' + self.filename + self.command
31    self.command += self.options
32    [self.status, self.output] = getstatusoutput(self.command)
33    if expected_status != -1:
34      assert self.status == expected_status, \
[5f4fd2f]35        "expected status was %s, got %s\nOutput was:\n%s\n command was %s" % \
36        (expected_status, self.status, self.output, self.command)
[874ed55]37
[f603b57]38def array_from_text_file(filename, dtype = 'float'):
39  return array([line.split() for line in open(filename).readlines()], 
40      dtype = dtype)
Note: See TracBrowser for help on using the repository browser.