test_figure.py 894 B

123456789101112131415161718192021222324252627
  1. import pytest
  2. import dingguo
  3. @pytest.mark.parametrize(('params', 'kwargs', 'expected_value', 'expected_unit'), [
  4. [[1, u'cm'], {}, 1, u'cm'],
  5. [[1], {'unit': u'cm'}, 1, u'cm'],
  6. [[], {'unit': u'cm'}, None, u'cm'],
  7. [[], {'value': 1.0, 'unit': u'cm'}, 1.0, u'cm'],
  8. [[], {'value': (3, -1), 'unit': u'cm'}, (3, -1), u'cm'],
  9. [[(-1, 3), u'cm'], {}, (-1, 3), u'cm'],
  10. ])
  11. def test_init(params, kwargs, expected_value, expected_unit):
  12. f = dingguo.Figure(*params, **kwargs)
  13. assert type(f.value) == type(expected_value)
  14. assert type(f.unit) == type(expected_unit)
  15. assert f.value == expected_value
  16. assert f.unit == expected_unit
  17. @pytest.mark.parametrize(('params', 'kwargs'), [
  18. [[], {}],
  19. [[1, 'cm'], {}],
  20. [[1], {'unit': 'cm'}],
  21. ])
  22. def test_init_fail(params, kwargs):
  23. with pytest.raises(Exception):
  24. dingguo.Figure(*params, **kwargs)