Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved the tests uit to a module.

Except for the script.
  • Loading branch information...
commit 534f0ccc5722812e90fe75f2f27aeee18a34951d 1 parent e3421b1
@Neppord Neppord authored
View
12 run_unit.py
@@ -1,5 +1,11 @@
-import tests
-import test
+#! python
+import testtools.tests
+import testtools.runner
import unittest
-unittest.main(tests, testRunner=test.Py2JsTestRunner(verbosity=2), exit=False, verbosity=2, buffer=True)
+unittest.main(
+ testtools.tests,
+ testRunner=testtools.runner.Py2JsTestRunner(verbosity=2),
+ exit=False,
+ verbosity=2
+ )
View
56 testtools/runner.py
@@ -0,0 +1,56 @@
+import unittest
+
+class Py2JsTestResult(unittest.TestResult):
+ """Test result class handeling all the results reported by the tests"""
+
+ def __init__(self, *a, **k):
+ import testtools.writer
+ super(Py2JsTestResult, self).__init__(*a, **k)
+ self.__writer = testtools.writer.Writer(a[0])
+ self.__faild = False
+ self.__color = ""
+ self.__state = ""
+
+ def startTest(self, test):
+ super(Py2JsTestResult, self).startTest(test)
+ test.reportProgres = self.addProgress
+ self.__writer.write(str(test))
+ self.__state = "[Error]"
+ self.__color = "Red"
+
+ def stopTest(self, test):
+ super(Py2JsTestResult, self).stopTest(test)
+ self.__writer.write(self.__state, align="right", color=self.__color)
+
+ def addProgress(self):
+ """Part of tests done"""
+ self.__writer.write(".")
+
+ def addSuccess(self, test):
+ super(Py2JsTestResult, self).addSuccess(test)
+ self.__color = "Green"
+ self.__state = "[OK]"
+
+ def addUnexpectedSuccess(self, test):
+ super(Py2JsTestResult, self).addUnexpectedSuccess(test)
+ self.__color = "Green"
+ self.__state = "should fail but [OK]"
+
+ def addExpectedFailure(self, test, err):
+ super(Py2JsTestResult, self).addExpectedFailure(test, err)
+ self.__color = "Purple"
+ self.__state = "known to [FAIL]"
+
+ def addFailure(self, test, err):
+ super(Py2JsTestResult, self).addFailure(test, err)
+ self.__color = "Red"
+ self.__state = "[FAIL]"
+
+ def stopTestRun(self):
+ super(Py2JsTestResult, self).stopTestRun()
+ self.__writer.write("\n")
+
+class Py2JsTestRunner(unittest.TextTestRunner):
+ """Test runner with Py2JsTestResult as result class"""
+ resultclass = Py2JsTestResult
+
View
12 tests.py → testtools/tests.py
@@ -1,8 +1,10 @@
"""module which findes tests from the test directory and convert them to
the unittest framwork classes."""
-import test
+
+import testtools.util as util
import glob
import os
+
KNOWN_TO_FAIL = [
"tests/basic/nestedclass.py",
"tests/basic/super.py",
@@ -69,14 +71,14 @@ def create_cases():
test_paths.sort()
for test_path in test_paths:
test_cases.append(
- test.compile_file_test(test_path, os.path.basename(test_path))
+ util.compile_file_test(test_path, os.path.basename(test_path))
)
test_paths = glob.glob("tests/test_*.js")
test_paths.sort()
for test_path in test_paths:
test_cases.append(
- test.run_with_stdlib(test_path, os.path.basename(test_path))
+ util.run_with_stdlib(test_path, os.path.basename(test_path))
)
@@ -85,14 +87,14 @@ def create_cases():
for test_path in test_paths:
if test_path.replace("\\","/") not in KNOWN_TO_FAIL:
test_cases.append(
- test.compile_and_run_file_test(
+ util.compile_and_run_file_test(
test_path,
os.path.basename(test_path)
)
)
else:
test_cases.append(
- test.compile_and_run_file_failing_test(
+ util.compile_and_run_file_failing_test(
test_path,
os.path.basename(test_path)
)
View
66 test.py → testtools/util.py
@@ -4,59 +4,15 @@
"""
import unittest
import os
-class Py2JsTestResult(unittest.TestResult):
- """Test result class handeling all the results reported by the tests"""
-
- def __init__(self, *a, **k):
- import testtools.writer
- super(Py2JsTestResult, self).__init__(*a, **k)
- self.__writer = testtools.writer.Writer(a[0])
- self.__faild = False
- self.__color = ""
- self.__state = ""
-
- def startTest(self, test):
- super(Py2JsTestResult, self).startTest(test)
- test.reportProgres = self.addProgress
- self.__writer.write(str(test))
- self.__state = "[Error]"
- self.__color = "Red"
-
- def stopTest(self, test):
- super(Py2JsTestResult, self).stopTest(test)
- self.__writer.write(self.__state, align="right", color=self.__color)
-
- def addProgress(self):
- """Part of tests done"""
- self.__writer.write(".")
-
- def addSuccess(self, test):
- super(Py2JsTestResult, self).addSuccess(test)
- self.__color = "Green"
- self.__state = "[OK]"
-
- def addUnexpectedSuccess(self, test):
- super(Py2JsTestResult, self).addUnexpectedSuccess(test)
- self.__color = "Green"
- self.__state = "should fail but [OK]"
-
- def addExpectedFailure(self, test, err):
- super(Py2JsTestResult, self).addExpectedFailure(test, err)
- self.__color = "Purple"
- self.__state = "known to [FAIL]"
-
- def addFailure(self, test, err):
- super(Py2JsTestResult, self).addFailure(test, err)
- self.__color = "Red"
- self.__state = "[FAIL]"
-
- def stopTestRun(self):
- super(Py2JsTestResult, self).stopTestRun()
- self.__writer.write("\n")
+import posixpath
-class Py2JsTestRunner(unittest.TextTestRunner):
- """Test runner with Py2JsTestResult as result class"""
- resultclass = Py2JsTestResult
+def get_posix_path(path):
+ heads = []
+ tail = path
+ while tail!='':
+ tail, head = os.path.split(tail)
+ heads.append(head)
+ return posixpath.join(*heads[::-1])
def run_with_stdlib(file_path, file_name=None):
"""Creats a test that runs a js file with the stdlib."""
@@ -66,7 +22,7 @@ class TestStdLib(unittest.TestCase):
"""Tests js code with the stdlib"""
templ = {
"js_path": file_path,
- "js_unix_path": file_path,
+ "js_unix_path": get_posix_path(file_path),
"js_out_path": file_path + ".out",
"js_error": file_path + ".err",
"name": file_name,
@@ -96,7 +52,7 @@ class CompileFile(unittest.TestCase):
templ = {
"py_path": file_path,
- "py_unix_path": file_path,
+ "py_unix_path": get_posix_path(file_path),
"py_out_path": file_path + ".out",
"py_error": file_path + ".err",
"name": file_name,
@@ -130,7 +86,7 @@ class CompileAndRunFile(unittest.TestCase):
"""Tests that a file can be compiled and run as js"""
templ = {
"py_path": file_path,
- "py_unix_path": file_path,
+ "py_unix_path": get_posix_path(file_path),
"py_out_path": file_path + ".out",
"js_path": file_path + ".js",
"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.