test_utils.py 567 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python
  2. """
  3. Implement common functions for tests
  4. """
  5. from __future__ import print_function
  6. from __future__ import unicode_literals
  7. import io
  8. import sys
  9. def parse_yaml(yaml_file):
  10. """
  11. Parses a yaml file, returning its contents as a dict.
  12. """
  13. try:
  14. import yaml
  15. except ImportError:
  16. sys.exit("Unable to import yaml module.")
  17. try:
  18. with io.open(yaml_file, encoding='utf-8') as fname:
  19. return yaml.load(fname)
  20. except IOError:
  21. sys.exit("Unable to open YAML file: {0}".format(yaml_file))