123456789101112131415161718192021222324 |
- import pytest
- import finoex
- import yaml
- @pytest.mark.parametrize(('source_object', 'expected_yaml'), [
- [finoex.Sum(1.23, 'EUR'), "!sum '1.23 EUR'\n"],
- [finoex.Sum(20.45, 'US$'), "!sum '20.45 USD'\n"],
- ])
- def test_to_yaml(source_object, expected_yaml):
- class Dumper(yaml.Dumper):
- pass
- finoex.Sum.register_yaml_representer(Dumper)
- assert expected_yaml == yaml.dump(source_object, Dumper = Dumper)
- @pytest.mark.parametrize(('expected_object', 'source_yaml'), [
- [finoex.Sum(1.23, 'EUR'), "!sum 1.23 EUR"],
- [finoex.Sum(20.45, 'US$'), "!sum 20.45 USD"],
- ])
- def test_from_yaml(expected_object, source_yaml):
- class Loader(yaml.Loader):
- pass
- finoex.Sum.register_yaml_constructor(Loader)
- assert expected_object == yaml.load(source_yaml, Loader = Loader)
|