| 1 |
#!/usr/bin/env python3 |
| 2 |
"""Tests for the decorators.""" |
| 3 |
|
| 4 |
import unittest |
| 5 |
import warnings |
| 6 |
|
| 7 |
from dfdatetime import decorators |
| 8 |
|
| 9 |
|
| 10 |
class TestClass: |
| 11 |
"""Class for testing deprecated decorator.""" |
| 12 |
|
| 13 |
def Method(self): |
| 14 |
"""Test method.""" |
| 15 |
return "result" |
| 16 |
|
| 17 |
@decorators.deprecated |
| 18 |
def DeprecatedMethod(self): |
| 19 |
"""Deprecated test method.""" |
| 20 |
return "deprecated_result" |
| 21 |
|
| 22 |
|
| 23 |
class DeprecatedTest(unittest.TestCase): |
| 24 |
"""Tests for the deprecated decorator.""" |
| 25 |
|
| 26 |
def test_deprecated(self): |
| 27 |
"""Tests the deprecated decorator.""" |
| 28 |
test_object = TestClass() |
| 29 |
|
| 30 |
result = test_object.Method() |
| 31 |
self.assertEqual(result, "result") |
| 32 |
|
| 33 |
with warnings.catch_warnings(record=True) as warning: |
| 34 |
warnings.simplefilter("always", DeprecationWarning) |
| 35 |
|
| 36 |
result = test_object.DeprecatedMethod() |
| 37 |
|
| 38 |
self.assertEqual(result, "deprecated_result") |
| 39 |
self.assertEqual(len(warning), 1) |
| 40 |
self.assertIn("DeprecatedMethod", str(warning[0].message)) |
| 41 |
|
| 42 |
|
| 43 |
if __name__ == "__main__": |
| 44 |
unittest.main() |