<commit_before># -*- coding: utf-8 -*-

import logging
logging.basicConfig(level=logging.INFO)
import unittest
import sys

import exceptions
from webdriverwrapper import Firefox
from errors import get_error_page, get_error_messages

__all__ = (
    'WebdriverTestCase',
    'ONE_INSTANCE_FOR_ALL_TESTS',
    'ONE_INSTANCE_PER_TESTCASE',
    'ONE_INSTANCE_PER_TEST',
)


ONE_INSTANCE_FOR_ALL_TESTS = 0
ONE_INSTANCE_PER_TESTCASE = 1
ONE_INSTANCE_PER_TEST = 2


class WebdriverTestCase(unittest.TestCase):
    domain = None
    instances_of_driver = ONE_INSTANCE_FOR_ALL_TESTS
    wait_after_test = False

    def __init__(self, *args, **kwds):
        super(WebdriverTestCase, self).__init__(*args, **kwds)
        self.__class__._number_of_test = 0
        self.__class__._count_of_tests = len(filter(lambda m: m.startswith('test'), dir(self)))
        self.init()

    def init(self):
        pass

    def run(self, result=None):
        if result is None:
            result = self.defaultTestResult()
        result.startTest(self)
        test_method = getattr(self, self._testMethodName)
        self._test_method = test_method
        try:
            self._set_up()

            try:
                self.setUp()
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())
                return

            ok = False
            try:
                test_method()
                ok = True
            except self.failureException:
                result.addFailure(self, sys.exc_info())
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())

            try:
                self._check_errors()
            except:
                ok = False
                result.addError(self, sys.exc_info())

            try:
                self.tearDown()
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())
                ok = False

            if ok:
                result.addSuccess(self)

            # Is nice to see at break point if test passed or not.
            # So this call have to be after all addError/addSuccess calls.
            self._tear_down()
        finally:
            result.stopTest(self)

    def _set_up(self):
        self.__class__._number_of_test += 1
        if not hasattr(WebdriverTestCase, 'driver'):<commit_msg>If setUp fails, check for errors<commit_after># -*- coding: utf-8 -*-

import logging
logging.basicConfig(level=logging.INFO)
import unittest
import sys

import exceptions
from webdriverwrapper import Firefox
from errors import get_error_page, get_error_messages

__all__ = (
    'WebdriverTestCase',
    'ONE_INSTANCE_FOR_ALL_TESTS',
    'ONE_INSTANCE_PER_TESTCASE',
    'ONE_INSTANCE_PER_TEST',
)


ONE_INSTANCE_FOR_ALL_TESTS = 0
ONE_INSTANCE_PER_TESTCASE = 1
ONE_INSTANCE_PER_TEST = 2


class WebdriverTestCase(unittest.TestCase):
    domain = None
    instances_of_driver = ONE_INSTANCE_FOR_ALL_TESTS
    wait_after_test = False

    def __init__(self, *args, **kwds):
        super(WebdriverTestCase, self).__init__(*args, **kwds)
        self.__class__._number_of_test = 0
        self.__class__._count_of_tests = len(filter(lambda m: m.startswith('test'), dir(self)))
        self.init()

    def init(self):
        pass

    def run(self, result=None):
        if result is None:
            result = self.defaultTestResult()
        result.startTest(self)
        test_method = getattr(self, self._testMethodName)
        self._test_method = test_method
        try:
            self._set_up()

            try:
                self.setUp()
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())
                #  setUp can fail because of app in some state returns internal
                #+ server error. It's good to know about it - it can say more
                #+ than that some element couldn't be found.
                try:
                    self._check_errors()
                except:
                    result.addError(self, sys.exc_info())
                return

            ok = False
            try:
                test_method()
                ok = True
            except self.failureException:
                result.addFailure(self, sys.exc_info())
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())

            try:
                self._check_errors()
            except:
                ok = False
                result.addError(self, sys.exc_info())

            try:
                self.tearDown()
            except KeyboardInterrupt:
                raise
            except:
                result.addError(self, sys.exc_info())
                ok = False

            if ok:
                result.addSuccess(self)
        finally:
            result.stopTest(self)
            # Is nice to see at break point if test passed or not.
            # So this call have to be after stopTest which print result of test.
            self._tear_down()

    def _set_up(self):
        self.__class__._number_of_test += 1
        if not hasattr(WebdriverTestCase, 'driver'):
{'fraction_non_alphanumeric': 0.07940354147250699, 'fraction_numerical': 0.0022367194780987883, 'mean_word_length': 1.7363590005099439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4124660', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1462, 'n_words': 348}