Skip to content
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

Clean up test output #553

Merged
merged 4 commits into from
Nov 13, 2019
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
4 changes: 1 addition & 3 deletions traits/etsconfig/tests/test_etsconfig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
""" Tests the 'ETSConfig' configuration object. """

from __future__ import print_function

# Standard library imports.
import contextlib
import os
Expand Down Expand Up @@ -258,7 +256,7 @@ def test_provisional_toolkit(self):

with mock_sys_argv(test_args):
with mock_os_environ(test_environ):
print(repr(self.ETSConfig.toolkit))
repr(self.ETSConfig.toolkit)
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove the print but keep the call to repr?

Copy link
Member Author

Choose a reason for hiding this comment

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

To keep the effect of the test. It's (indirectly) testing that the repr doesn't fail, so I wanted to keep that test.

with self.ETSConfig.provisional_toolkit("test_direct"):
toolkit = self.ETSConfig.toolkit
self.assertEqual(toolkit, "test_direct")
Expand Down
26 changes: 16 additions & 10 deletions traits/testing/tests/test_unittest_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,16 @@ def test_assert_deprecated_when_warning_already_issued(self):
def old_and_dull_caller():
old_and_dull()

# Pollute the registry by pre-calling the function.
old_and_dull_caller()
with warnings.catch_warnings(record=True):
warnings.simplefilter("always", DeprecationWarning)

# Check that we can still detect the DeprecationWarning.
with self.assertDeprecated():
# Pollute the registry by pre-calling the function.
old_and_dull_caller()

# Check that we can still detect the DeprecationWarning.
with self.assertDeprecated():
old_and_dull_caller()

def test_assert_not_deprecated_failures(self):
with self.assertRaises(self.failureException):
with self.assertNotDeprecated():
Expand All @@ -430,10 +433,13 @@ def test_assert_not_deprecated_when_warning_already_issued(self):
def old_and_dull_caller():
old_and_dull()

# Pollute the registry by pre-calling the function.
old_and_dull_caller()
with warnings.catch_warnings(record=True):
warnings.simplefilter("always", DeprecationWarning)

# Check that we can still detect the DeprecationWarning.
with self.assertRaises(self.failureException):
with self.assertNotDeprecated():
old_and_dull_caller()
# Pollute the registry by pre-calling the function.
old_and_dull_caller()

# Check that we can still detect the DeprecationWarning.
with self.assertRaises(self.failureException):
with self.assertNotDeprecated():
old_and_dull_caller()
15 changes: 9 additions & 6 deletions traits/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def test_subclass_extension_category(self):
Seems like the declaration of the subclass (BasePlusPlus) should fail.
"""
try:
x = self.base.pp
self.base.pp
self.fail(
msg="base.pp should have thrown AttributeError "
"as Category subclassing is not supported."
)
except AttributeError:
pass

basepp = BasePlusPlus()
BasePlusPlus()
Copy link
Contributor

Choose a reason for hiding this comment

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

im guessing that this too is a test where we instantiate the object and we expect to see/not-see errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep.

return

def test_subclass_instance_category(self):
Expand Down Expand Up @@ -130,10 +130,13 @@ def test_subclasses_dont_modify_category_base_class(self):
class A(HasTraits):
a = Str()

class B(Category, A):
b = Str()
with warnings.catch_warnings(record=True):
warnings.simplefilter("always", DeprecationWarning)

class B(Category, A):
b = Str()

class C(Category, A):
c = Str()
class C(Category, A):
c = Str()

self.assertEqual(Category.__class_traits__, {})
30 changes: 24 additions & 6 deletions traits/tests/test_interface_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# Standard library imports.
import unittest
import warnings

# Enthought library imports.
from traits.adaptation.api import reset_global_adaptation_manager
Expand Down Expand Up @@ -392,7 +393,7 @@ class Foo(HasTraits):
class Bar(HasTraits):
foo = Instance(IFoo)

b = Bar(foo=Foo())
Bar(foo=Foo())
Copy link
Contributor

Choose a reason for hiding this comment

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

im guessing this too is a test where we simply instantiate the object and expect to see/not see errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was a drive-by fix to eliminate a flake8 warning about an unused variable, without changing the semantics of the test.


return

Expand All @@ -407,9 +408,18 @@ class Foo(HasTraits):
pass

f = Foo()
self.assertEqual(f, IFoo(f))

return
# Adaptation via direct instantiation of interfaces is deprecated, so
# catch the warning to keep the test run output clean.
with warnings.catch_warnings(record=True) as warn_msgs:
warnings.simplefilter("always", DeprecationWarning)
self.assertEqual(f, IFoo(f))

self.assertEqual(len(warn_msgs), 1)
warn_msg = warn_msgs[0]
self.assertIn(
'use "adapt(adaptee, protocol)" instead', str(warn_msg.message))
self.assertIn("test_interface_checker", warn_msg.filename)

def test_adaptation(self):
""" adaptation """
Expand All @@ -428,9 +438,17 @@ class FooToIFooAdapter(Adapter):

f = Foo()

# Make sure adaptation works.
i_foo = IFoo(f)
# Make sure adaptation works. Adaptation via direct instantiation of
# Interface classes is deprecated, so suppress the warning.
with warnings.catch_warnings(record=True) as warn_msgs:
warnings.simplefilter("always", DeprecationWarning)
i_foo = IFoo(f)

self.assertNotEqual(None, i_foo)
self.assertEqual(FooToIFooAdapter, type(i_foo))
return

self.assertEqual(len(warn_msgs), 1)
warn_msg = warn_msgs[0]
self.assertIn(
'use "adapt(adaptee, protocol)" instead', str(warn_msg.message))
self.assertIn("test_interface_checker", warn_msg.filename)