You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_utils.py 754 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import pytest
  2. from fastNLP.core.dataloaders.utils import _match_param
  3. from fastNLP import logger
  4. from tests.helpers.utils import recover_logger, Capturing
  5. def demo():
  6. pass
  7. def test_no_args():
  8. def f(*args, a, b, **kwarg):
  9. c = 100
  10. call_kwargs = _match_param(f, demo)
  11. f(a=1, b=2)
  12. def f(a, *args, b, **kwarg):
  13. c = 100
  14. call_kwargs = _match_param(f, demo)
  15. f(a=1, b=2)
  16. @recover_logger
  17. def test_warning():
  18. logger.set_stdout('raw')
  19. def f1(a, b):
  20. return 1
  21. def f2(a, b, c=2):
  22. kwargs = _match_param(f2, f1)
  23. return f1(*kwargs)
  24. with Capturing() as out:
  25. f2(a=1, b=2, c=3)
  26. assert 'Parameter:c' in out[0] # 传入了需要 warning
  27. assert f2(1, 2) == 1