test_coding_utils.py 844 B

12345678910111213141516171819202122232425262728293031
  1. from flexmeasures.utils.coding_utils import deprecated
  2. def other_function():
  3. return 1
  4. def test_deprecated_decorator(caplog, app):
  5. # defining a function that is deprecated
  6. @deprecated(other_function, "v14")
  7. def deprecated_function():
  8. return other_function()
  9. caplog.clear()
  10. value = deprecated_function() # calling a deprecated function
  11. print(caplog.records)
  12. assert len(caplog.records) == 1 # only 1 warning being printed
  13. assert "flexmeasures.utils.tests.test_coding_utils:other_function" in str(
  14. caplog.records[0].message
  15. ) # checking that the message is correct
  16. assert "v14" in str(
  17. caplog.records[0].message
  18. ) # checking that the message is correct
  19. assert (
  20. value == 1
  21. ) # check that the decorator is returning the value of `other_function`