1
0

test_yaml.py 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import os
  4. import yaml
  5. import dingguo
  6. import datetime
  7. project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
  8. test_data_path = os.path.join(project_root_path, 'tests', 'data')
  9. def get_figure_a():
  10. return dingguo.Figure(12.3, u'km')
  11. def get_figure_b():
  12. return dingguo.Figure(12300, u'米')
  13. def to_yaml(data):
  14. return yaml.dump(data, default_flow_style = False, allow_unicode = True).decode('utf-8')
  15. def test_figure_to_yaml():
  16. assert to_yaml(get_figure_a()) == u"""!figure
  17. unit: km
  18. value: 12.3
  19. """
  20. def test_figure_to_yaml_unicode():
  21. assert to_yaml(get_figure_b()) == u"""!figure
  22. unit: 米
  23. value: 12300
  24. """
  25. def test_figure_from_yaml():
  26. assert get_figure_a() == yaml.load(u"""!figure
  27. unit: km
  28. value: 12.3
  29. """)
  30. def test_figure_to_yaml_unicode():
  31. assert get_figure_b() == yaml.load(u"""!figure
  32. unit: 米
  33. value: 12300
  34. """)