|
| 1 | +import sys |
| 2 | +import unittest |
| 3 | +import warnings |
| 4 | + |
| 5 | +import mock |
| 6 | + |
| 7 | +import pyemma |
| 8 | +from pyemma.util.exceptions import PyEMMA_DeprecationWarning |
| 9 | + |
| 10 | + |
| 11 | +@unittest.skipIf(sys.version_info.major == 2, "disabled on py2 for nosetest stupidness") |
| 12 | +class TestShowDeprecationWarningOnLowLevelAPIUsage(unittest.TestCase): |
| 13 | + |
| 14 | + @classmethod |
| 15 | + def setUpClass(cls): |
| 16 | + cls.old_filters = warnings.filters[:] |
| 17 | + if sys.version_info.major == 2: |
| 18 | + warnings.filters = [] |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def tearDownClass(cls): |
| 22 | + warnings.filters = cls.old_filters |
| 23 | + |
| 24 | + def test_analysis(self): |
| 25 | + with warnings.catch_warnings(record=True) as cm: |
| 26 | + warnings.simplefilter("always") |
| 27 | + from pyemma.msm import analysis |
| 28 | + analysis.is_transition_matrix |
| 29 | + |
| 30 | + self.assertEqual(len(cm), 1) |
| 31 | + self.assertIn('analysis', cm[0].message.args[0]) |
| 32 | + |
| 33 | + with warnings.catch_warnings(record=True) as cm: |
| 34 | + warnings.simplefilter("always") |
| 35 | + pyemma.msm.analysis.is_transition_matrix |
| 36 | + self.assertEqual(len(cm), 1) |
| 37 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 38 | + self.assertIn('analysis', cm[0].message.args[0]) |
| 39 | + |
| 40 | + @unittest.skipIf(sys.version_info.major == 2, "not on py2") |
| 41 | + def test_warn_was_called(self): |
| 42 | + shim_mod = sys.modules['pyemma.msm.analysis'] |
| 43 | + with mock.patch.object(shim_mod, '_warn') as m: |
| 44 | + from pyemma.msm import analysis |
| 45 | + analysis.is_transition_matrix |
| 46 | + |
| 47 | + m.assert_called_once() |
| 48 | + |
| 49 | + def test_estimation(self): |
| 50 | + with warnings.catch_warnings(record=True) as cm: |
| 51 | + warnings.simplefilter("always") |
| 52 | + from pyemma.msm import estimation |
| 53 | + estimation.count_matrix |
| 54 | + |
| 55 | + self.assertEqual(len(cm), 1) |
| 56 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 57 | + |
| 58 | + self.assertIn('estimation', cm[0].message.args[0]) |
| 59 | + |
| 60 | + with warnings.catch_warnings(record=True) as cm: |
| 61 | + warnings.simplefilter("always") |
| 62 | + pyemma.msm.estimation.count_matrix |
| 63 | + self.assertEqual(len(cm), 1) |
| 64 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 65 | + |
| 66 | + self.assertIn('estimation', cm[0].message.args[0]) |
| 67 | + |
| 68 | + def test_generation(self): |
| 69 | + with warnings.catch_warnings(record=True) as cm: |
| 70 | + warnings.simplefilter("always") |
| 71 | + from pyemma.msm import generation |
| 72 | + generation.generate_traj |
| 73 | + |
| 74 | + self.assertEqual(len(cm), 1) |
| 75 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 76 | + |
| 77 | + self.assertIn('generation', cm[0].message.args[0]) |
| 78 | + |
| 79 | + with warnings.catch_warnings(record=True) as cm: |
| 80 | + warnings.simplefilter("always") |
| 81 | + pyemma.msm.generation.generate_traj |
| 82 | + self.assertEqual(len(cm), 1) |
| 83 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 84 | + |
| 85 | + self.assertIn('generation', cm[0].message.args[0]) |
| 86 | + |
| 87 | + def test_dtraj(self): |
| 88 | + with warnings.catch_warnings(record=True) as cm: |
| 89 | + warnings.simplefilter("always") |
| 90 | + from pyemma.msm import dtraj |
| 91 | + dtraj.load_discrete_trajectory |
| 92 | + |
| 93 | + self.assertEqual(len(cm), 1) |
| 94 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 95 | + |
| 96 | + self.assertIn('dtraj', cm[0].message.args[0]) |
| 97 | + |
| 98 | + with warnings.catch_warnings(record=True) as cm: |
| 99 | + warnings.simplefilter("always") |
| 100 | + pyemma.msm.dtraj.load_discrete_trajectory |
| 101 | + self.assertEqual(len(cm), 1) |
| 102 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 103 | + |
| 104 | + self.assertIn('dtraj', cm[0].message.args[0]) |
| 105 | + |
| 106 | + def test_io(self): |
| 107 | + with warnings.catch_warnings(record=True) as cm: |
| 108 | + warnings.simplefilter("always") |
| 109 | + from pyemma.msm import io as dtraj |
| 110 | + dtraj.load_discrete_trajectory |
| 111 | + |
| 112 | + self.assertEqual(len(cm), 1) |
| 113 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 114 | + |
| 115 | + self.assertIn('dtraj', cm[0].message.args[0]) |
| 116 | + |
| 117 | + with warnings.catch_warnings(record=True) as cm: |
| 118 | + warnings.simplefilter("always") |
| 119 | + pyemma.msm.dtraj.load_discrete_trajectory |
| 120 | + self.assertEqual(len(cm), 1) |
| 121 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 122 | + |
| 123 | + self.assertIn('dtraj', cm[0].message.args[0]) |
| 124 | + |
| 125 | + def test_flux(self): |
| 126 | + with warnings.catch_warnings(record=True) as cm: |
| 127 | + warnings.simplefilter("always") |
| 128 | + from pyemma.msm import flux |
| 129 | + flux.total_flux |
| 130 | + |
| 131 | + self.assertEqual(len(cm), 1) |
| 132 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 133 | + |
| 134 | + self.assertIn('flux', cm[0].message.args[0]) |
| 135 | + |
| 136 | + with warnings.catch_warnings(record=True) as cm: |
| 137 | + warnings.simplefilter("always") |
| 138 | + pyemma.msm.flux.total_flux |
| 139 | + self.assertEqual(len(cm), 1) |
| 140 | + self.assertIsInstance(cm[0].message, PyEMMA_DeprecationWarning) |
| 141 | + |
| 142 | + self.assertIn('flux', cm[0].message.args[0]) |
0 commit comments