Ejemplo n.º 1
0
    def check_astroid_module(self, astroid, walker, rawcheckers,
                             tokencheckers):
        """check a module from its astroid representation, real work"""
        # call raw checkers if possible
        try:
            tokens = tokenize_module(astroid)
        except tokenize.TokenError as ex:
            self.add_message('syntax-error',
                             line=ex.args[1][0],
                             args=ex.args[0])
            return

        if not astroid.pure_python:
            self.add_message('raw-checker-failed', args=astroid.name)
        else:
            #assert astroid.file.endswith('.py')
            # invoke ITokenChecker interface on self to fetch module/block
            # level options
            self.process_tokens(tokens)
            if self._ignore_file:
                return False
            # walk ast to collect line numbers
            self.file_state.collect_block_lines(self.msgs_store, astroid)
            # run raw and tokens checkers
            for checker in rawcheckers:
                checker.process_module(astroid)
            for checker in tokencheckers:
                checker.process_tokens(tokens)
        # generate events to astroid checkers
        walker.walk(astroid)
        return True
Ejemplo n.º 2
0
    def check_astroid_module(self, astroid, walker, rawcheckers, tokencheckers):
        """check a module from its astroid representation, real work"""
        # call raw checkers if possible
        try:
            tokens = tokenize_module(astroid)
        except tokenize.TokenError as ex:
            self.add_message('E0001', line=ex.args[1][0], args=ex.args[0])
            return

        if not astroid.pure_python:
            self.add_message('I0001', args=astroid.name)
        else:
            #assert astroid.file.endswith('.py')
            # invoke ITokenChecker interface on self to fetch module/block
            # level options
            self.process_tokens(tokens)
            if self._ignore_file:
                return False
            # walk ast to collect line numbers
            for msg, lines in self._module_msgs_state.items():
                self._raw_module_msgs_state[msg] = lines.copy()
            orig_state = self._module_msgs_state.copy()
            self._module_msgs_state = {}
            self._suppression_mapping = {}
            self.collect_block_lines(astroid, orig_state)
            for checker in rawcheckers:
                checker.process_module(astroid)
            for checker in tokencheckers:
                checker.process_tokens(tokens)
        # generate events to astroid checkers
        walker.walk(astroid)
        return True
Ejemplo n.º 3
0
 def check_astroid_module(self, astroid, walker, rawcheckers, tokencheckers):
     """check a module from its astroid representation, real work"""
     # call raw checkers if possible
     try:
         tokens = tokenize_module(astroid)
     except tokenize.TokenError, ex:
         self.add_message('syntax-error', line=ex.args[1][0], args=ex.args[0])
         return
Ejemplo n.º 4
0
 def check_astroid_module(self, astroid, walker, rawcheckers, tokencheckers):
     """check a module from its astroid representation, real work"""
     # call raw checkers if possible
     try:
         tokens = tokenize_module(astroid)
     except tokenize.TokenError, ex:
         self.add_message('E0001', line=ex.args[1][0], args=ex.args[0])
         return
