Skip to content
This repository
Browse code

Moved the tests uit to a module.

Except for the script.
  • Loading branch information...
commit 534f0ccc5722812e90fe75f2f27aeee18a34951d 1 parent e3421b1
Samuel Ytterbrink Neppord authored
12 run_unit.py
... ... @@ -1,5 +1,11 @@
1   -import tests
2   -import test
  1 +#! python
  2 +import testtools.tests
  3 +import testtools.runner
3 4 import unittest
4 5
5   -unittest.main(tests, testRunner=test.Py2JsTestRunner(verbosity=2), exit=False, verbosity=2, buffer=True)
  6 +unittest.main(
  7 + testtools.tests,
  8 + testRunner=testtools.runner.Py2JsTestRunner(verbosity=2),
  9 + exit=False,
  10 + verbosity=2
  11 + )
56 testtools/runner.py
... ... @@ -0,0 +1,56 @@
  1 +import unittest
  2 +
  3 +class Py2JsTestResult(unittest.TestResult):
  4 + """Test result class handeling all the results reported by the tests"""
  5 +
  6 + def __init__(self, *a, **k):
  7 + import testtools.writer
  8 + super(Py2JsTestResult, self).__init__(*a, **k)
  9 + self.__writer = testtools.writer.Writer(a[0])
  10 + self.__faild = False
  11 + self.__color = ""
  12 + self.__state = ""
  13 +
  14 + def startTest(self, test):
  15 + super(Py2JsTestResult, self).startTest(test)
  16 + test.reportProgres = self.addProgress
  17 + self.__writer.write(str(test))
  18 + self.__state = "[Error]"
  19 + self.__color = "Red"
  20 +
  21 + def stopTest(self, test):
  22 + super(Py2JsTestResult, self).stopTest(test)
  23 + self.__writer.write(self.__state, align="right", color=self.__color)
  24 +
  25 + def addProgress(self):
  26 + """Part of tests done"""
  27 + self.__writer.write(".")
  28 +
  29 + def addSuccess(self, test):
  30 + super(Py2JsTestResult, self).addSuccess(test)
  31 + self.__color = "Green"
  32 + self.__state = "[OK]"
  33 +
  34 + def addUnexpectedSuccess(self, test):
  35 + super(Py2JsTestResult, self).addUnexpectedSuccess(test)
  36 + self.__color = "Green"
  37 + self.__state = "should fail but [OK]"
  38 +
  39 + def addExpectedFailure(self, test, err):
  40 + super(Py2JsTestResult, self).addExpectedFailure(test, err)
  41 + self.__color = "Purple"
  42 + self.__state = "known to [FAIL]"
  43 +
  44 + def addFailure(self, test, err):
  45 + super(Py2JsTestResult, self).addFailure(test, err)
  46 + self.__color = "Red"
  47 + self.__state = "[FAIL]"
  48 +
  49 + def stopTestRun(self):
  50 + super(Py2JsTestResult, self).stopTestRun()
  51 + self.__writer.write("\n")
  52 +
  53 +class Py2JsTestRunner(unittest.TextTestRunner):
  54 + """Test runner with Py2JsTestResult as result class"""
  55 + resultclass = Py2JsTestResult
  56 +
12 tests.py → testtools/tests.py
... ... @@ -1,8 +1,10 @@
1 1 """module which findes tests from the test directory and convert them to
2 2 the unittest framwork classes."""
3   -import test
  3 +
  4 +import testtools.util as util
4 5 import glob
5 6 import os
  7 +
