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

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix test
  • Loading branch information
filmor committed Oct 16, 2023
commit ae0b7606b575a8d6f7d0afd2cd1ba734e48c447b
22 changes: 10 additions & 12 deletions src/embed_tests/Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,29 @@ public void TestCreateVirtualPackageStructure()
{
using (Py.GIL())
{
//parent module
PyModule.FromString("test", "");
//sub-module
PyModule.FromString("test.scope",
"class Class1():\n" +
using var _p1 = PyModule.FromString("test", "");
// Sub-module
using var _p2 = PyModule.FromString("test.scope",
"class Class1():\n" +
" def __init__(self, value):\n" +
" self.value = value\n" +
" def call(self, arg):\n" +
" return self.value + bb + arg\n" + // use scope variables
" def update(self, arg):\n" +
" global bb\n" +
" bb = self.value + arg\n" // update scope variable
, "test"
" bb = self.value + arg\n", // update scope variable
"test"
);

dynamic ps2 = Py.Import("test.scope");
ps2.bb = 100;

dynamic _ps = Py.Import("test.scope");
_ps.bb = 100;

dynamic obj1 = _ps.Class1(20);
dynamic obj1 = ps2.Class1(20);
var result = obj1.call(10).As<int>();
Assert.AreEqual(130, result);

obj1.update(10);
result = ps.Get<int>("bb");
result = ps2.Get<int>("bb");
Assert.AreEqual(30, result);
}
}
Expand Down