Ejemplo n.º 5
0
    def test_enable_message_block(self):
        linter = self.linter
        linter.open()
        filepath = join(INPUTDIR, 'func_block_disable_msg.py')
        linter.set_current_module('func_block_disable_msg')
        astroid = linter.get_astroid(filepath, 'func_block_disable_msg')
        linter.process_tokens(tokenize_module(astroid))
        orig_state = linter._module_msgs_state.copy()
        linter._module_msgs_state = {}
        linter._suppression_mapping = {}
        linter.collect_block_lines(astroid, orig_state)
        # global (module level)
        self.assertTrue(linter.is_message_enabled('W0613'))
        self.assertTrue(linter.is_message_enabled('E1101'))
        # meth1
        self.assertTrue(linter.is_message_enabled('W0613', 13))
        # meth2
        self.assertFalse(linter.is_message_enabled('W0613', 18))
        # meth3
        self.assertFalse(linter.is_message_enabled('E1101', 24))
        self.assertTrue(linter.is_message_enabled('E1101', 26))
        # meth4
        self.assertFalse(linter.is_message_enabled('E1101', 32))
        self.assertTrue(linter.is_message_enabled('E1101', 36))
        # meth5
        self.assertFalse(linter.is_message_enabled('E1101', 42))
        self.assertFalse(linter.is_message_enabled('E1101', 43))
        self.assertTrue(linter.is_message_enabled('E1101', 46))
        self.assertFalse(linter.is_message_enabled('E1101', 49))
        self.assertFalse(linter.is_message_enabled('E1101', 51))
        # meth6
        self.assertFalse(linter.is_message_enabled('E1101', 57))
        self.assertTrue(linter.is_message_enabled('E1101', 61))
        self.assertFalse(linter.is_message_enabled('E1101', 64))
        self.assertFalse(linter.is_message_enabled('E1101', 66))

        self.assertTrue(linter.is_message_enabled('E0602', 57))
        self.assertTrue(linter.is_message_enabled('E0602', 61))
        self.assertFalse(linter.is_message_enabled('E0602', 62))
        self.assertTrue(linter.is_message_enabled('E0602', 64))
        self.assertTrue(linter.is_message_enabled('E0602', 66))
        # meth7
        self.assertFalse(linter.is_message_enabled('E1101', 70))
        self.assertTrue(linter.is_message_enabled('E1101', 72))
        self.assertTrue(linter.is_message_enabled('E1101', 75))
        self.assertTrue(linter.is_message_enabled('E1101', 77))

        self.assertEqual(17, linter._suppression_mapping['W0613', 18])
        self.assertEqual(30, linter._suppression_mapping['E1101', 33])
        self.assert_(('E1101', 46) not in linter._suppression_mapping)
        self.assertEqual(1, linter._suppression_mapping['C0302', 18])
        self.assertEqual(1, linter._suppression_mapping['C0302', 50])
        # This is tricky. While the disable in line 106 is disabling
        # both 108 and 110, this is usually not what the user wanted.
        # Therefore, we report the closest previous disable comment.
        self.assertEqual(106, linter._suppression_mapping['E1101', 108])
        self.assertEqual(109, linter._suppression_mapping['E1101', 110])
Ejemplo n.º 6
0
    def test_enable_message_block(self):
        linter = self.linter
        linter.open()
        filepath = join(INPUTDIR, 'func_block_disable_msg.py')
        linter.set_current_module('func_block_disable_msg')
        astroid = linter.get_astroid(filepath, 'func_block_disable_msg')
        linter.process_tokens(tokenize_module(astroid))
        orig_state = linter._module_msgs_state.copy()
        linter._module_msgs_state = {}
        linter._suppression_mapping = {}
        linter.collect_block_lines(astroid, orig_state)
        # global (module level)
        self.assertTrue(linter.is_message_enabled('W0613'))
        self.assertTrue(linter.is_message_enabled('E1101'))
        # meth1
        self.assertTrue(linter.is_message_enabled('W0613', 13))
        # meth2
        self.assertFalse(linter.is_message_enabled('W0613', 18))
        # meth3
        self.assertFalse(linter.is_message_enabled('E1101', 24))
        self.assertTrue(linter.is_message_enabled('E1101', 26))
        # meth4
        self.assertFalse(linter.is_message_enabled('E1101', 32))
        self.assertTrue(linter.is_message_enabled('E1101', 36))
        # meth5
        self.assertFalse(linter.is_message_enabled('E1101', 42))
        self.assertFalse(linter.is_message_enabled('E1101', 43))
        self.assertTrue(linter.is_message_enabled('E1101', 46))
        self.assertFalse(linter.is_message_enabled('E1101', 49))
        self.assertFalse(linter.is_message_enabled('E1101', 51))
        # meth6
        self.assertFalse(linter.is_message_enabled('E1101', 57))
        self.assertTrue(linter.is_message_enabled('E1101', 61))
        self.assertFalse(linter.is_message_enabled('E1101', 64))
        self.assertFalse(linter.is_message_enabled('E1101', 66))

        self.assertTrue(linter.is_message_enabled('E0602', 57))
        self.assertTrue(linter.is_message_enabled('E0602', 61))
        self.assertFalse(linter.is_message_enabled('E0602', 62))
        self.assertTrue(linter.is_message_enabled('E0602', 64))
        self.assertTrue(linter.is_message_enabled('E0602', 66))
        # meth7
        self.assertFalse(linter.is_message_enabled('E1101', 70))
        self.assertTrue(linter.is_message_enabled('E1101', 72))
        self.assertTrue(linter.is_message_enabled('E1101', 75))
        self.assertTrue(linter.is_message_enabled('E1101', 77))

        self.assertEqual(17, linter._suppression_mapping['W0613', 18])
        self.assertEqual(30, linter._suppression_mapping['E1101', 33])
        self.assert_(('E1101', 46) not in linter._suppression_mapping)
        self.assertEqual(1, linter._suppression_mapping['C0302', 18])
        self.assertEqual(1, linter._suppression_mapping['C0302', 50])
        # This is tricky. While the disable in line 106 is disabling
        # both 108 and 110, this is usually not what the user wanted.
        # Therefore, we report the closest previous disable comment.
        self.assertEqual(106, linter._suppression_mapping['E1101', 108])
        self.assertEqual(109, linter._suppression_mapping['E1101', 110])
Ejemplo n.º 7
0
def test_enable_message_block(init_linter):
    linter = init_linter
    linter.open()
    filepath = join(REGRTEST_DATA_DIR, "func_block_disable_msg.py")
    linter.set_current_module("func_block_disable_msg")
    astroid = linter.get_ast(filepath, "func_block_disable_msg")
    linter.process_tokens(tokenize_module(astroid))
    fs = linter.file_state
    fs.collect_block_lines(linter.msgs_store, astroid)
    # global (module level)
    assert linter.is_message_enabled("W0613")
    assert linter.is_message_enabled("E1101")
    # meth1
    assert linter.is_message_enabled("W0613", 13)
    # meth2
    assert not linter.is_message_enabled("W0613", 18)
    # meth3
    assert not linter.is_message_enabled("E1101", 24)
    assert linter.is_message_enabled("E1101", 26)
    # meth4
    assert not linter.is_message_enabled("E1101", 32)
    assert linter.is_message_enabled("E1101", 36)
    # meth5
    assert not linter.is_message_enabled("E1101", 42)
    assert not linter.is_message_enabled("E1101", 43)
    assert linter.is_message_enabled("E1101", 46)
    assert not linter.is_message_enabled("E1101", 49)
    assert not linter.is_message_enabled("E1101", 51)
    # meth6
    assert not linter.is_message_enabled("E1101", 57)
    assert linter.is_message_enabled("E1101", 61)
    assert not linter.is_message_enabled("E1101", 64)
    assert not linter.is_message_enabled("E1101", 66)

    assert linter.is_message_enabled("E0602", 57)
    assert linter.is_message_enabled("E0602", 61)
    assert not linter.is_message_enabled("E0602", 62)
    assert linter.is_message_enabled("E0602", 64)
    assert linter.is_message_enabled("E0602", 66)
    # meth7
    assert not linter.is_message_enabled("E1101", 70)
    assert linter.is_message_enabled("E1101", 72)
    assert linter.is_message_enabled("E1101", 75)
    assert linter.is_message_enabled("E1101", 77)

    fs = linter.file_state
    assert fs._suppression_mapping["W0613", 18] == 17
    assert fs._suppression_mapping["E1101", 33] == 30
    assert ("E1101", 46) not in fs._suppression_mapping
    assert fs._suppression_mapping["C0302", 18] == 1
    assert fs._suppression_mapping["C0302", 50] == 1
    # This is tricky. While the disable in line 106 is disabling
    # both 108 and 110, this is usually not what the user wanted.
    # Therefore, we report the closest previous disable comment.
    assert fs._suppression_mapping["E1101", 108] == 106
    assert fs._suppression_mapping["E1101", 110] == 109
