aboutsummaryrefslogtreecommitdiff
path: root/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-11-11 17:59:49 +0000
committerZachary Turner <zturner@google.com>2015-11-11 17:59:49 +0000
commit7841efbb9255126763167b9d7d59242333c6f1bd (patch)
tree772ef04f6ea7c4bf9115b57228f2e8122164b55f /lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
parent7d7814ae8a50999db77c0617989232d807c801a2 (diff)
downloadllvm-7841efbb9255126763167b9d7d59242333c6f1bd.zip
llvm-7841efbb9255126763167b9d7d59242333c6f1bd.tar.gz
llvm-7841efbb9255126763167b9d7d59242333c6f1bd.tar.bz2
Add a `PythonModule` class, and a root-level method for resolving names.
llvm-svn: 252765
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
index 7abfb11..728208b 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
@@ -96,6 +96,66 @@ TEST_F(PythonDataObjectsTest, TestBorrowedReferences)
EXPECT_EQ(original_refcnt + 1, borrowed_long.get()->ob_refcnt);
}
+TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionNoDot)
+{
+ PythonObject sys_module = PythonObject::ResolveNameGlobal("sys");
+ EXPECT_TRUE(sys_module.IsAllocated());
+ EXPECT_TRUE(PythonModule::Check(sys_module.get()));
+}
+
+TEST_F(PythonDataObjectsTest, TestModuleNameResolutionNoDot)
+{
+ PythonObject sys_module = PythonObject::ResolveNameGlobal("sys");
+ PythonObject sys_path = sys_module.ResolveName("path");
+ PythonObject sys_version_info = sys_module.ResolveName("version_info");
+ EXPECT_TRUE(sys_path.IsAllocated());
+ EXPECT_TRUE(sys_version_info.IsAllocated());
+
+ EXPECT_TRUE(PythonList::Check(sys_path.get()));
+}
+
+TEST_F(PythonDataObjectsTest, TestTypeNameResolutionNoDot)
+{
+ PythonObject sys_module = PythonObject::ResolveNameGlobal("sys");
+ PythonObject sys_version_info = sys_module.ResolveName("version_info");
+
+ PythonObject version_info_type(PyRefType::Owned, PyObject_Type(sys_version_info.get()));
+ EXPECT_TRUE(version_info_type.IsAllocated());
+ PythonObject major_version_field = version_info_type.ResolveName("major");
+ EXPECT_TRUE(major_version_field.IsAllocated());
+}
+
+TEST_F(PythonDataObjectsTest, TestInstanceNameResolutionNoDot)
+{
+ PythonObject sys_module = PythonObject::ResolveNameGlobal("sys");
+ PythonObject sys_version_info = sys_module.ResolveName("version_info");
+ PythonObject major_version_field = sys_version_info.ResolveName("major");
+ PythonObject minor_version_field = sys_version_info.ResolveName("minor");
+
+ EXPECT_TRUE(major_version_field.IsAllocated());
+ EXPECT_TRUE(minor_version_field.IsAllocated());
+
+ PythonInteger major_version_value = major_version_field.AsType<PythonInteger>();
+ PythonInteger minor_version_value = minor_version_field.AsType<PythonInteger>();
+
+ EXPECT_EQ(PY_MAJOR_VERSION, major_version_value.GetInteger());
+ EXPECT_EQ(PY_MINOR_VERSION, minor_version_value.GetInteger());
+}
+
+TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionWithDot)
+{
+ PythonObject sys_path = PythonObject::ResolveNameGlobal("sys.path");
+ EXPECT_TRUE(sys_path.IsAllocated());
+ EXPECT_TRUE(PythonList::Check(sys_path.get()));
+
+ PythonInteger version_major = PythonObject::ResolveNameGlobal("sys.version_info.major").AsType<PythonInteger>();
+ PythonInteger version_minor = PythonObject::ResolveNameGlobal("sys.version_info.minor").AsType<PythonInteger>();
+ EXPECT_TRUE(version_major.IsAllocated());
+ EXPECT_TRUE(version_minor.IsAllocated());
+ EXPECT_EQ(PY_MAJOR_VERSION, version_major.GetInteger());
+ EXPECT_EQ(PY_MINOR_VERSION, version_minor.GetInteger());
+}
+
TEST_F(PythonDataObjectsTest, TestPythonInteger)
{
// Test that integers behave correctly when wrapped by a PythonInteger.