1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- # -*- coding: utf-8 -*-
- import pytest
- import os
- import yaml
- import dingguo
- import datetime
- project_root_path = os.path.realpath(os.path.join(__file__, '..', '..'))
- test_data_path = os.path.join(project_root_path, 'tests', 'data')
- def get_figure_a():
- return dingguo.Figure(12.3, u'km')
- def get_figure_b():
- return dingguo.Figure(12300, u'米')
- def get_sum_a():
- return dingguo.Sum(1.23, u'EUR')
- def get_sum_b():
- return dingguo.Sum(20.45, u'€')
- def to_yaml(data):
- return yaml.dump(data, default_flow_style = False, allow_unicode = True).decode('utf-8')
- def test_figure_to_yaml():
- assert to_yaml(get_figure_a()) == u"""!figure
- unit: km
- value: 12.3
- """
- def test_figure_to_yaml_unicode():
- assert to_yaml(get_figure_b()) == u"""!figure
- unit: 米
- value: 12300
- """
- def test_figure_from_yaml():
- assert get_figure_a() == yaml.load(u"""!figure
- unit: km
- value: 12.3
- """)
- def test_figure_to_yaml_unicode():
- assert get_figure_b() == yaml.load(u"""!figure
- unit: 米
- value: 12300
- """)
- def test_sum_to_yaml_a():
- assert to_yaml(get_sum_a()) == u"!sum 'EUR 1.23'\n"
- def test_sum_to_yaml_b():
- assert to_yaml(get_sum_b()) == u"!sum 'EUR 20.45'\n"
- def test_sum_from_yaml_a():
- assert get_sum_a() == yaml.load(u"!sum EUR 1.23")
- def test_sum_from_yaml_a_sign():
- assert get_sum_a() == yaml.load(u"!sum € 1.23")
- def test_sum_from_yaml_a_quotes():
- assert get_sum_a() == yaml.load(u"!sum 'EUR 1.23'")
|