~ubuntu-branches/ubuntu/oneiric/weave/oneiric

« back to all changes in this revision

Viewing changes to tools/scripts/runtests.py

  • Committer: Bazaar Package Importer
  • Author(s): Micah Gersten
  • Date: 2010-08-11 00:35:15 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100811003515-o3jbh826bnd1syjv
Tags: 1.4.3-1ubuntu1
* Add -fshort-wchar to CXXFLAGS to fix FTBFS in Ubuntu
  - update debian/rules 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
import sys
3
 
import difflib
4
 
import unittest
5
 
import subprocess
6
 
import distutils.file_util
7
 
 
8
 
import getnose
9
 
import nose.plugins
10
 
import nose.plugins.builtin
11
 
import makeloadertests
12
 
 
13
 
class JsTest(nose.plugins.Plugin):
14
 
    def options(self, parser, env=os.environ):
15
 
        nose.plugins.Plugin.options(self, parser, env)
16
 
        parser.add_option("--revalidate-logs", action="store_true",
17
 
                          dest="revalidate_logs",
18
 
                          default=False,
19
 
                          help="For all tests run, makes their logs "
20
 
                          "the expected, or canonical, log file to "
21
 
                          "which all future runs of the tests are "
22
 
                          "compared to.")
23
 
 
24
 
    def configure(self, options, config):
25
 
        nose.plugins.Plugin.configure(self, options, config)
26
 
        self.revalidate_logs = options.revalidate_logs
27
 
 
28
 
    def wantFile(self, file):
29
 
        basename = os.path.basename(file)
30
 
        ext = os.path.splitext(file)[1]
31
 
        if (basename.startswith("test_") and ext == ".js"):
32
 
            return True
33
 
        # Oddly enough, if we return 'False' here instead of 'None',
34
 
        # none of the other plugins get a chance to test the file.
35
 
        return None
36
 
 
37
 
    def loadTestsFromFile(self, filename):
38
 
        return [JsTestCase(filename, self.revalidate_logs)]
39
 
 
40
 
class JsTestCase(unittest.TestCase):
41
 
    def __init__(self, test, revalidate_logs):
42
 
        self.__test = test
43
 
        self.__revalidate_logs = revalidate_logs
44
 
        unittest.TestCase.__init__(self)
45
 
 
46
 
    def shortDescription(self):
47
 
        return os.path.basename(os.path.splitext(self.__test)[0])
48
 
 
49
 
    def runTest(self):
50
 
        test = self.__test
51
 
        dirname = os.path.dirname(test)
52
 
        testname = os.path.splitext(os.path.basename(test))[0]
53
 
        result = subprocess.call(
54
 
            ["make",
55
 
             "-C", dirname,
56
 
             "-f", "../harness/Makefile",
57
 
             testname],
58
 
            stdout = subprocess.PIPE,
59
 
            stderr = subprocess.STDOUT
60
 
            )
61
 
        logfile_name = os.path.join(dirname, testname + ".log")
62
 
        if result != 0:
63
 
            self.fail(open(logfile_name, "r").read())
64
 
        else:
65
 
            expected_logfile_name = logfile_name + ".expected"
66
 
            if self.__revalidate_logs:
67
 
                distutils.file_util.copy_file(logfile_name,
68
 
                                              expected_logfile_name)
69
 
            if os.path.exists(expected_logfile_name):
70
 
                expected = open(expected_logfile_name, "r").read()
71
 
                actual = open(logfile_name, "r").read()
72
 
                if expected != actual:
73
 
                    diff = "Expected results differ from actual results.\n\n"
74
 
                    diff += "\n".join(difflib.unified_diff(
75
 
                        expected.splitlines(), actual.splitlines(),
76
 
                        "expected results", "actual results"
77
 
                        ))
78
 
                    diff += ("\n\nIf you believe that these changes are valid "
79
 
                             "(i.e., that they don't represent malfunctioning "
80
 
                             "code), you may want to re-validate the expected "
81
 
                             "results by running the following command:\n\n")
82
 
                    diff += "python %s %s --revalidate-logs\n" % (
83
 
                        sys.argv[0],
84
 
                        self.__test
85
 
                        )
86
 
                    self.fail(diff)
87
 
 
88
 
if __name__ == "__main__":
89
 
    makeloadertests.remove_old_loader_tests()
90
 
    makeloadertests.make_loader_tests()
91
 
 
92
 
    sys.argv.append("--with-jstest")
93
 
    nose.main(defaultTest=["scripts",
94
 
                           "tests/unit",
95
 
                           "tests/system"],
96
 
              plugins=[JsTest()])