Tools to make Jenkins jobs from templates
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_yamlparser.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Joint copyright:
  2. # - Copyright 2012,2013 Wikimedia Foundation
  3. # - Copyright 2012,2013 Antoine "hashar" Musso
  4. # - Copyright 2013 Arnaud Fabre
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. # License for the specific language governing permissions and limitations
  16. # under the License.
  17. import os
  18. from jenkins_jobs import parser
  19. from jenkins_jobs import registry
  20. from tests import base
  21. class TestCaseModuleYamlInclude(base.SingleJobTestCase):
  22. fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
  23. scenarios = base.get_scenarios(fixtures_path)
  24. class TestYamlParserExceptions(base.BaseTestCase):
  25. fixtures_path = os.path.join(os.path.dirname(__file__), 'exceptions')
  26. def test_incorrect_template_dimensions(self):
  27. self.conf_filename = None
  28. config = self._get_config()
  29. yp = parser.YamlParser(config)
  30. yp.parse(os.path.join(self.fixtures_path,
  31. "incorrect_template_dimensions.yaml"))
  32. reg = registry.ModuleRegistry(config)
  33. e = self.assertRaises(Exception, yp.expandYaml, reg)
  34. self.assertIn("'NoneType' object is not iterable", str(e))
  35. self.assertIn("- branch: current\n current: null", self.logger.output)
  36. class TestYamlParserFailureFormattingExceptions(base.BaseScenariosTestCase):
  37. fixtures_path = os.path.join(os.path.dirname(__file__), 'exceptions')
  38. scenarios = [
  39. ('s1', {'name': 'template'}),
  40. ('s2', {'name': 'params'})
  41. ]
  42. def test_yaml_snippet(self):
  43. self.conf_filename = None
  44. config = self._get_config()
  45. yp = parser.YamlParser(config)
  46. yp.parse(os.path.join(self.fixtures_path,
  47. "failure_formatting_{}.yaml".format(self.name)))
  48. reg = registry.ModuleRegistry(config)
  49. self.assertRaises(Exception, yp.expandYaml, reg)
  50. self.assertIn("Failure formatting {}".format(self.name),
  51. self.logger.output)
  52. self.assertIn("Problem formatting with args", self.logger.output)