pungi/tests/test_config_utils.py
Lubomír Sedlář acd3c19618 config-validate: Allow defining variables
When trying to validate a template that should later be filled in with
`pungi-config-dump`, there will be errors about undefined variables.
These are meant to be set when the template is populated.

This patch adds support for `-e`, `--define` argument to the validation
script that can be used to suppress these errors.

Alternatively a JSON file is read from the directory with config file
that can contain values for the variables.

The `--define` option is changed in both validation and dumping to allow
empty string as an accepted value.

JIRA: COMPOSE-3599
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
2019-06-21 12:47:50 +02:00

38 lines
1.1 KiB
Python

# -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import argparse
import os
import sys
from parameterized import parameterized
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi_utils import config_utils
class TestDefineHelpers(unittest.TestCase):
@parameterized.expand(
[
([], {}),
(["foo=bar", "baz=quux"], {"foo": "bar", "baz": "quux"}),
(["foo="], {"foo": ""}),
(["foo==bar"], {"foo": "=bar"}),
]
)
def test_extract_defines(self, input, expected):
self.assertEqual(config_utils.extract_defines(input), expected)
@parameterized.expand(["foo=bar", "foo=", "foo==bar"])
def test_validate_define_correct(self, value):
self.assertEqual(config_utils.validate_definition(value), value)
@parameterized.expand(["foo", "=", "=foo", "1=2"])
def test_validate_define_incorrect(self, value):
with self.assertRaises(argparse.ArgumentTypeError):
config_utils.validate_definition(value)