Skip to content

Commit 46e9f5b

Browse files
simonjayhawkinsjreback
authored andcommitted
TST: add some message checks in test_query_eval (pandas-dev#29994)
1 parent c5f2084 commit 46e9f5b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/tests/frame/test_query_eval.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,13 @@ def test_query_scope(self):
479479
tm.assert_frame_equal(res, expected)
480480

481481
# no local variable c
482-
with pytest.raises(UndefinedVariableError):
482+
with pytest.raises(
483+
UndefinedVariableError, match="local variable 'c' is not defined"
484+
):
483485
df.query("@a > b > @c", engine=engine, parser=parser)
484486

485487
# no column named 'c'
486-
with pytest.raises(UndefinedVariableError):
488+
with pytest.raises(UndefinedVariableError, match="name 'c' is not defined"):
487489
df.query("@a > b > c", engine=engine, parser=parser)
488490

489491
def test_query_doesnt_pickup_local(self):
@@ -494,7 +496,7 @@ def test_query_doesnt_pickup_local(self):
494496
df = DataFrame(np.random.randint(m, size=(n, 3)), columns=list("abc"))
495497

496498
# we don't pick up the local 'sin'
497-
with pytest.raises(UndefinedVariableError):
499+
with pytest.raises(UndefinedVariableError, match="name 'sin' is not defined"):
498500
df.query("sin > 5", engine=engine, parser=parser)
499501

500502
def test_query_builtin(self):
@@ -588,7 +590,7 @@ def test_nested_raises_on_local_self_reference(self):
588590
df = DataFrame(np.random.randn(5, 3))
589591

590592
# can't reference ourself b/c we're a local so @ is necessary
591-
with pytest.raises(UndefinedVariableError):
593+
with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"):
592594
df.query("df > 0", engine=self.engine, parser=self.parser)
593595

594596
def test_local_syntax(self):
@@ -651,9 +653,9 @@ def test_query_undefined_local(self):
651653
skip_if_no_pandas_parser(parser)
652654

653655
df = DataFrame(np.random.rand(10, 2), columns=list("ab"))
654-
msg = "local variable 'c' is not defined"
655-
656-
with pytest.raises(UndefinedVariableError, match=msg):
656+
with pytest.raises(
657+
UndefinedVariableError, match="local variable 'c' is not defined"
658+
):
657659
df.query("a == @c", engine=engine, parser=parser)
658660

659661
def test_index_resolvers_come_after_columns_with_the_same_name(self):
@@ -784,7 +786,7 @@ def test_nested_scope(self):
784786
with pytest.raises(SyntaxError):
785787
df.query("(@df>0) & (@df2>0)", engine=engine, parser=parser)
786788

787-
with pytest.raises(UndefinedVariableError):
789+
with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"):
788790
df.query("(df>0) & (df2>0)", engine=engine, parser=parser)
789791

790792
expected = df[(df > 0) & (df2 > 0)]

0 commit comments

Comments
 (0)