8000 Add sys.args tests (#301) · pythonnet/pythonnet@79eeb61 · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit 79eeb61

Browse files
denfromufavmuriart
denfromufa
authored andcommitted
Add sys.args tests (#301)
1 parent 8afd512 commit 79eeb61

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

src/embed_tests/pyimport.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.Reflection;
3-
using System.Collections.Generic;
2+
using System.IO;
43
using NUnit.Framework;
54
using Python.Runtime;
6-
using System.IO;
75

86
namespace Python.EmbeddingTest
97
{
@@ -55,5 +53,15 @@ public void TestDottedName()
5553
PyObject module = PythonEngine.ImportModule("PyImportTest.test.one");
5654
Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED");
5755
}
56+
57+
/// <summary>
58+
/// Tests that sys.args is set. If it wasn't exception would be raised.
59+
/// </summary>
60+
[Test]
61+
public void TestSysArgsImportException()
62+
{
63+
PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv");
64+
Assert.IsNotNull(module, ">>> import PyImportTest.sysargv # FAILED");
65+
}
5866
}
5967
}

src/tests/PyImportTest/sysargv.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys
4+
# if argv is available, as expected, then no exception
5+
num_args = len(sys.argv)

src/tests/runtests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
clr.AddReference("System.Management")
2424

2525
test_modules = (
26+
# has to be first test before other module import clr
27+
'test_sysargv',
28+
2629
# test_module passes on its own, but not here if
2730
# other test modules that import System.Windows.Forms
2831
# run first. They must not do module level import/AddReference()

src/tests/test_sysargv.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
import sys
5+
6+
class SysArgvTests(unittest.TestCase):
7+
"""Test sys.argv state."""
8+
9+
def test_sys_argv_state(self):
10+
"""Test sys.argv state doesn't change after clr import."""
11+
argv = sys.argv
12+
import clr
13+
self.assertTrue(argv == sys.argv)
14+
15+
16+
def test_suite():
17+
return unittest.makeSuite(SysArgvTests)

src/tests/tests.pyproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
<ItemGroup>
3030
<Compile Include="leaktest.py" />
3131
<Compile Include="profile.py" />
32+
<Compile Include="PyImportTest\sysargv.py" />
3233
<Compile Include="PyImportTest\test\one.py" />
3334
<Compile Include="PyImportTest\test\__init__.py" />
3435
<Compile Include="PyImportTest\__init__.py" />
3536
<Compile Include="runtests.py" />
3637
<Compile Include="stress.py" />
3738
<Compile Include="stresstest.py" />
39+
<Compile Include="test_sysargv.py" />
3840
<Compile Include="test_array.py" />
3941
<Compile Include="test_class.py" />
4042
<Compile Include="test_compat.py" />

0 commit comments

Comments
 (0)
0