import os

from glob import glob
from oslo_config import cfg
from yaml import load


from magnum.common import paths
from magnum.tests import base


cfg.CONF.register_opts([cfg.StrOpt('template_path',
                        default=paths.basedir_def('templates'),
                        help='Heat template path')])


class TestTemplate(base.TestCase):

    def test_template_yaml(self):
        for yml in [y for x in os.walk(cfg.CONF.template_path)
                    for y in glob(os.path.join(x[0], '*.yaml'))]:
            with open(yml, 'r') as f:
                yml_contents = f.read()
                load(yml_contents)

import os
import sys

from glob import glob
from oslo_config import cfg
from yaml import load


from magnum.common import paths
from magnum.tests import base


cfg.CONF.register_opts([cfg.StrOpt('template_path',
                        default=paths.basedir_def('templates'),
                        help='Heat template path')])


class TestTemplate(base.TestCase):

    def test_template_yaml(self):
        for yml in [y for x in os.walk(cfg.CONF.template_path)
                    for y in glob(os.path.join(x[0], '*.yaml'))]:
            with open(yml, 'r') as f:
                yml_contents = f.read()
                try:
                    load(yml_contents)
                except Exception:
                    error_msg = "file: %s: %s" % (yml, sys.exc_info()[1])
                    self.fail(error_msg)

Improve yml template test case.
Improve yml template test case.

Print out yml file name when failed to loading yml.

Change-Id: Ie34282b91ec8101ffa2676e3144acf5a054578b0

  import os
+ import sys
  
  from glob import glob
  from oslo_config import cfg
  from yaml import load
  
  
  from magnum.common import paths
  from magnum.tests import base
  
  
  cfg.CONF.register_opts([cfg.StrOpt('template_path',
                          default=paths.basedir_def('templates'),
                          help='Heat template path')])
  
  
  class TestTemplate(base.TestCase):
  
      def test_template_yaml(self):
          for yml in [y for x in os.walk(cfg.CONF.template_path)
                      for y in glob(os.path.join(x[0], '*.yaml'))]:
              with open(yml, 'r') as f:
                  yml_contents = f.read()
+                 try:
-                 load(yml_contents)
+                     load(yml_contents)
+                 except Exception:
+                     error_msg = "file: %s: %s" % (yml, sys.exc_info()[1])
+                     self.fail(error_msg)
  
Improve yml template test case.
## Code Before:
import os

from glob import glob
from oslo_config import cfg
from yaml import load


from magnum.common import paths
from magnum.tests import base


cfg.CONF.register_opts([cfg.StrOpt('template_path',
                        default=paths.basedir_def('templates'),
                        help='Heat template path')])


class TestTemplate(base.TestCase):

    def test_template_yaml(self):
        for yml in [y for x in os.walk(cfg.CONF.template_path)
                    for y in glob(os.path.join(x[0], '*.yaml'))]:
            with open(yml, 'r') as f:
                yml_contents = f.read()
                load(yml_contents)

## Instruction:
Improve yml template test case.
## Code After:
import os
import sys

from glob import glob
from oslo_config import cfg
from yaml import load


from magnum.common import paths
from magnum.tests import base


cfg.CONF.register_opts([cfg.StrOpt('template_path',
                        default=paths.basedir_def('templates'),
                        help='Heat template path')])


class TestTemplate(base.TestCase):

    def test_template_yaml(self):
        for yml in [y for x in os.walk(cfg.CONF.template_path)
                    for y in glob(os.path.join(x[0], '*.yaml'))]:
            with open(yml, 'r') as f:
                yml_contents = f.read()
                try:
                    load(yml_contents)
                except Exception:
                    error_msg = "file: %s: %s" % (yml, sys.exc_info()[1])
                    self.fail(error_msg)
