summaryrefslogtreecommitdiffstats
path: root/tests/yamlparser/test_yamlparser.py
blob: 320308355b21e6f81548e3e77a2a5384fd9aaebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Joint copyright:
#  - Copyright 2012,2013 Wikimedia Foundation
#  - Copyright 2012,2013 Antoine "hashar" Musso
#  - Copyright 2013 Arnaud Fabre
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import os

from jenkins_jobs import parser
from jenkins_jobs import registry

from tests import base


class TestCaseModuleYamlInclude(base.SingleJobTestCase):
    fixtures_path = os.path.join(os.path.dirname(__file__), "fixtures")
    scenarios = base.get_scenarios(fixtures_path)


class TestYamlParserExceptions(base.BaseTestCase):
    fixtures_path = os.path.join(os.path.dirname(__file__), "exceptions")

    def test_incorrect_template_dimensions(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(os.path.join(self.fixtures_path, "incorrect_template_dimensions.yaml"))

        reg = registry.ModuleRegistry(config)

        e = self.assertRaises(Exception, yp.expandYaml, reg)
        self.assertIn("'NoneType' object is not iterable", str(e))
        self.assertIn("- branch: current\n  current: null", self.logger.output)


class TestYamlParserFailureFormattingExceptions(base.BaseScenariosTestCase):
    fixtures_path = os.path.join(os.path.dirname(__file__), "exceptions")
    scenarios = [("s1", {"name": "template"}), ("s2", {"name": "params"})]

    def test_yaml_snippet(self):
        self.conf_filename = None
        config = self._get_config()

        yp = parser.YamlParser(config)
        yp.parse(
            os.path.join(
                self.fixtures_path, "failure_formatting_{}.yaml".format(self.name)
            )
        )

        reg = registry.ModuleRegistry(config)

        self.assertRaises(Exception, yp.expandYaml, reg)
        self.assertIn("Failure formatting {}".format(self.name), self.logger.output)
        self.assertIn("Problem formatting with args", self.logger.output)