GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pythonnet/src/embed_tests/TestPyList.cs at master · pythonnet/pythonnet

Expand file tree

/

TestPyList.cs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
160 lines (131 loc) · 4.41 KB
/

TestPyList.cs

Copy path

File metadata and controls

160 lines (131 loc) · 4.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
158
159
160
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class TestPyList
{
[Test]
public void TestStringIsListType()
{
var s = new PyString("foo");
Assert.False(PyList.IsListType(s));
}
[Test]
public void TestListIsListType()
{
var s = new PyList();
Assert.True(PyList.IsListType(s));
}
[Test]
public void TestStringAsListType()
{
var i = new PyInt(5);
PyList t = null;
var ex = Assert.Throws<PythonException>(() => t = PyList.AsList(i));
Assert.That(ex.Message, Is.EqualTo("'int' object is not iterable"));
Assert.IsNull(t);
}
[Test]
public void TestListAsListType()
{
var l = new PyList();
PyList t = PyList.AsList(l);
Assert.IsNotNull(t);
Assert.IsInstanceOf(typeof(PyList), t);
}
[Test]
public void TestEmptyCtor()
{
var s = new PyList();
Assert.IsInstanceOf(typeof(PyList), s);
Assert.That(s.Length(), Is.EqualTo(0));
}
[Test]
public void TestPyObjectArrayCtor()
{
var ai = new PyObject[] {new PyInt(3), new PyInt(2), new PyInt(1) };
var s = new PyList(ai);
Assert.IsInstanceOf(typeof(PyList), s);
Assert.That(s.Length(), Is.EqualTo(3));
Assert.That(s[0].ToString(), Is.EqualTo("3"));
Assert.That(s[1].ToString(), Is.EqualTo("2"));
Assert.That(s[2].ToString(), Is.EqualTo("1"));
}
[Test]
public void TestPyObjectCtor()
{
var a = new PyList();
var s = new PyList(a);
Assert.IsInstanceOf(typeof(PyList), s);
Assert.That(s.Length(), Is.EqualTo(0));
}
[Test]
public void TestBadPyObjectCtor()
{
var i = new PyInt(5);
PyList t = null;
var ex = Assert.Throws<ArgumentException>(() => t = new PyList(i));
Assert.That(ex.Message, Is.EqualTo("object is not a list"));
Assert.IsNull(t);
}
[Test]
public void TestAppend()
{
var ai = new PyObject[] { new PyInt(3), new PyInt(2), new PyInt(1) };
var s = new PyList(ai);
s.Append(new PyInt(4));
Assert.That(s.Length(), Is.EqualTo(4));
Assert.That(s[3].ToString(), Is.EqualTo("4"));
}
[Test]
public void TestInsert()
{
var ai = new PyObject[] { new PyInt(3), new PyInt(2), new PyInt(1) };
var s = new PyList(ai);
s.Insert(0, new PyInt(4));
Assert.That(s.Length(), Is.EqualTo(4));
Assert.That(s[0].ToString(), Is.EqualTo("4"));
}
[Test]
public void TestReverse()
{
var ai = new PyObject[] { new PyInt(3), new PyInt(1), new PyInt(2) };
var s = new PyList(ai);
s.Reverse();
Assert.That(s.Length(), Is.EqualTo(3));
Assert.That(s[0].ToString(), Is.EqualTo("2"));
Assert.That(s[1].ToString(), Is.EqualTo("1"));
Assert.That(s[2].ToString(), Is.EqualTo("3"));
}
[Test]
public void TestSort()
{
var ai = new PyObject[] { new PyInt(3), new PyInt(1), new PyInt(2) };
var s = new PyList(ai);
s.Sort();
Assert.That(s.Length(), Is.EqualTo(3));
Assert.That(s[0].ToString(), Is.EqualTo("1"));
Assert.That(s[1].ToString(), Is.EqualTo("2"));
Assert.That(s[2].ToString(), Is.EqualTo("3"));
}
[Test]
public void TestOnPyList()
{
var list = new PyList();
list.Append(new PyString("foo"));
list.Append(new PyString("bar"));
list.Append(new PyString("baz"));
var result = new List<string>();
foreach (PyObject item in list)
{
result.Add(item.ToString());
}
Assert.That(result.Count, Is.EqualTo(3));
Assert.That(result[0], Is.EqualTo("foo"));
Assert.That(result[1], Is.EqualTo("bar"));
Assert.That(result[2], Is.EqualTo("baz"));
}
}
}
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.