Ejemplo n.º 8
0
def test_enable_message_block(init_linter):
    linter = init_linter
    linter.open()
    filepath = join(INPUTDIR, 'func_block_disable_msg.py')
    linter.set_current_module('func_block_disable_msg')
    astroid = linter.get_ast(filepath, 'func_block_disable_msg')
    linter.process_tokens(tokenize_module(astroid))
    fs = linter.file_state
    fs.collect_block_lines(linter.msgs_store, astroid)
    # global (module level)
    assert linter.is_message_enabled('W0613')
    assert linter.is_message_enabled('E1101')
    # meth1
    assert linter.is_message_enabled('W0613', 13)
    # meth2
    assert not linter.is_message_enabled('W0613', 18)
    # meth3
    assert not linter.is_message_enabled('E1101', 24)
    assert linter.is_message_enabled('E1101', 26)
    # meth4
    assert not linter.is_message_enabled('E1101', 32)
    assert linter.is_message_enabled('E1101', 36)
    # meth5
    assert not linter.is_message_enabled('E1101', 42)
    assert not linter.is_message_enabled('E1101', 43)
    assert linter.is_message_enabled('E1101', 46)
    assert not linter.is_message_enabled('E1101', 49)
    assert not linter.is_message_enabled('E1101', 51)
    # meth6
    assert not linter.is_message_enabled('E1101', 57)
    assert linter.is_message_enabled('E1101', 61)
    assert not linter.is_message_enabled('E1101', 64)
    assert not linter.is_message_enabled('E1101', 66)

    assert linter.is_message_enabled('E0602', 57)
    assert linter.is_message_enabled('E0602', 61)
    assert not linter.is_message_enabled('E0602', 62)
    assert linter.is_message_enabled('E0602', 64)
    assert linter.is_message_enabled('E0602', 66)
    # meth7
    assert not linter.is_message_enabled('E1101', 70)
    assert linter.is_message_enabled('E1101', 72)
    assert linter.is_message_enabled('E1101', 75)
    assert linter.is_message_enabled('E1101', 77)

    fs = linter.file_state
    assert 17 == fs._suppression_mapping['W0613', 18]
    assert 30 == fs._suppression_mapping['E1101', 33]
    assert ('E1101', 46) not in fs._suppression_mapping
    assert 1 == fs._suppression_mapping['C0302', 18]
    assert 1 == fs._suppression_mapping['C0302', 50]
    # This is tricky. While the disable in line 106 is disabling
    # both 108 and 110, this is usually not what the user wanted.
    # Therefore, we report the closest previous disable comment.
    assert 106 == fs._suppression_mapping['E1101', 108]
    assert 109 == fs._suppression_mapping['E1101', 110]
Ejemplo n.º 9
0
def test_enable_message_block(init_linter):
    linter = init_linter
    linter.open()
    filepath = join(INPUTDIR, 'func_block_disable_msg.py')
    linter.set_current_module('func_block_disable_msg')
    astroid = linter.get_ast(filepath, 'func_block_disable_msg')
    linter.process_tokens(tokenize_module(astroid))
    fs = linter.file_state
    fs.collect_block_lines(linter.msgs_store, astroid)
    # global (module level)
    assert linter.is_message_enabled('W0613')
    assert linter.is_message_enabled('E1101')
    # meth1
    assert linter.is_message_enabled('W0613', 13)
    # meth2
    assert not linter.is_message_enabled('W0613', 18)
    # meth3
    assert not linter.is_message_enabled('E1101', 24)
    assert linter.is_message_enabled('E1101', 26)
    # meth4
    assert not linter.is_message_enabled('E1101', 32)
    assert linter.is_message_enabled('E1101', 36)
    # meth5
    assert not linter.is_message_enabled('E1101', 42)
    assert not linter.is_message_enabled('E1101', 43)
    assert linter.is_message_enabled('E1101', 46)
    assert not linter.is_message_enabled('E1101', 49)
    assert not linter.is_message_enabled('E1101', 51)
    # meth6
    assert not linter.is_message_enabled('E1101', 57)
    assert linter.is_message_enabled('E1101', 61)
    assert not linter.is_message_enabled('E1101', 64)
    assert not linter.is_message_enabled('E1101', 66)

    assert linter.is_message_enabled('E0602', 57)
    assert linter.is_message_enabled('E0602', 61)
    assert not linter.is_message_enabled('E0602', 62)
    assert linter.is_message_enabled('E0602', 64)
    assert linter.is_message_enabled('E0602', 66)
    # meth7
    assert not linter.is_message_enabled('E1101', 70)
    assert linter.is_message_enabled('E1101', 72)
    assert linter.is_message_enabled('E1101', 75)
    assert linter.is_message_enabled('E1101', 77)

    fs = linter.file_state
    assert 17 == fs._suppression_mapping['W0613', 18]
    assert 30 == fs._suppression_mapping['E1101', 33]
    assert ('E1101', 46) not in fs._suppression_mapping
    assert 1 == fs._suppression_mapping['C0302', 18]
    assert 1 == fs._suppression_mapping['C0302', 50]
    # This is tricky. While the disable in line 106 is disabling
    # both 108 and 110, this is usually not what the user wanted.
    # Therefore, we report the closest previous disable comment.
    assert 106 == fs._suppression_mapping['E1101', 108]
    assert 109 == fs._suppression_mapping['E1101', 110]
