Skip to content

Unit test updates - #2

Merged
slide merged 16 commits into
IronLanguages:masterfrom
slide:ironpython_unittest_updates
Jun 2, 2017
Merged

slide merged 16 commits into
IronLanguages:masterfrom
slide:ironpython_unittest_updates

Conversation

@slide

@slide slide commented May 25, 2017

Copy link
Copy Markdown
Contributor

Updates to IronPython specific unit tests to use the unittest

@slozier slozier left a comment

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.

Wow, good work. I'm going to have to go through this a few times.

Are the commented out tests things you still need to work on?

Comment thread Tests/test_assert.py
AreEqual(0, launch_ironpython_changing_extensions(__file__, remove=["-O"]))
else:
run_test(__name__)
# if is_cli and '-O' in System.Environment.GetCommandLineArgs():

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.

Could we retain this check in some form and make the test fail (or be skipped) if optimize is set? Maybe something like

@unittest.skipIf(sys.flags.optimize, "should be run without optimize")

would work?

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.

It doesn't quite do what was originally there, but we could add the check for optimized.

#my_name = os.environ.get(r'USERNAME', None)
#my_dir = my_name and path_combine(team_dir, my_name) or None
#my_profile = my_dir and path_combine(my_dir, r'settings.py') or None
# #team_dir = path_combine(ip_root, r'Team')

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.

If this was already commented might as well just zap it.

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.

No, it's part of what makes this WIP still...I need it to refer back to as I work through test. It will be removed in the final commit.

#####################################################################################

AreEqual(z, 10)
self.assertEqual(z, 10)

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'm guessing more work needs to be done here?

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.

No, this is imported in test_execfile.py, it's just used for testing.

Comment thread Tests/Inc/toexec.py
from iptest.assert_util import *

Assert(__name__ in ["__main__", "test_execfile"], __name__)
self.assertTrue(__name__ in ["__main__", "test_execfile"], __name__)

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.

Still working on this 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.

No, this is imported in test_execfile.py

Comment thread Tests/test_attr.py Outdated
a = x()
try:
hasattr(a, 'abc')
AssertUnreachable()

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.

Replace with unittest equivalent?

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.

Yes, when it works I don't see the errors for wrong assertion methods :-)

Comment thread Tests/test_builtinfunc.py
import clr
cp946()
def test_no_clr_import(self):
self.cp946()

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.

Does unittest guarantee that this one will run before the next 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.

No, but isn't the import local to the method?

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.

Yes the clr variable is local to the function, but just fact that we're importing clr causes some side effects (such as the C# methods becoming visible). For example:

def test():
    import clr
assert "ToString" not in dir("a")
test()
assert "ToString" in dir("a")

@slide slide May 26, 2017 •

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.

I'll rename the methods, there is this note in the unittest docs:

"Note that the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings."

They will run in the correct order now, but I'll add a 00 an 01 respectively just to make sure.

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.

Maybe we could add something like assert not hasattr(object, "ToString") to check that clr isn't loaded?

Comment thread Tests/test_execfile.py Outdated

from iptest import IronPythonTestCase, is_cli

@unittest.skipUnless(is_cli, 'IronPython specific test case')

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.

The skip was only on test_sanity. Although unless there's something cli specific in toexec.py it might not be necessary.

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.

You are right, I don't think it's needed at all.

Comment thread Tests/test_excinfo.py Outdated
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
# This source code is subject to terms and conditions of the Apache License, Version 2.0. self.A

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.

Added a typo?

@@ -1,142 +0,0 @@
#####################################################################################

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.

Where did this file one go?

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.

No tests were being run from this file and the framework for running the test no longer exists in the testing libraries.

class D(C1): pass
d = D()
AreEqual([d.x, d.y], [100, 100])
def test_delete_getattribute(self):

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 one was disabled. Is it fixed now?

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.

Yes, it runs correctly. I generally have been enabling all the tests and then looking through to see if there really is something that should be disabled. I am also trying to use expectedFailure instead of disabling if there is an issue, that way it is noted in the logs.

Comment thread Tests/test_attr.py
try:
hasattr(a, 'abc')
AssertUnreachable()
self.fail('Should not reach this point')

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 think there is an assertUnreachable in IronPythonTestCase? There are probably more AssertUnreachable all over the place...

Comment thread Tests/test_builtinfunc.py
import clr
cp946()
def test_no_clr_import(self):
self.cp946()

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.

Maybe we could add something like assert not hasattr(object, "ToString") to check that clr isn't loaded?

Comment thread Tests/modules/system_related/test_gc.py Outdated
Fail("Returned value of getdebug method is not valid value:" + str(result))


#CodePlex Work Item# 8202

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 believe this comment should go with test_000_get_debug.

Comment thread Tests/test_regressions.py
self.assertEqual(errno.errorcode[2],
"ENOENT")

@unittest.skipIf(is_posix, 'Test does not work on Mono')

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.

Mono or posix? Do we have an is_mono?

Comment thread Tests/regressions.py
return "MyException is a user sub-type of IOError"

@skip("win32")
def test_clr_exception_has_non_trivial_exception_message():

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.

Did you move this one to another file?

Comment thread Tests/test_regressions.py
l[-1] = p2
self.assertEqual(id(l[-1]), id(p2))

@unittest.skipIf(is_netstandard or not is_cli, 'netstandard does not support PlatformNotSupportedException, nor does native')

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.

The skipIf message should probably read something like: IronPython specific test, .NET Core throws a PlatformNotSupportedException

