Skip to content

Commit 25ad9a7

Browse files
committed
Add tests.
1 parent 694a938 commit 25ad9a7

File tree

4 files changed

+192
-22
lines changed

4 files changed

+192
-22
lines changed

DSPythonNet3/DSPythonNet3Evaluator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using System.Collections;
3-
using System.Collections.Generic;
4-
using System.Linq;
53
using System.Reflection;
64
using Autodesk.DesignScript.Runtime;
75
using DSPythonNet3.Encoders;

DSPythonNet3Wheels/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ numpy == 2.*
88
pillow == 11.*
99
pyparsing == 3.*
1010
python-dateutil == 2.*
11-
pytz
1211
pandas == 2.*
1312
openpyxl == 3.*
1413
scipy == 1.*

DSpythonNet3Tests/DSPythonNet3Tests.csproj

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@
33
<PropertyGroup>
44
<IsPackable>false</IsPackable>
55
<IsTestProject>true</IsTestProject>
6+
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
7+
<AppendRuntimeIdentifierToOutputPath>true</AppendRuntimeIdentifierToOutputPath>
8+
<BuildOutput>$(MsBuildThisFileDirectory)bin</BuildOutput>
69
</PropertyGroup>
710

811
<ItemGroup>
9-
<PackageReference Include="coverlet.collector" Version="6.0.0" />
1012
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
1113
<PackageReference Include="NUnit" Version="3.14.0" />
1214
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
1315
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
1416

15-
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynamoPackageVersion)">
16-
<ExcludeAssets>runtime</ExcludeAssets>
17-
<IncludeAssets>compile; build; native; contentfiles; analyzers</IncludeAssets>
18-
</PackageReference>
19-
<PackageReference Include="DynamoVisualProgramming.Tests" Version="$(DynamoPackageVersion)">
20-
<ExcludeAssets>runtime</ExcludeAssets>
21-
<IncludeAssets>compile; build; native; contentfiles; analyzers</IncludeAssets>
22-
</PackageReference>
17+
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynamoPackageVersion)" />
18+
<PackageReference Include="DynamoVisualProgramming.DynamoServices" Version="$(DynamoPackageVersion)" />
2319
</ItemGroup>
2420

2521
<ItemGroup>
Lines changed: 187 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,203 @@
1-
using Dynamo;
1+
using DSPythonNet3;
22
using System.Collections;
33

