test_sum_yaml.py 811 B

123456789101112131415161718192021222324
  1. import pytest
  2. import finoex
  3. import yaml
  4. @pytest.mark.parametrize(('source_object', 'expected_yaml'), [
  5. [finoex.Sum(1.23, 'EUR'), "!sum '1.23 EUR'\n"],
  6. [finoex.Sum(20.45, 'US$'), "!sum '20.45 USD'\n"],
  7. ])
  8. def test_to_yaml(source_object, expected_yaml):
  9. class Dumper(yaml.Dumper):
  10. pass
  11. finoex.Sum.register_yaml_representer(Dumper)
  12. assert expected_yaml == yaml.dump(source_object, Dumper = Dumper)
  13. @pytest.mark.parametrize(('expected_object', 'source_yaml'), [
  14. [finoex.Sum(1.23, 'EUR'), "!sum 1.23 EUR"],
  15. [finoex.Sum(20.45, 'US$'), "!sum 20.45 USD"],
  16. ])
  17. def test_from_yaml(expected_object, source_yaml):
  18. class Loader(yaml.Loader):
  19. pass
  20. finoex.Sum.register_yaml_constructor(Loader)
  21. assert expected_object == yaml.load(source_yaml, Loader = Loader)