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_metric.py 747 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import pytest
  2. from fastNLP import Metric
  3. class DemoMetric(Metric):
  4. def __init__(self):
  5. super().__init__(backend='torch')
  6. self.count = 0
  7. self.register_element('count', 0)
  8. def evaluate(self):
  9. self.count += 1
  10. print(self.count)
  11. class DemoMetric1(Metric):
  12. def __init__(self):
  13. super().__init__(backend='torch')
  14. self.register_element('count', 0)
  15. self.count = 2
  16. def evaluate(self):
  17. self.count += 1
  18. return self.count
  19. class TestMetric:
  20. def test_v1(self):
  21. with pytest.raises(RuntimeError):
  22. dmtr = DemoMetric()
  23. dmtr.evaluate()
  24. def test_v2(self):
  25. dmtr = DemoMetric1()
  26. assert 3 == dmtr.evaluate()