source: tests/python/template.py @ 47f17fc

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

tests/python/template.py: factorise

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import unittest
2from commands import getstatusoutput
3from numpy import array
4
5class aubio_unit_template(unittest.TestCase):
6  """ a class derivated from unittest.TestCase """
7 
8  def assertCloseEnough(self, first, second, places=5, msg=None):
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))
21
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, \
35        "expected status was %s, got %s\nOutput was:\n%s" % \
36        (expected_status, self.status, self.output)
37
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.