Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Add sys.args tests
  • Loading branch information
den-run-ai authored and vmuriart committed Feb 8, 2017
commit 2d6f3714dc90f7ada0977a087b2a36054c4528a0
6 changes: 4 additions & 2 deletions src/embed_tests/pyimport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public void TearDown()
[Test]
public void TestDottedName()
{
PyObject module = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module, ">>> import PyImportTest.test.one # FAILED");
PyObject module1 = PythonEngine.ImportModule("PyImportTest.test.one");
Assert.IsNotNull(module1, ">>> import PyImportTest.test.one # FAILED");
PyObject module2 = PythonEngine.ImportModule("PyImportTest.sysargv");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this should be its own test, not part of the previous one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agreed, let me move it

Assert.IsNotNull(module2, ">>> 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
Copy Markdown
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this doesn't make sense. Did importing clr previous cause sys.argv to change? Other tests import clr before this test, that may change being too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is to ensure that importing clr does not mess sys.argv, when it is not empty. what do you mean by "that may change being too."?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have no idea what I was trying to write... I meant to say, that since other tests are doing import clr before this test, the library is already loaded into memory and won't be reimported and the import clr statement may do nothing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh, that is a great point! then this needs to be the first test in the test runner before clr is loaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clr is loaded before all tests being. its the 5th line on run_tests.py i think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this was missed, still importing clr before setargv test



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