Exemplo n.º 1
0
 def test_isTestMoudle(self):
     """
     isTestMoudle returns True if the given module name has '.test.' in it.
     """
     self.assertTrue(isTestModule("twisted.test.test_dict"))
     self.assertTrue(isTestModule("twisted.python.test.test_util"))
     self.assertFalse(isTestModule("twisted.python.hook"))
Exemplo n.º 2
0
 def test_isTestMoudle(self):
     """
     isTestMoudle returns True if the given module name has '.test.' in it.
     """
     self.assertTrue(isTestModule("twisted.test.test_dict"))
     self.assertTrue(isTestModule("twisted.python.test.test_util"))
     self.assertFalse(isTestModule("twisted.test.iosim"))
     self.assertFalse(isTestModule("twisted.python.hook"))
Exemplo n.º 3
0
    def visit_module(self, node):
        """
        A interface will be called when visiting a module.

        @param node: node of current module
        """
        modulename = node.name.split(".")[-1]
        if isTestModule(node.name) and self.moduleContainsTestCase(node):
            self._checkTestModuleName(modulename, node)
Exemplo n.º 4
0
    def visit_module(self, node):
        """
        A interface will be called when visiting a module.

        @param node: node of current module
        """
        modulename = node.name.split(".")[-1]
        if isTestModule(node.name) and self.moduleContainsTestCase(node):
            self._checkTestModuleName(modulename, node)
Exemplo n.º 5
0
    def visit_module(self, node):
        """
        A interface will be called when visiting a module.

        @param node: node of current module
        """
        if not node.file_stream:
            # failed to open the module
            return
        text = node.file_stream.read()
        self._checkCopyright(text, node)
        if not isTestModule(node.name) and moduleNeedsTests:
            self._checkTestReference(text, node)
Exemplo n.º 6
0
    def visit_module(self, node):
        """
        A interface will be called when visiting a module.

        @param node: node of current module
        """
        if not node.file_stream:
            # failed to open the module
            return
        text = node.file_stream.read()
        self._checkCopyright(text, node)
        if not isTestModule(node.name) and moduleNeedsTests:
            self._checkTestReference(text, node)
Exemplo n.º 7
0
    def visit_module(self, node):
        """
        Called when the AST checker visits a module.

        @param node: node of current module
        """
        if not isTestModule(node.name):
            return
        objects = list(node.values())
        objects.sort(key=operator.attrgetter('lineno'))
        for obj in objects:
            if (isinstance(obj, ClassDef) and self._isTestClass(obj)
                    and not obj.name.endswith('Tests')):
                self.add_message('W9701', line=obj.lineno, node=obj)
Exemplo n.º 8
0
    def visit_module(self, node):
        """
        Called when the AST checker visits a module.

        @param node: node of current module
        """
        if not isTestModule(node.name):
            return

        objects = node.values()
        objects.sort(key=operator.attrgetter("lineno"))
        for obj in objects:
            if isinstance(obj, Class) and self._isTestClass(obj) and not obj.name.endswith("Tests"):
                self.add_message("W9701", line=obj.lineno)
Exemplo n.º 9
0
    def visit_module(self, node):
        """
        Called when the AST checker visits a module.

        @param node: node of current module
        """
        if not isTestModule(node.name):
            return
        objects = list(node.values())
        objects.sort(key=operator.attrgetter('lineno'))
        for obj in objects:
            if (isinstance(obj, ClassDef) and self._isTestClass(obj) and
                    not obj.name.endswith('Tests')):
                self.add_message('W9701', line=obj.lineno, node=obj)
Exemplo n.º 10
0
    def visit_functiondef(self, node):
        """
        A interface will be called when visiting a function or a method.

        @param node: the current node
        """
        if not node.is_method():
            # We only check methods.
            return

        name = node.name

        if isTestModule(node.root().name):
            if name.startswith('test'):
                if not name.startswith('test_'):
                    self.add_message('C9303', node=node)
                    return
                else:
                    # Test names start with 'test_NAME' and can be like
                    # test_SOME_NAME or test_render_SomeCondition.
                    return

        if name[0].isupper():
            self.add_message('C9302', node=node)
            return

        if name.startswith('___'):
            self.add_message('C9302', node=node)
            return

        if name.endswith('___'):
            self.add_message('C9302', node=node)
            return

        if name.startswith('__'):
            if name.endswith('___'):
                # To many trailing underscores.
                self.add_message('C9302', node=node)
                return
            if name.endswith('_') and not name.endswith('__'):
                # To few trailing underscored
                self.add_message('C9302', node=node)
                return
            if name.endswith('__'):
                # This is a reserved name and we don't do any checks on it.
                return
            name = name[2:-2]

        if name.startswith('_'):
            name = name[1:]

        if name.endswith('_'):
            self.add_message('C9302', node=node)
            return

        if '_' in name:
            # This has a underscore in the main name.
            prefix = self._getMethodNamePrefix(node)
            if prefix:
                # There are other names with same prefix so this should be
                # a dispatched method.
                return

            self.add_message('C9302', node=node)
            return


        if isTestModule(node.name) and self.moduleContainsTestCase(node):
            self._checkTestMethodName(node)
Exemplo n.º 11
0
    def visit_functiondef(self, node):
        """
        A interface will be called when visiting a function or a method.

        @param node: the current node
        """
        if not node.is_method():
            # We only check methods.
            return

        name = node.name

        if isTestModule(node.root().name):
            if name.startswith('test'):
                if not name.startswith('test_'):
                    self.add_message('C9303', node=node)
                    return
                else:
                    # Test names start with 'test_NAME' and can be like
                    # test_SOME_NAME or test_render_SomeCondition.
                    return

        if name[0].isupper():
            self.add_message('C9302', node=node)
            return

        if name.startswith('___'):
            self.add_message('C9302', node=node)
            return

        if name.endswith('___'):
            self.add_message('C9302', node=node)
            return

        if name.startswith('__'):
            if name.endswith('___'):
                # To many trailing underscores.
                self.add_message('C9302', node=node)
                return
            if name.endswith('_') and not name.endswith('__'):
                # To few trailing underscored
                self.add_message('C9302', node=node)
                return
            if name.endswith('__'):
                # This is a reserved name and we don't do any checks on it.
                return
            name = name[2:-2]

        if name.startswith('_'):
            name = name[1:]

        if name.endswith('_'):
            self.add_message('C9302', node=node)
            return

        if '_' in name:
            # This has a underscore in the main name.
            prefix = self._getMethodNamePrefix(node)
            if prefix:
                # There are other names with same prefix so this should be
                # a dispatched method.
                return

            self.add_message('C9302', node=node)
            return

        if isTestModule(node.name) and self.moduleContainsTestCase(node):
            self._checkTestMethodName(node)