Ejemplo n.º 10
0
    def test_enable_message_block(self):
        linter = self.init_linter()
        linter.open()
        filepath = join(INPUTDIR, "func_block_disable_msg.py")
        linter.set_current_module("func_block_disable_msg")
        astroid = linter.get_ast(filepath, "func_block_disable_msg")
        linter.process_tokens(tokenize_module(astroid))
        fs = linter.file_state
        fs.collect_block_lines(linter.msgs_store, astroid)
        # global (module level)
        self.assertTrue(linter.is_message_enabled("W0613"))
        self.assertTrue(linter.is_message_enabled("E1101"))
        # meth1
        self.assertTrue(linter.is_message_enabled("W0613", 13))
        # meth2
        self.assertFalse(linter.is_message_enabled("W0613", 18))
        # meth3
        self.assertFalse(linter.is_message_enabled("E1101", 24))
        self.assertTrue(linter.is_message_enabled("E1101", 26))
        # meth4
        self.assertFalse(linter.is_message_enabled("E1101", 32))
        self.assertTrue(linter.is_message_enabled("E1101", 36))
        # meth5
        self.assertFalse(linter.is_message_enabled("E1101", 42))
        self.assertFalse(linter.is_message_enabled("E1101", 43))
        self.assertTrue(linter.is_message_enabled("E1101", 46))
        self.assertFalse(linter.is_message_enabled("E1101", 49))
        self.assertFalse(linter.is_message_enabled("E1101", 51))
        # meth6
        self.assertFalse(linter.is_message_enabled("E1101", 57))
        self.assertTrue(linter.is_message_enabled("E1101", 61))
        self.assertFalse(linter.is_message_enabled("E1101", 64))
        self.assertFalse(linter.is_message_enabled("E1101", 66))

        self.assertTrue(linter.is_message_enabled("E0602", 57))
        self.assertTrue(linter.is_message_enabled("E0602", 61))
        self.assertFalse(linter.is_message_enabled("E0602", 62))
        self.assertTrue(linter.is_message_enabled("E0602", 64))
        self.assertTrue(linter.is_message_enabled("E0602", 66))
        # meth7
        self.assertFalse(linter.is_message_enabled("E1101", 70))
        self.assertTrue(linter.is_message_enabled("E1101", 72))
        self.assertTrue(linter.is_message_enabled("E1101", 75))
        self.assertTrue(linter.is_message_enabled("E1101", 77))

        fs = linter.file_state
        self.assertEqual(17, fs._suppression_mapping["W0613", 18])
        self.assertEqual(30, fs._suppression_mapping["E1101", 33])
        self.assertTrue(("E1101", 46) not in fs._suppression_mapping)
        self.assertEqual(1, fs._suppression_mapping["C0302", 18])
        self.assertEqual(1, fs._suppression_mapping["C0302", 50])
        # This is tricky. While the disable in line 106 is disabling
        # both 108 and 110, this is usually not what the user wanted.
        # Therefore, we report the closest previous disable comment.
        self.assertEqual(106, fs._suppression_mapping["E1101", 108])
        self.assertEqual(109, fs._suppression_mapping["E1101", 110])