def test_parse_global_noqa_with_target(self): """Make sure targets are present in the lists.""" func = '\n'.join([ 'def my_function(arg1):', ' """Ignore missing argument.', '', ' # noqa: I101 arg1', '', ' """', ' pass', ]) doc = ast.get_docstring(ast.parse(func).body[0]) docstring = Docstring(doc) noqas = docstring.get_noqas() self.assertTrue('arg1' in noqas['I101'])
def test_parse_noqa_for_global(self): """Make sure global targets are empty lists.""" func = '\n'.join([ 'def my_function():', ' """Ignore missing return.', '', ' # noqa: I201', '', ' """', ' return "This is ignored."', ]) doc = ast.get_docstring(ast.parse(func).body[0]) docstring = Docstring(doc) noqas = docstring.get_noqas() self.assertEqual( noqas['I201'], [], 'Expected target for I201 to be None but was {}'.format( noqas['I201']))
def test_parse_noqa_for_argument(self): """Make sure we can get the noqas.""" func = '\n'.join([ 'def my_function():', ' """Has an extra argument, but thats okay.', '', ' Args:', ' arg1: This will be defined very soon. # noqa: I102', '', ' """', ' print("Not done yet!")', ]) doc = ast.get_docstring(ast.parse(func).body[0]) self.assertTrue(doc.startswith('Has an extra')) docstring = Docstring(doc) self.assertTrue('arg1' in docstring.arguments_description) noqas = docstring.get_noqas() self.assertTrue('arg1' in noqas['I102'])