Skip to content

Ensure that sys.argv is set #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -55,5 +53,15 @@ public void TestDottedName()
PyObject module = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED");
}

/// <summary>
/// Tests that sys.args is set. If it wasn't exception would be raised.
/// </summary>
[Test]
public void TestSysArgsImportException()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.sysargv");
Assert.IsNotNull(module, ">>> import PyImportTest.sysargv # FAILED");
}
}
}
5 changes: 5 additions & 0 deletions src/tests/PyImportTest/sysargv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-

import sys
# if argv is available, as expected, then no exception
num_args = len(sys.argv)
3 changes: 3 additions & 0 deletions src/tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions src/tests/test_sysargv.py
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be argv = list(sys.argv) - need to make a copy

import clr
self.assertTrue(argv == sys.argv)


def test_suite():
return unittest.makeSuite(SysArgvTests)
2 changes: 2 additions & 0 deletions src/tests/tests.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
<ItemGroup>
<Compile Include="leaktest.py" />
<Compile Include="profile.py" />
<Compile Include="PyImportTest\sysargv.py" />
<Compile Include="PyImportTest\test\one.py" />
<Compile Include="PyImportTest\test\__init__.py" />
<Compile Include="PyImportTest\__init__.py" />
<Compile Include="runtests.py" />
<Compile Include="stress.py" />
<Compile Include="stresstest.py" />
<Compile Include="test_sysargv.py" />
<Compile Include="test_array.py" />
<Compile Include="test_class.py" />
<Compile Include="test_compat.py" />
Expand Down