[038852a] | 1 | import unittest |
---|
[874ed55] | 2 | from commands import getstatusoutput |
---|
[f603b57] | 3 | from numpy import array |
---|
[038852a] | 4 | |
---|
| 5 | class 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] | 22 | class 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] | 38 | def array_from_text_file(filename, dtype = 'float'): |
---|
| 39 | return array([line.split() for line in open(filename).readlines()], |
---|
| 40 | dtype = dtype) |
---|