xref: /llvm-project/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp (revision c946d46283b2578055c47de9b7ef7d182cd9a2ac)
1 //===-- PythonDataObjectsTests.cpp ------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "gtest/gtest.h"
11 
12 #include "lldb/Host/File.h"
13 #include "lldb/Host/FileSystem.h"
14 #include "lldb/Host/HostInfo.h"
15 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
16 #include "Plugins/ScriptInterpreter/Python/PythonDataObjects.h"
17 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
18 
19 #include "PythonTestSuite.h"
20 
21 using namespace lldb_private;
22 
23 class PythonDataObjectsTest : public PythonTestSuite
24 {
25   public:
26     void
27     SetUp() override
28     {
29         PythonTestSuite::SetUp();
30 
31         PythonString sys_module("sys");
32         m_sys_module.Reset(PyRefType::Owned, PyImport_Import(sys_module.get()));
33         m_main_module = PythonModule::MainModule();
34         m_builtins_module = PythonModule::BuiltinsModule();
35     }
36 
37     void
38     TearDown() override
39     {
40         m_sys_module.Reset();
41         m_main_module.Reset();
42         m_builtins_module.Reset();
43 
44         PythonTestSuite::TearDown();
45     }
46 
47   protected:
48     PythonModule m_sys_module;
49     PythonModule m_main_module;
50     PythonModule m_builtins_module;
51 };
52 
53 TEST_F(PythonDataObjectsTest, TestOwnedReferences)
54 {
55     // After creating a new object, the refcount should be >= 1
56     PyObject *obj = PyLong_FromLong(3);
57     Py_ssize_t original_refcnt = obj->ob_refcnt;
58     EXPECT_LE(1, original_refcnt);
59 
60     // If we take an owned reference, the refcount should be the same
61     PythonObject owned_long(PyRefType::Owned, obj);
62     EXPECT_EQ(original_refcnt, owned_long.get()->ob_refcnt);
63 
64     // Take another reference and verify that the refcount increases by 1
65     PythonObject strong_ref(owned_long);
66     EXPECT_EQ(original_refcnt + 1, strong_ref.get()->ob_refcnt);
67 
68     // If we reset the first one, the refcount should be the original value.
69     owned_long.Reset();
70     EXPECT_EQ(original_refcnt, strong_ref.get()->ob_refcnt);
71 }
72 
73 TEST_F(PythonDataObjectsTest, TestResetting)
74 {
75     PythonDictionary dict(PyInitialValue::Empty);
76 
77     PyObject *new_dict = PyDict_New();
78     dict.Reset(PyRefType::Owned, new_dict);
79     EXPECT_EQ(new_dict, dict.get());
80 
81     dict.Reset(PyRefType::Owned, nullptr);
82     EXPECT_EQ(nullptr, dict.get());
83 
84     dict.Reset(PyRefType::Owned, PyDict_New());
85     EXPECT_NE(nullptr, dict.get());
86     dict.Reset();
87     EXPECT_EQ(nullptr, dict.get());
88 }
89 
90 TEST_F(PythonDataObjectsTest, TestBorrowedReferences)
91 {
92     PythonInteger long_value(PyRefType::Owned, PyLong_FromLong(3));
93     Py_ssize_t original_refcnt = long_value.get()->ob_refcnt;
94     EXPECT_LE(1, original_refcnt);
95 
96     PythonInteger borrowed_long(PyRefType::Borrowed, long_value.get());
97     EXPECT_EQ(original_refcnt + 1, borrowed_long.get()->ob_refcnt);
98 }
99 
100 TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionNoDot)
101 {
102     PythonObject sys_module = m_main_module.ResolveName("sys");
103     EXPECT_EQ(m_sys_module.get(), sys_module.get());
104     EXPECT_TRUE(sys_module.IsAllocated());
105     EXPECT_TRUE(PythonModule::Check(sys_module.get()));
106 }
107 
108 TEST_F(PythonDataObjectsTest, TestModuleNameResolutionNoDot)
109 {
110     PythonObject sys_path = m_sys_module.ResolveName("path");
111     PythonObject sys_version_info = m_sys_module.ResolveName("version_info");
112     EXPECT_TRUE(sys_path.IsAllocated());
113     EXPECT_TRUE(sys_version_info.IsAllocated());
114 
115     EXPECT_TRUE(PythonList::Check(sys_path.get()));
116 }
117 
118 TEST_F(PythonDataObjectsTest, TestTypeNameResolutionNoDot)
119 {
120     PythonObject sys_version_info = m_sys_module.ResolveName("version_info");
121 
122     PythonObject version_info_type(PyRefType::Owned, PyObject_Type(sys_version_info.get()));
123     EXPECT_TRUE(version_info_type.IsAllocated());
124     PythonObject major_version_field = version_info_type.ResolveName("major");
125     EXPECT_TRUE(major_version_field.IsAllocated());
126 }
127 
128 TEST_F(PythonDataObjectsTest, TestInstanceNameResolutionNoDot)
129 {
130     PythonObject sys_version_info = m_sys_module.ResolveName("version_info");
131     PythonObject major_version_field = sys_version_info.ResolveName("major");
132     PythonObject minor_version_field = sys_version_info.ResolveName("minor");
133 
134     EXPECT_TRUE(major_version_field.IsAllocated());
135     EXPECT_TRUE(minor_version_field.IsAllocated());
136 
137     PythonInteger major_version_value = major_version_field.AsType<PythonInteger>();
138     PythonInteger minor_version_value = minor_version_field.AsType<PythonInteger>();
139 
140     EXPECT_EQ(PY_MAJOR_VERSION, major_version_value.GetInteger());
141     EXPECT_EQ(PY_MINOR_VERSION, minor_version_value.GetInteger());
142 }
143 
144 TEST_F(PythonDataObjectsTest, TestGlobalNameResolutionWithDot)
145 {
146     PythonObject sys_path = m_main_module.ResolveName("sys.path");
147     EXPECT_TRUE(sys_path.IsAllocated());
148     EXPECT_TRUE(PythonList::Check(sys_path.get()));
149 
150     PythonInteger version_major = m_main_module.ResolveName(
151         "sys.version_info.major").AsType<PythonInteger>();
152     PythonInteger version_minor = m_main_module.ResolveName(
153         "sys.version_info.minor").AsType<PythonInteger>();
154     EXPECT_TRUE(version_major.IsAllocated());
155     EXPECT_TRUE(version_minor.IsAllocated());
156     EXPECT_EQ(PY_MAJOR_VERSION, version_major.GetInteger());
157     EXPECT_EQ(PY_MINOR_VERSION, version_minor.GetInteger());
158 }
159 
160 TEST_F(PythonDataObjectsTest, TestDictionaryResolutionWithDot)
161 {
162     // Make up a custom dictionary with "sys" pointing to the `sys` module.
163     PythonDictionary dict(PyInitialValue::Empty);
164     dict.SetItemForKey(PythonString("sys"), m_sys_module);
165 
166     // Now use that dictionary to resolve `sys.version_info.major`
167     PythonInteger version_major = PythonObject::ResolveNameWithDictionary(
168         "sys.version_info.major", dict).AsType<PythonInteger>();
169     PythonInteger version_minor = PythonObject::ResolveNameWithDictionary(
170         "sys.version_info.minor", dict).AsType<PythonInteger>();
171     EXPECT_EQ(PY_MAJOR_VERSION, version_major.GetInteger());
172     EXPECT_EQ(PY_MINOR_VERSION, version_minor.GetInteger());
173 }
174 
175 TEST_F(PythonDataObjectsTest, TestPythonInteger)
176 {
177 // Test that integers behave correctly when wrapped by a PythonInteger.
178 
179 #if PY_MAJOR_VERSION < 3
180     // Verify that `PythonInt` works correctly when given a PyInt object.
181     // Note that PyInt doesn't exist in Python 3.x, so this is only for 2.x
182     PyObject *py_int = PyInt_FromLong(12);
183     EXPECT_TRUE(PythonInteger::Check(py_int));
184     PythonInteger python_int(PyRefType::Owned, py_int);
185 
186     EXPECT_EQ(PyObjectType::Integer, python_int.GetObjectType());
187     EXPECT_EQ(12, python_int.GetInteger());
188 #endif
189 
190     // Verify that `PythonInteger` works correctly when given a PyLong object.
191     PyObject *py_long = PyLong_FromLong(12);
192     EXPECT_TRUE(PythonInteger::Check(py_long));
193     PythonInteger python_long(PyRefType::Owned, py_long);
194     EXPECT_EQ(PyObjectType::Integer, python_long.GetObjectType());
195 
196     // Verify that you can reset the value and that it is reflected properly.
197     python_long.SetInteger(40);
198     EXPECT_EQ(40, python_long.GetInteger());
199 
200     // Test that creating a `PythonInteger` object works correctly with the
201     // int constructor.
202     PythonInteger constructed_int(7);
203     EXPECT_EQ(7, constructed_int.GetInteger());
204 }
205 
206 TEST_F(PythonDataObjectsTest, TestPythonString)
207 {
208     // Test that strings behave correctly when wrapped by a PythonString.
209 
210     static const char *test_string = "PythonDataObjectsTest::TestPythonString1";
211     static const char *test_string2 = "PythonDataObjectsTest::TestPythonString2";
212     static const char *test_string3 = "PythonDataObjectsTest::TestPythonString3";
213 
214 #if PY_MAJOR_VERSION < 3
215     // Verify that `PythonString` works correctly when given a PyString object.
216     // Note that PyString doesn't exist in Python 3.x, so this is only for 2.x
217     PyObject *py_string = PyString_FromString(test_string);
218     EXPECT_TRUE(PythonString::Check(py_string));
219     PythonString python_string(PyRefType::Owned, py_string);
220 
221     EXPECT_EQ(PyObjectType::String, python_string.GetObjectType());
222     EXPECT_STREQ(test_string, python_string.GetString().data());
223 #else
224     // Verify that `PythonString` works correctly when given a PyUnicode object.
225     PyObject *py_unicode = PyUnicode_FromString(test_string);
226     EXPECT_TRUE(PythonString::Check(py_unicode));
227     PythonString python_unicode(PyRefType::Owned, py_unicode);
228     EXPECT_EQ(PyObjectType::String, python_unicode.GetObjectType());
229     EXPECT_STREQ(test_string, python_unicode.GetString().data());
230 #endif
231 
232     // Test that creating a `PythonString` object works correctly with the
233     // string constructor
234     PythonString constructed_string(test_string3);
235     EXPECT_STREQ(test_string3, constructed_string.GetString().str().c_str());
236 }
237 
238 TEST_F(PythonDataObjectsTest, TestPythonStringToStr)
239 {
240     const char *c_str = "PythonDataObjectsTest::TestPythonStringToStr";
241 
242     PythonString str(c_str);
243     EXPECT_STREQ(c_str, str.GetString().str().c_str());
244 
245     PythonString str_str = str.Str();
246     EXPECT_STREQ(c_str, str_str.GetString().str().c_str());
247 }
248 
249 TEST_F(PythonDataObjectsTest, TestPythonIntegerToStr)
250 {
251 }
252 
253 TEST_F(PythonDataObjectsTest, TestPythonIntegerToStructuredInteger)
254 {
255     PythonInteger integer(7);
256     auto int_sp = integer.CreateStructuredInteger();
257     EXPECT_EQ(7, int_sp->GetValue());
258 }
259 
260 TEST_F(PythonDataObjectsTest, TestPythonStringToStructuredString)
261 {
262     static const char *test_string = "PythonDataObjectsTest::TestPythonStringToStructuredString";
263     PythonString constructed_string(test_string);
264     auto string_sp = constructed_string.CreateStructuredString();
265     EXPECT_STREQ(test_string, string_sp->GetStringValue().c_str());
266 }
267 
268 TEST_F(PythonDataObjectsTest, TestPythonListValueEquality)
269 {
270     // Test that a list which is built through the native
271     // Python API behaves correctly when wrapped by a PythonList.
272     static const int list_size = 2;
273     static const long long_value0 = 5;
274     static const char *const string_value1 = "String Index 1";
275 
276     PyObject *py_list = PyList_New(2);
277     EXPECT_TRUE(PythonList::Check(py_list));
278     PythonList list(PyRefType::Owned, py_list);
279 
280     PythonObject list_items[list_size];
281     list_items[0].Reset(PythonInteger(long_value0));
282     list_items[1].Reset(PythonString(string_value1));
283 
284     for (int i = 0; i < list_size; ++i)
285         list.SetItemAtIndex(i, list_items[i]);
286 
287     EXPECT_EQ(list_size, list.GetSize());
288     EXPECT_EQ(PyObjectType::List, list.GetObjectType());
289 
290     // Verify that the values match
291     PythonObject chk_value1 = list.GetItemAtIndex(0);
292     PythonObject chk_value2 = list.GetItemAtIndex(1);
293     EXPECT_TRUE(PythonInteger::Check(chk_value1.get()));
294     EXPECT_TRUE(PythonString::Check(chk_value2.get()));
295 
296     PythonInteger chk_int(PyRefType::Borrowed, chk_value1.get());
297     PythonString chk_str(PyRefType::Borrowed, chk_value2.get());
298 
299     EXPECT_EQ(long_value0, chk_int.GetInteger());
300     EXPECT_STREQ(string_value1, chk_str.GetString().str().c_str());
301 }
302 
303 TEST_F(PythonDataObjectsTest, TestPythonListManipulation)
304 {
305     // Test that manipulation of a PythonList behaves correctly when
306     // wrapped by a PythonDictionary.
307 
308     static const long long_value0 = 5;
309     static const char *const string_value1 = "String Index 1";
310 
311     PythonList list(PyInitialValue::Empty);
312     PythonInteger integer(long_value0);
313     PythonString string(string_value1);
314 
315     list.AppendItem(integer);
316     list.AppendItem(string);
317     EXPECT_EQ(2, list.GetSize());
318 
319     // Verify that the values match
320     PythonObject chk_value1 = list.GetItemAtIndex(0);
321     PythonObject chk_value2 = list.GetItemAtIndex(1);
322     EXPECT_TRUE(PythonInteger::Check(chk_value1.get()));
323     EXPECT_TRUE(PythonString::Check(chk_value2.get()));
324 
325     PythonInteger chk_int(PyRefType::Borrowed, chk_value1.get());
326     PythonString chk_str(PyRefType::Borrowed, chk_value2.get());
327 
328     EXPECT_EQ(long_value0, chk_int.GetInteger());
329     EXPECT_STREQ(string_value1, chk_str.GetString().str().c_str());
330 }
331 
332 TEST_F(PythonDataObjectsTest, TestPythonListToStructuredList)
333 {
334     static const long long_value0 = 5;
335     static const char *const string_value1 = "String Index 1";
336 
337     PythonList list(PyInitialValue::Empty);
338     list.AppendItem(PythonInteger(long_value0));
339     list.AppendItem(PythonString(string_value1));
340 
341     auto array_sp = list.CreateStructuredArray();
342     EXPECT_EQ(StructuredData::Type::eTypeInteger, array_sp->GetItemAtIndex(0)->GetType());
343     EXPECT_EQ(StructuredData::Type::eTypeString, array_sp->GetItemAtIndex(1)->GetType());
344 
345     auto int_sp = array_sp->GetItemAtIndex(0)->GetAsInteger();
346     auto string_sp = array_sp->GetItemAtIndex(1)->GetAsString();
347 
348     EXPECT_EQ(long_value0, int_sp->GetValue());
349     EXPECT_STREQ(string_value1, string_sp->GetValue().c_str());
350 }
351 
352 TEST_F(PythonDataObjectsTest, TestPythonTupleSize)
353 {
354     PythonTuple tuple(PyInitialValue::Empty);
355     EXPECT_EQ(0, tuple.GetSize());
356 
357     tuple = PythonTuple(3);
358     EXPECT_EQ(3, tuple.GetSize());
359 }
360 
361 TEST_F(PythonDataObjectsTest, TestPythonTupleValues)
362 {
363     PythonTuple tuple(3);
364 
365     PythonInteger int_value(1);
366     PythonString string_value("Test");
367     PythonObject none_value(PyRefType::Borrowed, Py_None);
368 
369     tuple.SetItemAtIndex(0, int_value);
370     tuple.SetItemAtIndex(1, string_value);
371     tuple.SetItemAtIndex(2, none_value);
372 
373     EXPECT_EQ(tuple.GetItemAtIndex(0).get(), int_value.get());
374     EXPECT_EQ(tuple.GetItemAtIndex(1).get(), string_value.get());
375     EXPECT_EQ(tuple.GetItemAtIndex(2).get(), none_value.get());
376 }
377 
378 TEST_F(PythonDataObjectsTest, TestPythonTupleInitializerList)
379 {
380     PythonInteger int_value(1);
381     PythonString string_value("Test");
382     PythonObject none_value(PyRefType::Borrowed, Py_None);
383     PythonTuple tuple{ int_value, string_value, none_value };
384     EXPECT_EQ(3, tuple.GetSize());
385 
386     EXPECT_EQ(tuple.GetItemAtIndex(0).get(), int_value.get());
387     EXPECT_EQ(tuple.GetItemAtIndex(1).get(), string_value.get());
388     EXPECT_EQ(tuple.GetItemAtIndex(2).get(), none_value.get());
389 }
390 
391 TEST_F(PythonDataObjectsTest, TestPythonTupleInitializerList2)
392 {
393     PythonInteger int_value(1);
394     PythonString string_value("Test");
395     PythonObject none_value(PyRefType::Borrowed, Py_None);
396 
397     PythonTuple tuple{ int_value.get(), string_value.get(), none_value.get() };
398     EXPECT_EQ(3, tuple.GetSize());
399 
400     EXPECT_EQ(tuple.GetItemAtIndex(0).get(), int_value.get());
401     EXPECT_EQ(tuple.GetItemAtIndex(1).get(), string_value.get());
402     EXPECT_EQ(tuple.GetItemAtIndex(2).get(), none_value.get());
403 }
404 
405 TEST_F(PythonDataObjectsTest, TestPythonTupleToStructuredList)
406 {
407     PythonInteger int_value(1);
408     PythonString string_value("Test");
409 
410     PythonTuple tuple{ int_value.get(), string_value.get() };
411 
412     auto array_sp = tuple.CreateStructuredArray();
413     EXPECT_EQ(tuple.GetSize(), array_sp->GetSize());
414     EXPECT_EQ(StructuredData::Type::eTypeInteger, array_sp->GetItemAtIndex(0)->GetType());
415     EXPECT_EQ(StructuredData::Type::eTypeString, array_sp->GetItemAtIndex(1)->GetType());
416 }
417 
418 TEST_F(PythonDataObjectsTest, TestPythonDictionaryValueEquality)
419 {
420     // Test that a dictionary which is built through the native
421     // Python API behaves correctly when wrapped by a PythonDictionary.
422     static const int dict_entries = 2;
423     const char *key_0 = "Key 0";
424     int key_1 = 1;
425     const int value_0 = 0;
426     const char *value_1 = "Value 1";
427 
428     PythonObject py_keys[dict_entries];
429     PythonObject py_values[dict_entries];
430 
431     py_keys[0].Reset(PythonString(key_0));
432     py_keys[1].Reset(PythonInteger(key_1));
433     py_values[0].Reset(PythonInteger(value_0));
434     py_values[1].Reset(PythonString(value_1));
435 
436     PyObject *py_dict = PyDict_New();
437     EXPECT_TRUE(PythonDictionary::Check(py_dict));
438     PythonDictionary dict(PyRefType::Owned, py_dict);
439 
440     for (int i = 0; i < dict_entries; ++i)
441         PyDict_SetItem(py_dict, py_keys[i].get(), py_values[i].get());
442     EXPECT_EQ(dict.GetSize(), dict_entries);
443     EXPECT_EQ(PyObjectType::Dictionary, dict.GetObjectType());
444 
445     // Verify that the values match
446     PythonObject chk_value1 = dict.GetItemForKey(py_keys[0]);
447     PythonObject chk_value2 = dict.GetItemForKey(py_keys[1]);
448     EXPECT_TRUE(PythonInteger::Check(chk_value1.get()));
449     EXPECT_TRUE(PythonString::Check(chk_value2.get()));
450 
451     PythonInteger chk_int(PyRefType::Borrowed, chk_value1.get());
452     PythonString chk_str(PyRefType::Borrowed, chk_value2.get());
453 
454     EXPECT_EQ(value_0, chk_int.GetInteger());
455     EXPECT_STREQ(value_1, chk_str.GetString().str().c_str());
456 }
457 
458 TEST_F(PythonDataObjectsTest, TestPythonDictionaryManipulation)
459 {
460     // Test that manipulation of a dictionary behaves correctly when wrapped
461     // by a PythonDictionary.
462     static const int dict_entries = 2;
463 
464     const char *const key_0 = "Key 0";
465     const char *const key_1 = "Key 1";
466     const long value_0 = 1;
467     const char *const value_1 = "Value 1";
468 
469     PythonString keys[dict_entries];
470     PythonObject values[dict_entries];
471 
472     keys[0].Reset(PythonString(key_0));
473     keys[1].Reset(PythonString(key_1));
474     values[0].Reset(PythonInteger(value_0));
475     values[1].Reset(PythonString(value_1));
476 
477     PythonDictionary dict(PyInitialValue::Empty);
478     for (int i = 0; i < 2; ++i)
479         dict.SetItemForKey(keys[i], values[i]);
480 
481     EXPECT_EQ(dict_entries, dict.GetSize());
482 
483     // Verify that the keys and values match
484     PythonObject chk_value1 = dict.GetItemForKey(keys[0]);
485     PythonObject chk_value2 = dict.GetItemForKey(keys[1]);
486     EXPECT_TRUE(PythonInteger::Check(chk_value1.get()));
487     EXPECT_TRUE(PythonString::Check(chk_value2.get()));
488 
489     PythonInteger chk_int(PyRefType::Borrowed, chk_value1.get());
490     PythonString chk_str(PyRefType::Borrowed, chk_value2.get());
491 
492     EXPECT_EQ(value_0, chk_int.GetInteger());
493     EXPECT_STREQ(value_1, chk_str.GetString().str().c_str());
494 }
495 
496 TEST_F(PythonDataObjectsTest, TestPythonDictionaryToStructuredDictionary)
497 {
498     static const char *const string_key0 = "String Key 0";
499     static const char *const string_key1 = "String Key 1";
500 
501     static const char *const string_value0 = "String Value 0";
502     static const long int_value1 = 7;
503 
504     PythonDictionary dict(PyInitialValue::Empty);
505     dict.SetItemForKey(PythonString(string_key0), PythonString(string_value0));
506     dict.SetItemForKey(PythonString(string_key1), PythonInteger(int_value1));
507 
508     auto dict_sp = dict.CreateStructuredDictionary();
509     EXPECT_EQ(2, dict_sp->GetSize());
510 
511     EXPECT_TRUE(dict_sp->HasKey(string_key0));
512     EXPECT_TRUE(dict_sp->HasKey(string_key1));
513 
514     auto string_sp = dict_sp->GetValueForKey(string_key0)->GetAsString();
515     auto int_sp = dict_sp->GetValueForKey(string_key1)->GetAsInteger();
516 
517     EXPECT_STREQ(string_value0, string_sp->GetValue().c_str());
518     EXPECT_EQ(int_value1, int_sp->GetValue());
519 }
520 
521 TEST_F(PythonDataObjectsTest, TestPythonCallableCheck)
522 {
523     PythonObject sys_exc_info = m_sys_module.ResolveName("exc_info");
524     PythonObject none(PyRefType::Borrowed, Py_None);
525 
526     EXPECT_TRUE(PythonCallable::Check(sys_exc_info.get()));
527     EXPECT_FALSE(PythonCallable::Check(none.get()));
528 }
529 
530 TEST_F(PythonDataObjectsTest, TestPythonCallableInvoke)
531 {
532     auto list = m_builtins_module.ResolveName("list").AsType<PythonCallable>();
533     PythonInteger one(1);
534     PythonString two("two");
535     PythonTuple three = { one, two };
536 
537     PythonTuple tuple_to_convert = { one, two, three };
538     PythonObject result = list({ tuple_to_convert });
539 
540     EXPECT_TRUE(PythonList::Check(result.get()));
541     auto list_result = result.AsType<PythonList>();
542     EXPECT_EQ(3, list_result.GetSize());
543     EXPECT_EQ(one.get(), list_result.GetItemAtIndex(0).get());
544     EXPECT_EQ(two.get(), list_result.GetItemAtIndex(1).get());
545     EXPECT_EQ(three.get(), list_result.GetItemAtIndex(2).get());
546 }
547 
548 TEST_F(PythonDataObjectsTest, TestPythonFile)
549 {
550     File file(FileSystem::DEV_NULL, File::eOpenOptionRead);
551     PythonFile py_file(file, "r");
552     EXPECT_TRUE(PythonFile::Check(py_file.get()));
553 }
554 
555 TEST_F(PythonDataObjectsTest, TestObjectAttributes)
556 {
557     PythonInteger py_int(42);
558     EXPECT_TRUE(py_int.HasAttribute("numerator"));
559     EXPECT_FALSE(py_int.HasAttribute("this_should_not_exist"));
560 
561     PythonInteger numerator_attr = py_int.GetAttributeValue("numerator").AsType<PythonInteger>();
562     EXPECT_TRUE(numerator_attr.IsAllocated());
563     EXPECT_EQ(42, numerator_attr.GetInteger());
564 }