diff --git a/src/embed_tests/pyimport.cs b/src/embed_tests/pyimport.cs index e4ba8d546..dc9d90fe2 100644 --- a/src/embed_tests/pyimport.cs +++ b/src/embed_tests/pyimport.cs @@ -1,9 +1,7 @@ using System; -using System.Reflection; -using System.Collections.Generic; +using System.IO; using NUnit.Framework; using Python.Runtime; -using System.IO; namespace Python.EmbeddingTest { @@ -55,5 +53,15 @@ public void TestDottedName() PyObject module = PythonEngine.ImportModule("PyImportTest.test.one"); Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED"); } + + /// + /// Tests that sys.args is set. If it wasn't exception would be raised. + /// + [Test] + public void TestSysArgsImportException() + { + PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv"); + Assert.IsNotNull(module, ">>> import PyImportTest.sysargv # FAILED"); + } } } diff --git a/src/tests/PyImportTest/sysargv.py b/src/tests/PyImportTest/sysargv.py new file mode 100644 index 000000000..2e1508bff --- /dev/null +++ b/src/tests/PyImportTest/sysargv.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +import sys +# if argv is available, as expected, then no exception +num_args = len(sys.argv) diff --git a/src/tests/runtests.py b/src/tests/runtests.py index 9b77f99dd..92d9ecbd0 100644 --- a/src/tests/runtests.py +++ b/src/tests/runtests.py @@ -23,6 +23,9 @@ clr.AddReference("System.Management") test_modules = ( + # has to be first test before other module import clr + 'test_sysargv', + # test_module passes on its own, but not here if # other test modules that import System.Windows.Forms # run first. They must not do module level import/AddReference() diff --git a/src/tests/test_sysargv.py b/src/tests/test_sysargv.py new file mode 100644 index 000000000..eefb4d341 --- /dev/null +++ b/src/tests/test_sysargv.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +import unittest +import sys + +class SysArgvTests(unittest.TestCase): + """Test sys.argv state.""" + + def test_sys_argv_state(self): + """Test sys.argv state doesn't change after clr import.""" + argv = sys.argv + import clr + self.assertTrue(argv == sys.argv) + + +def test_suite(): + return unittest.makeSuite(SysArgvTests) diff --git a/src/tests/tests.pyproj b/src/tests/tests.pyproj index cf8f74a4a..5d042249e 100644 --- a/src/tests/tests.pyproj +++ b/src/tests/tests.pyproj @@ -29,12 +29,14 @@ + +