예제 #1
0
class JavaScriptTests(TestCase):
    """
    Tests for the JavaScript UnitTest runner, L{JavaScriptTestCase}.
    """
    def setUp(self):
        """
        Create a L{JavaScriptTestCase} and verify that its dependencies are
        present (otherwise, skip the test).
        """
        self.case = JavaScriptTestCase()
        try:
            self.case.checkDependencies()
        except NotSupported:
            raise SkipTest("Missing JS dependencies")


    def test_unsuccessfulExit(self):
        """
        Verify that an unsuccessful exit status results in an error.
        """
        result = TestResult()
        self.case.createSource = lambda testMethod: "throw new TypeError();"
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertTrue(
            result.errors[0][1].startswith(
                'Exception: JavaScript interpreter had error exit: '))


    def test_signalledExit(self):
        """
        An error should be reported if the JavaScript interpreter exits because
        it received a signal.
        """
        segfault = FilePath(__file__).sibling('segfault.py')

        def stubFinder():
            return sys.executable
        def stubScript(testModule):
            return segfault.path
        self.case.findJavascriptInterpreter = stubFinder
        self.case.makeScript = stubScript
        result = TestResult()
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertEquals(
            result.errors[0][1],
            'Exception: JavaScript interpreter exited due to signal 11\n')


    def test_missingJavaScriptClass(self):
        """
        If a JavaScript class required by the test code is unavailable, an
        error is added to the result object by L{JavaScriptTestCase.run}.
        """
        result = TestResult()
        self.case.testMethod = lambda: "Nevow.Test.NoSuchModule"
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
예제 #2
0
class JavaScriptTests(TestCase):
    """
    Tests for the JavaScript UnitTest runner, L{JavaScriptTestCase}.
    """
    def setUp(self):
        """
        Create a L{JavaScriptTestCase} and verify that its dependencies are
        present (otherwise, skip the test).
        """
        self.case = JavaScriptTestCase()
        try:
            self.case.checkDependencies()
        except NotSupported:
            raise SkipTest("Missing JS dependencies")


    def test_unsuccessfulExit(self):
        """
        Verify that an unsuccessful exit status results in an error.
        """
        result = TestResult()
        self.case.createSource = lambda testMethod: "throw new TypeError();"
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)


    def test_signalledExit(self):
        """
        An error should be reported if the JavaScript interpreter exits because
        it received a signal.
        """
        def stubFinder():
            return FilePath(__file__).sibling('segfault.py').path
        self.case.findJavascriptInterpreter = stubFinder
        self.case.createSource = lambda testMethod: ""
        result = TestResult()
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
예제 #3
0
class JavaScriptTests(TestCase):
    """
    Tests for the JavaScript UnitTest runner, L{JavaScriptTestCase}.
    """
    def setUp(self):
        """
        Create a L{JavaScriptTestCase} and verify that its dependencies are
        present (otherwise, skip the test).
        """
        self.case = JavaScriptTestCase()
        try:
            self.case.checkDependencies()
        except NotSupported:
            raise SkipTest("Missing JS dependencies")

    def test_unsuccessfulExit(self):
        """
        Verify that an unsuccessful exit status results in an error.
        """
        result = TestResult()
        self.case.createSource = lambda testMethod: "throw new TypeError();"
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertTrue(result.errors[0][1].startswith(
            'Exception: JavaScript interpreter had error exit: '))

    def test_signalledExit(self):
        """
        An error should be reported if the JavaScript interpreter exits because
        it received a signal.
        """
        segfault = FilePath(__file__).sibling('segfault.py')

        def stubFinder():
            return sys.executable

        def stubScript(testModule):
            return segfault.path

        self.case.findJavascriptInterpreter = stubFinder
        self.case.makeScript = stubScript
        result = TestResult()
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
        self.assertEquals(
            result.errors[0][1],
            'Exception: JavaScript interpreter exited due to signal 11\n')

    def test_missingJavaScriptClass(self):
        """
        If a JavaScript class required by the test code is unavailable, an
        error is added to the result object by L{JavaScriptTestCase.run}.
        """
        result = TestResult()
        self.case.testMethod = lambda: "Nevow.Test.NoSuchModule"
        self.case.run(result)
        self.assertEqual(len(result.errors), 1)
예제 #4
0
 def run(self, result):
     """
     Wrap L{JavaScriptTestCase.run} to change and restore the plugin environment
     on each test run.
     """
     base = ExampleTestBase()
     base.examplePath = self.examplePath
     try:
         base.setUp()
     except SkipTest as e:
         result.startTest(self)
         result.addSkip(self, str(e))
         result.stopTest(self)
     else:
         try:
             return JavaScriptTestCase.run(self, result)
         finally:
             base.tearDown()
예제 #5
0
 def run(self, result):
     """
     Wrap L{JavaScriptTestCase.run} to change and restore the plugin environment
     on each test run.
     """
     base = ExampleTestBase()
     base.examplePath = self.examplePath
     try:
         base.setUp()
     except SkipTest as e:
         result.startTest(self)
         result.addSkip(self, str(e))
         result.stopTest(self)
     else:
         try:
             return JavaScriptTestCase.run(self, result)
         finally:
             base.tearDown()
예제 #6
0
    def run(self, result):
        """
        Wrap L{JavaScriptTestCase.run} to change and restore the plugin environment
        on each test run.
        """
        base = ExampleTestBase()
        base.examplePath = self.examplePath
        try:
            base.setUp()
        except SkipTest, e:
            result.startTest(self)
            result.addSkip(self, str(e))
            result.stopTest(self)
        else:
            try:
                return JavaScriptTestCase.run(self, result)
            finally:
                base.tearDown()


def chatListing(partname):
    """
    Return a list of strings that represents a path from the root of the Nevow
    source package which contains a potential PYTHONPATH entry with some
    listing code in it, based on which part of the chat tutorial it came from.
    """
    return ['doc', 'howto', 'chattutorial', 'part'+partname, 'listings']



class Part00Tests(ExampleJavaScriptTestCase):