def test_doctstring_pass(self): def inner(): """This is just a function that passes.""" pass with self.assertRaisesRegex(ValueError, 'pass'): syntax_matchers.StmtFromFunctionPattern(func=inner)
def test_bare_yield(self): def inner(): yield # pylint: disable=misplaced-bare-raise self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'def f():\n yield'), ['yield'])
def test_return(self): def inner(x): return x.y self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'def f():\n return z.y'), ['return z.y'])
def test_empty_return(self): def inner(): return self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'def x():\n return'), ['return'])
def test_single_line(self): def inner(x, y): x = y # pylint: disable=unused-argument,multiple-statements self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'a = b'), ['a = b'])
def test_lvalue_variable(self): def inner(x, y): # pylint: disable=unused-argument x = y self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'a = b'), ['a = b'])
def test_docstring(self): def inner(x, y): # pylint: disable=unused-argument """This function should just transform certain assignments.""" x = y self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'a = b'), ['a = b'])
def test_single_line_multi_statement(self): # This is bad don't ever do this. def inner(x, y): x = y y = x # pylint: disable=unused-argument,multiple-statements self.assertEqual( self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=inner), 'a = b'), ['a = b'])
def test_pass(self): def inner(): pass with self.assertRaisesRegex(ValueError, 'pass'): syntax_matchers.StmtFromFunctionPattern(func=inner)
def test_lambda(self): with self.assertRaisesRegex(ValueError, 'lambda'): self.get_all_match_strings( syntax_matchers.StmtFromFunctionPattern(func=lambda x: x))
def test_empty_function(self): def inner(): """This is a load-bearing docstring!""" with self.assertRaisesRegex(ValueError, 'docstring'): syntax_matchers.StmtFromFunctionPattern(func=inner)