GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pythonnet/src/embed_tests/TestPyTuple.cs at master · pythonnet/pythonnet Expand file tree/ Copy pathTestPyTuple.csMore file actions 157 lines (131 loc) · 4.25 KB / Copy pathTestPyTuple.csFile metadata and controls157 lines (131 loc) · 4.25 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 using System; using NUnit.Framework; using Python.Runtime; namespace Python.EmbeddingTest { public class TestPyTuple { /// <summary> /// Test IsTupleType without having to Initialize a tuple. /// PyTuple constructor use IsTupleType. This decouples the tests. /// </summary> [Test] public void TestStringIsTupleType() { var s = new PyString("foo"); Assert.False(PyTuple.IsTupleType(s)); } /// <summary> /// Test IsTupleType with Tuple. /// </summary> [Test] public void TestPyTupleIsTupleType() { var t = new PyTuple(); Assert.True(PyTuple.IsTupleType(t)); } [Test] public void TestPyTupleEmpty() { var t = new PyTuple(); Assert.That(t.Length(), Is.EqualTo(0)); } [Test] public void TestPyTupleBadCtor() { var i = new PyInt(5); PyTuple t = null; var ex = Assert.Throws<ArgumentException>(() => t = new PyTuple(i)); Assert.That(ex.Message, Is.EqualTo("object is not a tuple")); Assert.IsNull(t); } [Test] public void TestPyTupleCtorEmptyArray() { var a = new PyObject[] { }; var t = new PyTuple(a); Assert.That(t.Length(), Is.EqualTo(0)); } [Test] public void TestPyTupleCtorArrayPyIntEmpty() { var a = new PyInt[] { }; var t = new PyTuple(a); Assert.That(t.Length(), Is.EqualTo(0)); } [Test] public void TestPyTupleCtorArray() { var a = new PyObject[] { new PyInt(1), new PyString("Foo") }; var t = new PyTuple(a); Assert.That(t.Length(), Is.EqualTo(2)); } /// <summary> /// Test PyTuple.Concat(...) doesn't let invalid appends happen /// and throws and exception. /// </summary> /// <remarks> /// Test has second purpose. Currently it generated an Exception /// that the GC failed to remove often and caused AppDomain unload /// errors at the end of tests. See GH#397 for more info. /// </remarks> [Test] public void TestPyTupleInvalidAppend() { PyObject s = new PyString("foo"); var t = new PyTuple(); var ex = Assert.Throws<PythonException>(() => t.Concat(s)); StringAssert.StartsWith("can only concatenate tuple", ex.Message); Assert.That(t.Length(), Is.EqualTo(0)); Assert.IsEmpty(t); } [Test] public void TestPyTupleValidAppend() { var t0 = new PyTuple(); var t = new PyTuple(); t.Concat(t0); Assert.IsNotNull(t); Assert.IsInstanceOf(typeof(PyTuple), t); } [Test] public void TestPyTupleStringConvert() { PyObject s = new PyString("foo"); PyTuple t = PyTuple.AsTuple(s); Assert.IsNotNull(t); Assert.IsInstanceOf(typeof(PyTuple), t); Assert.That(t[0].ToString(), Is.EqualTo("f")); Assert.That(t[1].ToString(), Is.EqualTo("o")); Assert.That(t[2].ToString(), Is.EqualTo("o")); } [Test] public void TestPyTupleValidConvert() { var l = new PyList(); PyTuple t = PyTuple.AsTuple(l); Assert.IsNotNull(t); Assert.IsInstanceOf(typeof(PyTuple), t); } [Test] public void TestNewPyTupleFromPyTuple() { var t0 = new PyTuple(); var t = new PyTuple(t0); Assert.IsNotNull(t); Assert.IsInstanceOf(typeof(PyTuple), t); } /// <remarks> /// TODO: Should this throw ArgumentError instead? /// </remarks> [Test] public void TestInvalidAsTuple() { var i = new PyInt(5); PyTuple t = null; var ex = Assert.Throws<PythonException>(() => t = PyTuple.AsTuple(i)); Assert.That(ex.Message, Is.EqualTo("'int' object is not iterable")); Assert.IsNull(t); } } } |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |