# Path: heatclient/common/template_format.py
# class yaml_loader(yaml_loader_base):
# class yaml_dumper(yaml_dumper_base):
# def _construct_yaml_str(self, node):
# def parse(tmpl_str):


from unittest import mock
from heatclient.common import template_format
import six
import testscenarios
import testtools
import yaml

load_tests = testscenarios.load_tests_apply_scenarios


class YamlParseExceptions(testtools.TestCase):

    scenarios = [
        ('scanner', dict(raised_exception=yaml.scanner.ScannerError())),
        ('parser', dict(raised_exception=yaml.parser.ParserError())),
        ('reader',
         dict(raised_exception=yaml.reader.ReaderError('', '', '', '', ''))),
    ]

    def test_parse_to_value_exception(self):
        text = 'not important'

        with mock.patch.object(yaml, 'load') as yaml_loader:
            yaml_loader.side_effect = self.raised_exception

            self.assertRaises(ValueError,
                              template_format.parse, text)

    def test_parse_no_version_format(self):
        yaml = ''
        self.assertRaises(ValueError, template_format.parse, yaml)
        yaml2 = '''Parameters: {}
Mappings: {}
Resources: {}
Outputs: {}
'''

# Path: heatclient/common/template_format.py
# class yaml_loader(yaml_loader_base):
# class yaml_dumper(yaml_dumper_base):
# def _construct_yaml_str(self, node):
# def parse(tmpl_str):


# Path: heatclient/tests/unit/test_template_format.py
from unittest import mock
from heatclient.common import template_format
import six
import testscenarios
import testtools
import yaml


load_tests = testscenarios.load_tests_apply_scenarios


class YamlParseExceptions(testtools.TestCase):

    scenarios = [
        ('scanner', dict(raised_exception=yaml.scanner.ScannerError())),
        ('parser', dict(raised_exception=yaml.parser.ParserError())),
        ('reader',
         dict(raised_exception=yaml.reader.ReaderError('', '', '', '', ''))),
    ]

    def test_parse_to_value_exception(self):
        text = 'not important'

        with mock.patch.object(yaml, 'load') as yaml_loader:
            yaml_loader.side_effect = self.raised_exception

            self.assertRaises(ValueError,
                              template_format.parse, text)

    def test_parse_no_version_format(self):
        yaml = ''
        self.assertRaises(ValueError, template_format.parse, yaml)
        yaml2 = '''Parameters: {}
Mappings: {}
Resources: {}
Outputs: {}
'''

        self.assertRaises(ValueError, template_format.parse, yaml2)