1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import warnings
- import pytest
- from flaskbb.deprecation import RemovedInFlaskBB3, deprecated
- NEXT_VERSION_STRING = ".".join([str(x) for x in RemovedInFlaskBB3.version])
- @deprecated("This is only a drill")
- def only_a_drill():
- pass
- # TODO(anr): Make the parens optional
- @deprecated()
- def default_deprecation():
- pass
- class TestDeprecation(object):
- def test_emits_default_deprecation_warning(self, recwarn):
- warnings.simplefilter("default", RemovedInFlaskBB3)
- default_deprecation()
- assert len(recwarn) == 1
- assert "default_deprecation is deprecated" in str(recwarn[0].message)
- assert recwarn[0].category == RemovedInFlaskBB3
- assert recwarn[0].filename == __file__
- # assert on the next line is conditional on the position of the call
- # to default_deprecation please don't jiggle it around too much
- assert recwarn[0].lineno == 25
- def tests_emits_specialized_message(self, recwarn):
- warnings.simplefilter("default", RemovedInFlaskBB3)
- only_a_drill()
- expected = "only_a_drill is deprecated and will be removed in version {}. This is only a drill".format( # noqa
- NEXT_VERSION_STRING
- )
- assert len(recwarn) == 1
- assert expected in str(recwarn[0].message)
- def tests_only_accepts_FlaskBBDeprecationWarnings(self):
- with pytest.raises(ValueError) as excinfo:
- # DeprecationWarning is ignored by default
- @deprecated("This is also a drill", category=UserWarning)
- def also_a_drill():
- pass
- assert "Expected subclass of FlaskBBDeprecation" in str(excinfo.value)
- def tests_deprecated_decorator_work_with_method(self, recwarn):
- warnings.simplefilter("default", RemovedInFlaskBB3)
- self.deprecated_instance_method()
- assert len(recwarn) == 1
- @deprecated()
- def deprecated_instance_method(self):
- pass
|