Comment thread Tests/test_regressions.py
self.assertTrue(is_complete)
self.assertEqual(Flag.Value, 32)

@unittest.skipIf(is_posix, "mono's GC behaves differently so we get another print when GC occurs")

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.

in_mono instead of is_posix?

Comment thread Tests/test_is.py Outdated
def test_object():
a = object()
b = object()
@unittest.skipUnless(is_cli, 'IronPython specific test case')

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.

Move the skipUnless over to test_bool_nullablebool? test_object should work with CPython.

Comment thread Tests/test_isinstance.py
except NameError:
pass

def test_file():

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.

Dropped this test?

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.

Yes, it didn't seem to fit with the test of the tests.

Comment thread Tests/test_listcomp.py Outdated
self.assertRaises(NameError, lambda: [(i, j) for i in range(10) if j < 'c' for j in ['a', 'b', 'c'] if i % 3 == 0])

def test_negative_flow_checker(self):
self.assertRaises(NameError, lambda: [y for x in "python"])

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 seems like exactly the same as the test above?

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.

Yeah, I'll remove the second one.

Comment thread Tests/test_property.py Outdated

def test_stdin(self):
self.assertTrue('<stdin>' in str(sys.stdin))
#self.assertTrue('<stdout>' in str(sys.stdout))

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.

Can we uncomment these?

Comment thread Tests/test_str.py
AreEqual(id(x), id(True))

def test_str_dict():
print "CodePlex Work Item 13115"

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.

Maybe preverse the codeplex # as a comment?

if options.RUN_TESTS: #TODO - bug when generating Pydoc
from Merlin.Testing.FieldTest import *
from Merlin.Testing.TypeSample import *
class FieldMiscTest(IronPythonTestCase):

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.

We probably want skipunless is_cli on all of these.

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.

I thought of that too, but wasn't sure we would ever try running these under CPython.

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'm actually thinking about running the tests under CPython. Maybe not under CI, but it would be useful to highlight compatibility issues.

Comment thread Tests/test_isinstance.py

def test_eval_dicts(self):
# eval referencing locals / globals
import System

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.

Maybe move the import to the if is_cli block?

Comment thread Tests/test_isinstance.py Outdated
self.assertRaises(TypeError, tuple.__new__, str)
self.assertRaises(TypeError, tuple.__new__, str, 'abc')

def test_override_pow(self):

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.

Something wrong with this test?

@@ -1,125 +0,0 @@
#####################################################################################

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.

Why remove this test?

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.

It was just calling the other loadorder tests, which will be run automatically now.

AreEqual(NSwForwardee1.Foo.A, 120)
AreEqual(NSwForwardee1.Bar.A, -120)

@skip("multiple_execute", "posix")

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.

In other places you kept the multiple_execute as a TODO however it seems you zapped it here.

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 fixed now


class BinasciiTest(unittest.TestCase):

@skipUnlessIronPython

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 think we can remove the skipUnless, seems to work with CPython.

@@ -1,944 +0,0 @@
#####################################################################################

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.

Why remove this 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.

It's renamed in a coming commit.

Comment thread Tests/modules/io_related/test_codecs.py Outdated
t_in.close()

self.assertEqual(len(t_out_lines), 0)
print t_err_lines[0]

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.

Are these prints for testing?

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.

Yes, will remove

try {
byte[] buffer = new byte[2048];
MemoryStream result = new MemoryStream(n);
MemoryStream result = new MemoryStream(len);

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.

Unrelated to the change, but wow, we're really allocating a 2gb array if len is not specified?

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.

Yes, that is indeed bad...

"<type 'socket.ssl'>")

#--Negative
if is_cpython:

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.

Dropped the negative case?

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.

No, the file was renamed to match the test_*.py naming convention

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 meant the positive case of test_SSLType appears in test__ssl.py but I don't see the negative case...

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.

Ah, that's because there is no SSLType for the _ssl module anymore. Both IronPython and CPython get a message saying the module object has no attribute SSLType, so the test was bogus.

s.connect((SSL_URL, SSL_PORT))
ssl_s = real_ssl.sslwrap(s._sock, False)

if not is_cli:

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.

Any reason why the shutdown is excluded here but not in other tests?

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.

No, I'll fix it

f.bufsize = 4096
self.assertEqual(4096, f.bufsize)

@unittest.skipIf(is_posix, 'some issue on mono, need to debug further')

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.

is_mono?

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.

Right, good catch.

Comment thread Tests/modules/system_related/test_nt.py Outdated
nt.mkdir("dir_create_test")
try:
nt.mkdir("dir_create_test")
self.assertTrueUnreachabale("Cannot create the same directory twice")

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.

assertTrueUnreachable?

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.

replace all issue, will fix

Comment thread Tests/test_kwarg.py

def test_negTestFunc_ObjectSubClass_testFunc_pw_kw_dupArg(self):
o = ObjectSubClass()
try: o.testFunc_pw_kw(a='abc')

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.

Any idea why assertRaises doesn't work for these? Maybe add a comment that assertRaises should not be used here?

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.

I think it may have something to do with how the parameter is passed around (in the case of NOT using assertRaises, it is setting the value of the 'a' parameter, but when passed into assertRaises it is passed as **kwArgs. A comment is a good idea

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.

C Python doesn't seem to have any issues with it though, so I guess we have a bug.

@slide
slide merged commit 0fe44c3 into IronLanguages:master Jun 2, 2017
@slide
slide deleted the ironpython_unittest_updates branch June 2, 2017 19:45
@slide slide changed the title [WIP] Unit test updates Unit test updates Jun 2, 2017
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.

2 participants