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 838 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. with pytest.raises(RuntimeError):
  12. f(a=1, b=2)
  13. def f(a, *args, b, **kwarg):
  14. c = 100
  15. call_kwargs = _match_param(f, demo)
  16. with pytest.raises(RuntimeError):
  17. f(a=1, b=2)
  18. @recover_logger
  19. def test_warning():
  20. logger.set_stdout('raw')
  21. def f1(a, b):
  22. return 1
  23. def f2(a, b, c=2):
  24. kwargs = _match_param(f2, f1)
  25. return f1(*kwargs)
  26. with Capturing() as out:
  27. f2(a=1, b=2, c=3)
  28. assert 'Parameter:c' in out[0] # 传入了需要 warning
  29. assert f2(1, 2) == 1