4-
namespace DSPythonNet3
4+
namespace DSPythonNet3Tests
55
{
6-
public class PythonLibraryTests : DynamoModelTestBase
6+
public class PythonLibraryTests
77
{
8-
protected override void GetLibrariesToPreload(List<string> libraries)
9-
{
10-
libraries.Add("DSCoreNodes.dll");
11-
}
12-
138
[Test]
149
public void TestSciPyAvailable()
1510
{
1611
string code = @"
1712
from scipy import special
18-
1913
OUT = special.exp10(3)
2014
";
2115
var empty = new ArrayList();
2216
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
2317
Assert.That(result, Is.EqualTo(1000));
2418
}
19+
20+
[Test]
21+
public void TestContourPyAvailable()
22+
{
23+
string code = @"
24+
import numpy as np
25+
import contourpy
26+
27+
x = np.linspace(-2, 2, 20)
28+
y = np.linspace(-2, 2, 20)
29+
X, Y = np.meshgrid(x, y)
30+
Z = np.sin(X) * np.cos(Y)
31+
32+
contour_generator = contourpy.contour_generator(x, y, Z)
33+
lines = contour_generator.lines(0.0)
34+
OUT = len(lines)
35+
";
36+
var empty = new ArrayList();
37+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
38+
Assert.That(result, Is.EqualTo(3));
39+
}
40+
41+
[Test]
42+
public void TestCyclerAvailable()
43+
{
44+
string code = @"
45+
from cycler import cycler
46+
color_cycle = cycler(color=['r', 'g', 'b'])
47+
OUT = len(color_cycle)
48+
";
49+
var empty = new ArrayList();
50+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
51+
Assert.That(result, Is.EqualTo(3));
52+
}
53+
54+
[Test]
55+
public void TestEt_xmlfileAvailable()
56+
{
57+
string code = @"
58+
from io import BytesIO
59+
from xml.etree.ElementTree import Element
60+
from et_xmlfile import xmlfile
61+
62+
out = BytesIO()
63+
with xmlfile(out) as xf:
64+
el = Element(""root"")
65+
xf.write(el)
66+
67+
OUT = out.getvalue() == b""<root />""
68+
";
69+
var empty = new ArrayList();
70+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
71+
Assert.That(result, Is.EqualTo(true));
72+
}
73+
74+
[Test]
75+
public void TestFonttoolsAvailable()
76+
{
77+
string code = @"
78+
from fontTools.pens import svgPathPen
79+
pen = svgPathPen.SVGPathPen(None)
80+
pen.moveTo((0, 0))
81+
pen.lineTo((1, 1))
82+
OUT = pen.getCommands()
83+
";
84+
var empty = new ArrayList();
85+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
86+
Assert.That(result, Is.EqualTo("M0 0 1 1"));
87+
}
88+
89+
[Test]
90+
public void TestKiwisolverAvailable()
91+
{
92+
string code = @"
93+
import kiwisolver as kiwi
94+
95+
solver = kiwi.Solver()
96+
x = kiwi.Variable('x')
97+
solver.addConstraint(3 * x + 5 == 14)
98+
solver.updateVariables()
99+
OUT = x.value()
100+
";
101+
var empty = new ArrayList();
102+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
103+
Assert.That(result, Is.EqualTo(3));
104+
}
105+
106+
[Test]
107+
public void TestMatplotlibAvailable()
108+
{
109+
string code = @"
110+
import sys
111+
OUT = sys.version
112+
import unicodedata2
113+
#print(unicodedata.name('A'))
114+
115+
#import matplotlib as mpl
116+
117+
#cmap = mpl.colormaps['plasma']
118+
#OUT = cmap.name
119+
";
120+
var empty = new ArrayList();
121+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
122+
Assert.That(result, Is.EqualTo("plasma"));
123+
}
124+
125+
[Test]
126+
public void TestPillowAvailable()
127+
{
128+
string code = @"
129+
from PIL import Image, ImageDraw
130+
131+
image = Image.new('RGB', (100, 100), 'white')
132+
draw = ImageDraw.Draw(image)
133+
draw.rectangle((25, 25, 100, 100), fill='red')
134+
OUT = image.getpixel((50, 50))[0]
135+
";
136+
var empty = new ArrayList();
137+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
138+
Assert.That(result, Is.EqualTo(255));
139+
}
140+
141+
[Test]
142+
public void TestPyParsingAvailable()
143+
{
144+
string code = @"
145+
import pyparsing as pp
146+
147+
parser = pp.Word(pp.alphas) + ',' + pp.Word(pp.alphas)
148+
parsed = parser.parse_string('Hello, World')
149+
OUT = len(parsed)
150+
";
151+
var empty = new ArrayList();
152+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
153+
Assert.That(result, Is.EqualTo(3));
154+
}
155+
156+
[Test]
157+
public void TestPythonDateutilAvailable()
158+
{
159+
string code = @"
160+
from dateutil.parser import parse
161+
162+
date_string = 'Today is January 3, 2047 at 8:21:00AM'
163+
parsed_date = parse(date_string, fuzzy=True)
164+
OUT = parsed_date.day
165+
";
166+
var empty = new ArrayList();
167+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
168+
Assert.That(result, Is.EqualTo(3));
169+
}
170+
171+
[Test]
172+
public void TestPandasAvailable()
173+
{
174+
string code = @"
175+
import pandas as pd
176+
177+
ser = pd.Series(range(5), index=list('abcde'))
178+
OUT = ser['d']
179+
";
180+
var empty = new ArrayList();
181+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
182+
Assert.That(result, Is.EqualTo(3));
183+
}
184+
185+
[Test]
186+
public void TestOpenpyxlAvailable()
187+
{
188+
string code = @"
189+
from openpyxl import Workbook
190+
191+
wb = Workbook()
192+
ws = wb.active
193+
treeData = [['A', 'B', 'C'], [1, 2, 3]]
194+
for row in treeData:
195+
ws.append(row)
196+
OUT = ws['C2'].value
197+
";
198+
var empty = new ArrayList();
199+
var result = DSPythonNet3Evaluator.EvaluatePythonScript(code, empty, empty);
200+
Assert.That(result, Is.EqualTo(3));
201+
}
25202
}
26-
}
203+
}

0 commit comments

Comments
 (0)