Fix a bug in PythonExceptionState and add unittest coverage.
I forgot to reset the restore flag when calling member function `Acquire`. The newly added unittest should cover this case. llvm-svn: 253002
This commit is contained in:
@@ -79,6 +79,33 @@ TEST_F(PythonExceptionStateTest, TestDiscardSemantics)
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
}
|
||||
|
||||
TEST_F(PythonExceptionStateTest, TestResetSemantics)
|
||||
{
|
||||
PyErr_Clear();
|
||||
|
||||
// Resetting when auto-restore is true should restore.
|
||||
RaiseException();
|
||||
PythonExceptionState error(true);
|
||||
EXPECT_TRUE(error.IsError());
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
error.Reset();
|
||||
EXPECT_FALSE(error.IsError());
|
||||
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
|
||||
|
||||
PyErr_Clear();
|
||||
|
||||
// Resetting when auto-restore is false should discard.
|
||||
RaiseException();
|
||||
PythonExceptionState error2(false);
|
||||
EXPECT_TRUE(error2.IsError());
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
error2.Reset();
|
||||
EXPECT_FALSE(error2.IsError());
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
TEST_F(PythonExceptionStateTest, TestManualRestoreSemantics)
|
||||
{
|
||||
PyErr_Clear();
|
||||
@@ -119,3 +146,29 @@ TEST_F(PythonExceptionStateTest, TestAutoRestoreSemantics)
|
||||
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
TEST_F(PythonExceptionStateTest, TestAutoRestoreChanged)
|
||||
{
|
||||
// Test that if we re-acquire with different auto-restore semantics,
|
||||
// that the new semantics are respected.
|
||||
PyErr_Clear();
|
||||
|
||||
RaiseException();
|
||||
PythonExceptionState error(false);
|
||||
EXPECT_TRUE(error.IsError());
|
||||
|
||||
error.Reset();
|
||||
EXPECT_FALSE(error.IsError());
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
|
||||
RaiseException();
|
||||
error.Acquire(true);
|
||||
EXPECT_TRUE(error.IsError());
|
||||
EXPECT_FALSE(PythonExceptionState::HasErrorOccurred());
|
||||
|
||||
error.Reset();
|
||||
EXPECT_FALSE(error.IsError());
|
||||
EXPECT_TRUE(PythonExceptionState::HasErrorOccurred());
|
||||
|
||||
PyErr_Clear();
|
||||
}
|
||||
Reference in New Issue
Block a user