Skip to content

Commit

Permalink
narrow warning filter in core (see #222)
Browse files Browse the repository at this point in the history
also refactored test for warnings to use module filter; no filter
should lead to failed tests now.
  • Loading branch information
aleneum committed Jun 3, 2017
1 parent ce7e82f commit 2cb4291
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
32 changes: 17 additions & 15 deletions tests/test_core.py
Expand Up @@ -10,7 +10,6 @@
from transitions.core import listify, prep_ordered_arg
from unittest import TestCase, skipIf
import warnings
warnings.filterwarnings('error', category=PendingDeprecationWarning, message=r".*0\.6\.0.*")

try:
from unittest.mock import MagicMock
Expand Down Expand Up @@ -699,20 +698,6 @@ def check_before_repr(event_data):
self.assertTrue(m.do_strcheck())
self.assertIn('checked', vars(m))

def test_warning(self):
import sys
# does not work with python 3.3. However, the warning is shown when Machine is initialized manually.
if (3, 3) <= sys.version_info < (3, 4):
return
with self.assertRaises(PendingDeprecationWarning):
m = Machine(None)

with self.assertRaises(PendingDeprecationWarning):
m = Machine(initial=None)

with self.assertRaises(PendingDeprecationWarning):
m = Machine(None, add_self=False)

def test_machine_prepare(self):

global_mock = MagicMock()
Expand Down Expand Up @@ -862,3 +847,20 @@ def test_reflexive_transition(self):
with self.assertRaises(MachineError):
self.stuff.reflex()
self.assertEqual(self.stuff.level, 3)


class TestWarnings(TestCase):

def test_warning(self):
import sys
# does not work with python 3.3. However, the warning is shown when Machine is initialized manually.
if (3, 3) <= sys.version_info < (3, 4):
return

with warnings.catch_warnings(record=True) as w:
m = Machine(None)
m = Machine(initial=None)
m = Machine(None, add_self=False)
self.assertEqual(len(w), 3)
for warn in w:
self.assertEqual(warn.category, PendingDeprecationWarning)
4 changes: 3 additions & 1 deletion transitions/core.py
Expand Up @@ -14,7 +14,9 @@
from six import string_types

import warnings
warnings.simplefilter('default')
# make deprecation warnings of transition visible for module users
warnings.filterwarnings('default', category=PendingDeprecationWarning,
message=r".*transitions version 0\.6\.0.*")

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
Expand Down

1 comment on commit 2cb4291

@ksandeep
Copy link

Choose a reason for hiding this comment

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

Thanks a lot!!

Please sign in to comment.