Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4be925f

Browse files
author
Rickard Holmberg
committed
Move the tests from test_runtime.py to TestRuntime.py
1 parent 1a85eef commit 4be925f

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

src/embed_tests/TestRuntime.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using NUnit.Framework;
33
using Python.Runtime;
44

@@ -47,5 +47,46 @@ public static void RefCountTest()
4747

4848
Runtime.Runtime.Py_Finalize();
4949
}
50+
51+
[Test]
52+
public static void PyCheck_Iter_PyObject_IsIterable_Test()
53+
{
54+
Runtime.Runtime.Py_Initialize();
55+
56+
// Tests that a python list is an iterable, but not an iterator
57+
var pyList = Runtime.Runtime.PyList_New(0);
58+
Assert.IsFalse(Runtime.Runtime.PyIter_Check(pyList));
59+
Assert.IsTrue(Runtime.Runtime.PyObject_IsIterable(pyList));
60+
61+
// Tests that a python list iterator is both an iterable and an iterator
62+
var pyListIter = Runtime.Runtime.PyObject_GetIter(pyList);
63+
Assert.IsTrue(Runtime.Runtime.PyObject_IsIterable(pyListIter));
64+
Assert.IsTrue(Runtime.Runtime.PyIter_Check(pyListIter));
65+
66+
// Tests that a python float is neither an iterable nor an iterator
67+
var pyFloat = Runtime.Runtime.PyFloat_FromDouble(2.73);
68+
Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(pyFloat));
69+
Assert.IsFalse(Runtime.Runtime.PyIter_Check(pyFloat));
70+
71+
Runtime.Runtime.Py_Finalize();
72+
}
73+
74+
[Test]
75+
public static void PyCheck_Iter_PyObject_IsIterable_ThreadingLock_Test()
76+
{
77+
Runtime.Runtime.Py_Initialize();
78+
79+
// Create an instance of threading.Lock, which is one of the very few types that does not have the
80+
// TypeFlags.HaveIter set in Python 2. This tests a different code path in PyObject_IsIterable and PyIter_Check.
81+
var threading = Runtime.Runtime.PyImport_ImportModule("threading");
82+
var threadingDict = Runtime.Runtime.PyModule_GetDict(threading);
83+
var lockType = Runtime.Runtime.PyDict_GetItemString(threadingDict, "Lock");
84+
var lockInstance = Runtime.Runtime.PyObject_CallObject(lockType, Runtime.Runtime.PyTuple_New(0));
85+
86+
Assert.IsFalse(Runtime.Runtime.PyObject_IsIterable(lockInstance));
87+
Assert.IsFalse(Runtime.Runtime.PyIter_Check(lockInstance));
88+
89+
Runtime.Runtime.Py_Finalize();
90+
}
5091
}
5192
}

src/tests/test_runtime.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)