class ModuleUnitTestRunner(SimpleRpcLogicBase):
    def __post_init__(self):
        self.twins_manager = TwinModulesManager(self.context)
        self.file_manager = FileManager(self.context)
        self.nodejs = NodeJsRunner(self.context)

    def runTestByNumber(self, package, test_number):
        tests_dict = self._getTestDict()
        sorted_names = self.__getSortedNames(tests_dict)
        new_dict = dict((module.__name__, class_) for module, class_ in tests_dict.items())
        tester_class = new_dict[sorted_names[test_number]]
        self.runPythonTest(tester_class)

    def __runUnitTest(self, tester_class):
        tester_class.setTestsContext(self.context)
        suite = TestLoader().loadTestsFromTestCase(tester_class)
        TextTestRunner().run(suite)

    def runPythonTest(self, tested_class):
        tester_class = self.twins_manager.getTesterFromTested(tested_class)
        path = self.file_manager.formatClassFilePath(tester_class)
        name = tester_class.__name__
        self.log.d('Running %r test at:\n %s' % (name, path))
        #self.module_unit_test_runner.runPythonTest(tester_class)
        self.__runUnitTest(tester_class)

    def runJsTest(self, tested_class):
        file_path = self.twins_manager.getJsUnittest(tested_class)
        path = self.file_manager.formatFilePath(file_path)
        self.log.d('Running jasmine test at:\n%s' % path)
        ret_val = self.nodejs.runJasmineTest(file_path)
        if ret_val:
            raise SimpleRpcError('Jasmine test failed')
Пример #2
0
class ExposedTestBase(SimpleRpcLogicBase):
    tests_context = None

    @staticmethod
    def setTestsContext(context):
        ExposedTestBase.tests_context = context

    def __init__(self, first_arg=None):
        #Initialize the class if inheriting from TestCase
        if isinstance(self, TestCase): #If using unittest, then initialize the class
            #Keep signature
            if isinstance(first_arg, str):
                methodName = first_arg
                first_arg = None
                TestCase.__init__(self, methodName)
            else:
                TestCase.__init__(self)

        context = first_arg
        #Solve context if not provided
        if context == None:
            if ExposedTestBase.tests_context == None: #To enable context free initialization supporting unittest.TestCase
                self.__runs_from_tested_module = False
                ExposedTestBase.tests_context = SimpleRpcContext(self.__class__.__name__)
            else:
                self.__runs_from_tested_module = True
            context = ExposedTestBase.tests_context
        SimpleRpcLogicBase.__init__(self, context)

    def __post_init__(self):
        self.twins_manager = TwinModulesManager(self.context)
        self.module_unit_test_runner = ModuleUnitTestRunner(self.context)
        self.file_manager = FileManager(self.context)

    def runTest(self):
        pass

    def __printTestedClassFile(self, tested_class):
        path = self.file_manager.formatClassFilePath(tested_class)
        name = tested_class.__name__
        self.log.d('Testing %r at:\n %s' % (name, path))

    def testJsJasmine(self):
        tested_class = self._getTestedClass()
        self.module_unit_test_runner.runJsTest(tested_class)

    def testMethodsExistence(self):
        tested_class = self._getTestedClass()
        if not self.__runs_from_tested_module:
            self.__printTestedClassFile(tested_class)
        #tested_instance =
        for name, attrib in tested_class.__dict__.items():
            if callable(attrib) and not name.startswith('_'):
                test_name = 'test_%s' % name
                msg = 'There is no test test_%s for class %r' % (name, tested_class)
                assert test_name in self.__class__.__dict__, msg
                #assert callable(self.__class__.__dict__[test_name]) #TODO: necessary?

    def _getTestedClass(self):
        return self.twins_manager.getTestedFromTester(self.__class__)
 def __post_init__(self):
     self.twins_manager = TwinModulesManager(self.context)
     self.file_manager = FileManager(self.context)
     self.nodejs = NodeJsRunner(self.context)
Пример #4
0
 def __post_init__(self):
     self.twins_manager = TwinModulesManager(self.context)
     self.module_unit_test_runner = ModuleUnitTestRunner(self.context)
     self.file_manager = FileManager(self.context)