1 | import unittest |
---|
2 | from commands import getstatusoutput |
---|
3 | from numpy import array |
---|
4 | |
---|
5 | class 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 | |
---|
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, \ |
---|
35 | "expected status was %s, got %s\nOutput was:\n%s\n command was %s" % \ |
---|
36 | (expected_status, self.status, self.output, self.command) |
---|
37 | |
---|
38 | def array_from_text_file(filename, dtype = 'float'): |
---|
39 | return array([line.split() for line in open(filename).readlines()], |
---|
40 | dtype = dtype) |
---|