6 8 KNOWN_TO_FAIL = [
7 9 "tests/basic/nestedclass.py",
8 10 "tests/basic/super.py",
@@ -69,14 +71,14 @@ def create_cases():
69 71 test_paths.sort()
70 72 for test_path in test_paths:
71 73 test_cases.append(
72   - test.compile_file_test(test_path, os.path.basename(test_path))
  74 + util.compile_file_test(test_path, os.path.basename(test_path))
73 75 )
74 76
75 77 test_paths = glob.glob("tests/test_*.js")
76 78 test_paths.sort()
77 79 for test_path in test_paths:
78 80 test_cases.append(
79   - test.run_with_stdlib(test_path, os.path.basename(test_path))
  81 + util.run_with_stdlib(test_path, os.path.basename(test_path))
80 82 )
81 83
82 84
@@ -85,14 +87,14 @@ def create_cases():
85 87 for test_path in test_paths:
86 88 if test_path.replace("\\","/") not in KNOWN_TO_FAIL:
87 89 test_cases.append(
88   - test.compile_and_run_file_test(
  90 + util.compile_and_run_file_test(
89 91 test_path,
90 92 os.path.basename(test_path)
91 93 )
92 94 )
93 95 else:
94 96 test_cases.append(
95   - test.compile_and_run_file_failing_test(
  97 + util.compile_and_run_file_failing_test(
96 98 test_path,
97 99 os.path.basename(test_path)
98 100 )
66 test.py → testtools/util.py
@@ -4,59 +4,15 @@
4 4 """
5 5 import unittest
6 6 import os
7   -class Py2JsTestResult(unittest.TestResult):
8   - """Test result class handeling all the results reported by the tests"""
9   -
10   - def __init__(self, *a, **k):
11   - import testtools.writer
12   - super(Py2JsTestResult, self).__init__(*a, **k)
13   - self.__writer = testtools.writer.Writer(a[0])
14   - self.__faild = False
15   - self.__color = ""
16   - self.__state = ""
17   -
18   - def startTest(self, test):
19   - super(Py2JsTestResult, self).startTest(test)
20   - test.reportProgres = self.addProgress
21   - self.__writer.write(str(test))
22   - self.__state = "[Error]"
23   - self.__color = "Red"
24   -
25   - def stopTest(self, test):
26   - super(Py2JsTestResult, self).stopTest(test)
27   - self.__writer.write(self.__state, align="right", color=self.__color)
28   -
29   - def addProgress(self):
30   - """Part of tests done"""
31   - self.__writer.write(".")
32   -
33   - def addSuccess(self, test):
34   - super(Py2JsTestResult, self).addSuccess(test)
35   - self.__color = "Green"
36   - self.__state = "[OK]"
37   -
38   - def addUnexpectedSuccess(self, test):
39   - super(Py2JsTestResult, self).addUnexpectedSuccess(test)
40   - self.__color = "Green"
41   - self.__state = "should fail but [OK]"
42   -
43   - def addExpectedFailure(self, test, err):
44   - super(Py2JsTestResult, self).addExpectedFailure(test, err)
45   - self.__color = "Purple"
46   - self.__state = "known to [FAIL]"
47   -
48   - def addFailure(self, test, err):
49   - super(Py2JsTestResult, self).addFailure(test, err)
50   - self.__color = "Red"
51   - self.__state = "[FAIL]"
52   -
53   - def stopTestRun(self):
54   - super(Py2JsTestResult, self).stopTestRun()
55   - self.__writer.write("\n")
  7 +import posixpath
56 8
57   -class Py2JsTestRunner(unittest.TextTestRunner):
58   - """Test runner with Py2JsTestResult as result class"""
59   - resultclass = Py2JsTestResult
  9 +def get_posix_path(path):
  10 + heads = []
  11 + tail = path
  12 + while tail!='':
  13 + tail, head = os.path.split(tail)
  14 + heads.append(head)
  15 + return posixpath.join(*heads[::-1])
60 16
61 17 def run_with_stdlib(file_path, file_name=None):
62 18 """Creats a test that runs a js file with the stdlib."""
@@ -66,7 +22,7 @@ class TestStdLib(unittest.TestCase):
66 22 """Tests js code with the stdlib"""
67 23 templ = {
68 24 "js_path": file_path,
69   - "js_unix_path": file_path,
  25 + "js_unix_path": get_posix_path(file_path),
70 26 "js_out_path": file_path + ".out",
71 27 "js_error": file_path + ".err",
72 28 "name": file_name,
@@ -96,7 +52,7 @@ class CompileFile(unittest.TestCase):
96 52
97 53 templ = {
98 54 "py_path": file_path,
99   - "py_unix_path": file_path,
  55 + "py_unix_path": get_posix_path(file_path),
100 56 "py_out_path": file_path + ".out",
101 57 "py_error": file_path + ".err",
102 58 "name": file_name,
@@ -130,7 +86,7 @@ class CompileAndRunFile(unittest.TestCase):
130 86 """Tests that a file can be compiled and run as js"""
131 87 templ = {
132 88 "py_path": file_path,
133   - "py_unix_path": file_path,
  89 + "py_unix_path": get_posix_path(file_path),
134 90 "py_out_path": file_path + ".out",
135 91 "js_path": file_path + ".js",
136 92 "js_out_path": file_path + ".js.out",

0 comments on commit 534f0cc

Please sign in to comment.
Something went wrong with that request. Please try again.