Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66716db

Browse files
committed
PyScope/PyModule cleanup
removed PyScopeManagermerged PyScope into PyModuleminor behavioral changes
1 parent8846fd2 commit66716db

File tree

10 files changed

+529
-828
lines changed

10 files changed

+529
-828
lines changed

‎CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ details about the cause of the failure
4444
- floating point values passed from Python are no longer silently truncated
4545
when .NET expects an integer[#1342][i1342]
4646
- More specific error messages for method argument mismatch
47+
- BREAKING: most`PyScope` methods will never return`null`. Instead,`PyObject``None` will be returned.
48+
- BREAKING:`PyScope` was renamed to`PyModule`
4749
- BREAKING: Methods with`ref` or`out` parameters and void return type return a tuple of only the`ref` and`out` parameters.
4850
- BREAKING: to call Python from .NET`Runtime.PythonDLL` property must be set to Python DLL name
4951
or the DLL must be loaded in advance. This must be done before calling any other Python.NET functions.
@@ -97,6 +99,7 @@ Instead, `PyIterable` does that.
9799

98100
- implicit assembly loading (you have to explicitly`clr.AddReference` before doing import)
99101
- messages in`PythonException` no longer start with exception type
102+
-`PyScopeManager`,`PyScopeException`,`PyScope` (use`PyModule` instead)
100103
- support for .NET Framework 4.0-4.6; Mono before 5.4. Python.NET now requires .NET Standard 2.0
101104
(see[the matrix](https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support))
102105

‎src/embed_tests/TestPyScope.csrenamed to‎src/embed_tests/Modules.cs

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
namespacePython.EmbeddingTest
77
{
8-
publicclassPyScopeTest
8+
publicclassModules
99
{
10-
privatePyScopeps;
10+
privatePyModuleps;
1111

1212
[SetUp]
1313
publicvoidSetUp()
1414
{
1515
using(Py.GIL())
1616
{
1717
ps=Py.CreateScope("test");
18-
}
18+
}
1919
}
2020

2121
[TearDown]
@@ -28,6 +28,18 @@ public void Dispose()
2828
}
2929
}
3030

31+
[OneTimeSetUp]
32+
publicvoidOneTimeSetUp()
33+
{
34+
PythonEngine.Initialize();
35+
}
36+
37+
[OneTimeTearDown]
38+
publicvoidOneTimeTearDown()
39+
{
40+
PythonEngine.Shutdown();
41+
}
42+
3143
/// <summary>
3244
/// Eval a Python expression and obtain its return value.
3345
/// </summary>
@@ -243,7 +255,7 @@ public void TestImportScopeFunction()
243255
"def func1():\n"+
244256
" return cc + bb\n");
245257

246-
using(PyScopescope=ps.NewScope())
258+
using(varscope=ps.NewScope())
247259
{
248260
//'func1' is imported from the origion scope
249261
scope.Exec(
@@ -267,27 +279,6 @@ public void TestImportScopeFunction()
267279
}
268280
}
269281

270-
/// <summary>
271-
/// Import a python module into the session with a new name.
272-
/// Equivalent to the Python "import .. as .." statement.
273-
/// </summary>
274-
[Test]
275-
publicvoidTestImportScopeByName()
276-
{
277-
using(Py.GIL())
278-
{
279-
ps.Set("bb",100);
280-
281-
using(varscope=Py.CreateScope())
282-
{
283-
scope.ImportAll("test");
284-
//scope.ImportModule("test");
285-
286-
Assert.IsTrue(scope.Contains("bb"));
287-
}
288-
}
289-
}
290-
291282
/// <summary>
292283
/// Use the locals() and globals() method just like in python module
293284
/// </summary>
@@ -381,5 +372,34 @@ public void TestThread()
381372
PythonEngine.EndAllowThreads(ts);
382373
}
383374
}
375+
376+
[Test]
377+
publicvoidTestCreate()
378+
{
379+
usingvarscope=Py.CreateScope();
380+
381+
Assert.IsFalse(PyModule.SysModules.HasKey("testmod"));
382+
383+
PyModuletestmod=newPyModule("testmod");
384+
385+
testmod.SetAttr("testattr1","True".ToPython());
386+
387+
PyModule.SysModules.SetItem("testmod",testmod);
388+
389+
usingPyObjectcode=PythonEngine.Compile(
390+
"import testmod\n"+
391+
"x = testmod.testattr1"
392+
);
393+
scope.Execute(code);
394+
395+
Assert.IsTrue(scope.TryGet("x",outdynamicx));
396+
Assert.AreEqual("True",x.ToString());
397+
}
398+
399+
[Test]
400+
publicvoidImportClrNamespace()
401+
{
402+
Py.Import(GetType().Namespace);
403+
}
384404
}
385405
}

‎src/embed_tests/TestPyModule.cs

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

‎src/embed_tests/pyinitialize.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,6 @@ public void ReInitialize()
9595
PythonEngine.Shutdown();
9696
}
9797

98-
[Test]
99-
publicvoidTestScopeIsShutdown()
100-
{
101-
PythonEngine.Initialize();
102-
varscope=PyScopeManager.Global.Create("test");
103-
PythonEngine.Shutdown();
104-
Assert.That(PyScopeManager.Global.Contains("test"),Is.False);
105-
}
106-
10798
/// <summary>
10899
/// Helper for testing the shutdown handlers.
109100
/// </summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp