Example #1
0
    def test_single_test(self):
        '''a single test should output TapAssertion and TapTast'''

        parser = TapParser(TapTest)
        output = '''
# test: should be defined
ok 1
        '''

        for item in parser.parse(output):
            print item.display()
Example #2
0
    def test_single_module(self):
        '''Should parse a module and its children'''
        parser = TapParser(TapAssertion)
        output = '''
# module: This is a module
# test: should be defined
ok 1
        '''

        items = list(parser.parse(output.splitlines()))

        self.assertIsInstance(items[0], TapModule)
        self.assertIsInstance(items[1], TapTest)
        self.assertIsInstance(items[2], TapAssertion)
Example #3
0
    def test_single_test(self):
        '''Should parse a test and its children'''
        parser = TapParser(TapAssertion)
        output = '''
# test: should be defined
ok 1
not ok 2
        '''

        items = list(parser.parse(output.splitlines()))

        self.assertIsInstance(items[0], TapTest)
        self.assertIsInstance(items[1], TapAssertion)
        self.assertIsInstance(items[2], TapAssertion)
Example #4
0
    def test_single_module(self):
        '''Should parse a module and its children'''
        parser = TapParser(TapAssertion)
        output = '''
# module: This is a module
# test: should be defined
ok 1
        '''

        items = list(parser.parse(output.splitlines()))

        self.assertIsInstance(items[0], TapModule)
        self.assertIsInstance(items[1], TapTest)
        self.assertIsInstance(items[2], TapAssertion)
Example #5
0
    def test_single_test(self):
        '''Should parse a test and its children'''
        parser = TapParser(TapAssertion)
        output = '''
# test: should be defined
ok 1
not ok 2
        '''

        items = list(parser.parse(output.splitlines()))

        self.assertIsInstance(items[0], TapTest)
        self.assertIsInstance(items[1], TapAssertion)
        self.assertIsInstance(items[2], TapAssertion)
Example #6
0
    def phantomjs(self, *args, **kwargs):
        '''
        Execute PhantomJS by giving ``args`` as command line arguments.

        If test are run in verbose mode (``-v/--verbosity`` = 2), it output:
          - the title as header (with separators before and after)
          - modules and test names
          - assertions results (with ``django.utils.termcolors`` support)

        In case of error, a JsTestException is raised to give details about javascript errors.
        '''
        separator = '=' * LINE_SIZE
        title = kwargs['title'] if 'title' in kwargs else 'phantomjs output'
        nb_spaces = (LINE_SIZE - len(title)) // 2

        if VERBOSE:
            print('')
            print(separator)
            print(' ' * nb_spaces + title)
            print(separator)
            sys.stdout.flush()

        with NamedTemporaryFile(delete=True) as cookies_file:
            cmd = ('node_modules/.bin/phantomjs',
                   '--cookies-file=%s' % cookies_file.name) + args

            print('cmd!!!!!', cmd)
            if self.timeout:
                cmd += (str(self.timeout), )
            parser = TapParser(debug=VERBOSITY > 2)
            output = self.execute(cmd)

            for item in parser.parse(output):
                if VERBOSE:
                    print(item.display())
                    sys.stdout.flush()

        if VERBOSE:
            print(separator)
            sys.stdout.flush()

        failures = parser.suites.get_all_failures()
        if failures:
            raise JsTestException('Failed javascript assertions', failures)
        if self.returncode > 0:
            raise JsTestException(
                'PhantomJS return with non-zero exit code (%s)' %
                self.returncode)
Example #7
0
    def phantomjs(self, *args, **kwargs):
        '''
        Execute PhantomJS by giving ``args`` as command line arguments.

        If test are run in verbose mode (``-v/--verbosity`` = 2), it output:
          - the title as header (with separators before and after)
          - modules and test names
          - assertions results (with ``django.utils.termcolors`` support)

        In case of error, a JsTestException is raised to give details about javascript errors.
        '''
        separator = '=' * LINE_SIZE
        title = kwargs['title'] if 'title' in kwargs else 'phantomjs output'
        nb_spaces = (LINE_SIZE - len(title)) // 2

        if VERBOSE:
            print('')
            print(separator)
            print(' ' * nb_spaces + title)
            print(separator)
            sys.stdout.flush()

        with NamedTemporaryFile(delete=True) as cookies_file:
            cmd = ('phantomjs', '--cookies-file=%s' % cookies_file.name) + args
            if self.timeout:
                cmd += (str(self.timeout),)
            parser = TapParser(debug=VERBOSITY > 2)
            output = self.execute(cmd)

            for item in parser.parse(output):
                if VERBOSE:
                    print(item.display())
                    sys.stdout.flush()

        if VERBOSE:
            print(separator)
            sys.stdout.flush()

        failures = parser.suites.get_all_failures()
        if failures:
            raise JsTestException('Failed javascript assertions', failures)
        if self.returncode > 0:
            raise JsTestException('PhantomJS return with non-zero exit code (%s)' % self.returncode)