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

Skip to content

Fixes breaking tests in .Net Core 2.0 #605

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 1 commit into from
Feb 16, 2018
Merged

Fixes breaking tests in .Net Core 2.0 #605

merged 1 commit into from
Feb 16, 2018

Conversation

Cronan
Copy link
Contributor

@Cronan Cronan commented Jan 25, 2018

Contributes to fixing the issues detailed in #590

@Cronan
Copy link
Contributor Author

Cronan commented Jan 25, 2018

@dmitriyse @denfromufa

@codecov
Copy link

codecov bot commented Jan 25, 2018

Codecov Report

Merging #605 into pytests-core will decrease coverage by 0.19%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##           pytests-core     #605     +/-   ##
===============================================
- Coverage         70.85%   70.66%   -0.2%     
===============================================
  Files                64       64             
  Lines              5607     5607             
  Branches            887      887             
===============================================
- Hits               3973     3962     -11     
- Misses             1343     1352      +9     
- Partials            291      293      +2
Flag Coverage Δ
#setup_linux 69.42% <ø> (ø) ⬆️
#setup_windows 69.84% <ø> (-0.2%) ⬇️
Impacted Files Coverage Δ
src/runtime/assemblymanager.cs 79.56% <0%> (-2.69%) ⬇️
src/runtime/moduleobject.cs 68.96% <0%> (-2.3%) ⬇️
src/runtime/importhook.cs 77.62% <0%> (-0.7%) ⬇️
src/runtime/classmanager.cs 92.25% <0%> (-0.65%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f018085...80eb41b. Read the comment docs.

@den-run-ai
Copy link
Contributor

@Cronan just tested this PR on Windows and getting 6 failures:

Click here to expand the pytest results
C:\Python\pythonnet\pythonnet>dotnet build\lib.win-amd64-3.5\netcoreapp2.0\nPython.dll
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> import sys
>>> sys.path.append(r"C:\Python\pythonnet\pythonnet\build\lib.win-amd64-3.5\netcoreapp2.0")
>>> import pytest
>>> pytest.main()
============================= test session starts =============================
platform win32 -- Python 3.5.3, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: C:\Python\pythonnet\pythonnet, inifile: setup.cfg
collected 293 items

src\tests\test_array.py ........................................
src\tests\test_callback.py ..
src\tests\test_class.py ..................
src\tests\test_clrmethod.py FFFFF
src\tests\test_compat.py ................
src\tests\test_constructors.py ....
src\tests\test_conversion.py ....................
src\tests\test_docstring.py ...
src\tests\test_engine.py .ss
src\tests\test_enum.py ...............
src\tests\test_exceptions.py .........................
src\tests\test_field.py ..............................
src\tests\test_generic.py .................
src\tests\test_import.py .
src\tests\test_indexer.py .............................
src\tests\test_interface.py ....
src\tests\test_method.py ..............................................
src\tests\test_property.py ..........
src\tests\test_recursive_types.py .
src\tests\test_sysargv.py F
src\tests\test_thread.py ...
=========================== short test summary info ===========================
FAIL src/tests/test_clrmethod.py::test_set_and_get_property_from_py
FAIL src/tests/test_clrmethod.py::test_set_and_get_property_from_clr
FAIL src/tests/test_clrmethod.py::test_set_and_get_property_from_clr_and_py
FAIL src/tests/test_clrmethod.py::test_method_invocation_from_py
FAIL src/tests/test_clrmethod.py::test_method_invocation_from_clr
FAIL src/tests/test_sysargv.py::test_sys_argv_state
SKIP [1] src\tests\test_engine.py:29: FIXME: test freezes
SKIP [1] src\tests\test_engine.py:21: FIXME: test crashes

========================== slowest 5 test durations ===========================
1.11s call     src/tests/test_thread.py::test_python_thread_calls_to_clr
0.29s call     src/tests/test_compat.py::test_multiple_imports
0.20s call     src/tests/test_sysargv.py::test_sys_argv_state
0.18s call     src/tests/test_callback.py::test_default_for_null
0.12s call     src/tests/test_exceptions.py::test_str_of_exception
================================== FAILURES ===================================
______________________ test_set_and_get_property_from_py ______________________

    def test_set_and_get_property_from_py():
        """Test setting and getting clr-accessible properties from python."""
>       t = ExampleClrClass()
E       TypeError: no constructor matches given arguments

src\tests\test_clrmethod.py:30: TypeError
_____________________ test_set_and_get_property_from_clr ______________________

    def test_set_and_get_property_from_clr():
        """Test setting and getting clr-accessible properties from the clr."""
>       t = ExampleClrClass()
E       TypeError: no constructor matches given arguments

src\tests\test_clrmethod.py:39: TypeError
__________________ test_set_and_get_property_from_clr_and_py __________________

    def test_set_and_get_property_from_clr_and_py():
        """Test setting and getting clr-accessible properties alternatingly from the clr and from python."""
>       t = ExampleClrClass()
E       TypeError: no constructor matches given arguments

src\tests\test_clrmethod.py:49: TypeError
_______________________ test_method_invocation_from_py ________________________

    def test_method_invocation_from_py():
        """Test calling a clr-accessible method from python."""
>       t = ExampleClrClass()
E       TypeError: no constructor matches given arguments

src\tests\test_clrmethod.py:67: TypeError
_______________________ test_method_invocation_from_clr _______________________

    def test_method_invocation_from_clr():
        """Test calling a clr-accessible method from the clr."""
>       t = ExampleClrClass()
E       TypeError: no constructor matches given arguments

src\tests\test_clrmethod.py:72: TypeError
_____________________________ test_sys_argv_state _____________________________

filepath = <function filepath.<locals>.make_filepath at 0x00000230BAD92158>

    def test_sys_argv_state(filepath):
        """Test sys.argv state doesn't change after clr import.
        To better control the arguments being passed, test on a fresh python
        instance with specific arguments"""

        script = filepath("argv-fixture.py")
>       out = check_output([sys.executable, script, "foo", "bar"])

src\tests\test_sysargv.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src\tests\_compat.py:71: in check_output
    output = subprocess.check_output(*args, **kwargs)
..\..\Python35_64b\Lib\subprocess.py:316: in check_output
    **kwargs).stdout
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input = None, timeout = None, check = True
popenargs = (['C:\\Program Files\\dotnet\\dotnet.exe', 'C:\\Python\\pythonnet\\pythonnet\\src\\tests\\fixtures/netstandard2.0\\argv-fixture.py', 'foo', 'bar'],)
kwargs = {'stdout': -1}
process = <subprocess.Popen object at 0x00000230BAFC46A0>, stdout = b''
stderr = None, retcode = 1

    def run(*popenargs, input=None, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.

        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.

        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.

        There is an optional argument "input", allowing you to
        pass a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.

        The other arguments are the same as for the Popen constructor.

        If universal_newlines=True is passed, the "input" argument must be a
        string and stdout/stderr in the returned object will be strings rather than
        bytes.
        """
        if input is not None:
            if 'stdin' in kwargs:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE

        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired:
                process.kill()
                stdout, stderr = process.communicate()
                raise TimeoutExpired(process.args, timeout, output=stdout,
                                     stderr=stderr)
            except:
                process.kill()
                process.wait()
                raise
            retcode = process.poll()
            if check and retcode:
                raise CalledProcessError(retcode, process.args,
>                                        output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '['C:\\Program Files\\dotnet\\dotnet.exe', 'C:\\Python\\pythonnet\\pythonnet\\src\\tests\\fixtures/netstandard2.0\\argv-fixture.py', 'foo', 'bar']' returned non-zero exit status 1

..\..\Python35_64b\Lib\subprocess.py:398: CalledProcessError
---------------------------- Captured stderr call -----------------------------
No executable found matching command "dotnet-C:\Python\pythonnet\pythonnet\src\tests\fixtures/netstandard2.0\argv-fixture.py"
=============== 6 failed, 285 passed, 2 skipped in 7.18 seconds ===============

@dmitriyse
Copy link
Contributor

dmitriyse commented Jan 29, 2018

@Cronan, IMHO, switching tests to the .net standard 2.0 classes is a good idea in general, but I want to found a way to link some extra nuget in py tests, to test engine assembly loading solution (that is not implemented yet for .net standard 2.0). For example System.Drawing.Primitives nuget, so some test need not to be modified.

@den-run-ai
Copy link
Contributor

den-run-ai commented Jan 29, 2018

@dmitriyse i tried debugging these TypeError: no constructor matches given arguments errors in tests for .NET Core in VS 2017, but all the breakpoints are skipped in constructorbinder.cs, even if I force Debugger.Launch() in the code. Instead I'm only able to debug Console.15.csproj code for nPython assembly. I tried various combinations of debugger engines. This is probably because there is a lot of layers of embedding with .NET Core console, nPython, CPython, clr.py resource, etc.

I suggest that we disable these subclassing tests when under .NET Core, until clr.pyd/clr.so is ready for .NET Core mode.

@den-run-ai
Copy link
Contributor

I meant Console.15.csproj, not clrmodule.15.csproj above.

@Cronan
Copy link
Contributor Author

Cronan commented Jan 29, 2018

@denfromufa I get these failures too, but then I got them before I made the other changes.
Is everyone happy for me to skip the subclassing tests? (also, how to test running under .Net Core from the python tests?)

@Cronan
Copy link
Contributor Author

Cronan commented Jan 29, 2018

@dmitriyse What about adding some tests into test_compat to cover engine assembly loading?

@Cronan
Copy link
Contributor Author

Cronan commented Feb 8, 2018

@dmitriyse @denfromufa So should I close this if it's not acceptable?

@den-run-ai
Copy link
Contributor

@Cronan this PR looks good to me, please skip the failing tests conditionally under .net core @dmitriyse are you ok with this PR? I'M OK with dropping System.Drawing, even if it is available via nuget

@dmitriyse
Copy link
Contributor

System.Drawing can be excluded, but Non Generic collections should definetely works (even I am personally hate this legacy subsystem).
Everything else than Non Generic collections can be merged.

@den-run-ai
Copy link
Contributor

@dmitriyse can you please be more specific about non-generic collections? I did find any issue. Do you mean you are not OK with switch from HashTable to ArrayList?

@dmitriyse
Copy link
Contributor

dmitriyse commented Feb 8, 2018

Yes, exactly this change. We should work fine with all classes:
System.Collections.ArrayList
System.Collections.Hashtable
System.Collections.CollectionBase
System.Collections.ReadOnlyCollectionBase
System.Collections.Stack
System.Collections.SortedList
System.Collections.DictionaryBase
System.Collections.Queue
System.Collections.Comparer
System.Collections.CaseInsensitiveComparer

That were moved out in the NetStandard 2.0 from core to nuget https://www.nuget.org/packages/System.Collections.NonGeneric

@den-run-ai
Copy link
Contributor

@dmitriyse the point of this test is not testing all non-generic collections, but only testing test_basic_subclass, so I'm ok with ArrayList in this PR.

So I'm approving this PR, we can add skipping failing tests later once .NET Core support is stabilized and in CI.

@Cronan
Copy link
Contributor Author

Cronan commented Feb 16, 2018

Anymore for any more? @dmitriyse @filmor @vmuriart

@den-run-ai den-run-ai merged commit 77c3216 into pythonnet:pytests-core Feb 16, 2018
@den-run-ai
Copy link
Contributor

@Cronan can you submit this PR against the main branch? Why is this in pytests-core branch?

@Cronan
Copy link
Contributor Author

Cronan commented Feb 17, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants