pungi/tests/test_variant_wrapper.py
Lubomír Sedlář 4a61de1e8a variants: Reject values with whitespace
If there is leading or trailing whitespace in a comps group name, it
will not be included in the compose and there will even be no error
message. Whitespace on module name results in a failure.

To avoid these errors, validating the variants file will now also check
that there is no whitespace in significant places, and abort the compose
if there a problem.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
2018-06-12 12:48:14 +02:00

36 lines
978 B
Python

# -*- coding: utf-8 -*-
try:
import unittest2 as unittest
except ImportError:
import unittest
import os
import sys
from six.moves import cStringIO
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from pungi.wrappers.variants import VariantsXmlParser
VARIANTS_WITH_WHITESPACE = """
<variants>
<variant id="Foo" name="Foo" type="variant">
<arches><arch>x86_64 </arch></arches>
<groups><group> core</group></groups>
<environments><environment> foo </environment></environments>
</variant>
</variants>
"""
class TestVariantsXmlParser(unittest.TestCase):
def test_whitespace_in_file(self):
input = cStringIO(VARIANTS_WITH_WHITESPACE)
with self.assertRaises(ValueError) as ctx:
VariantsXmlParser(input)
self.assertIn("Tag arch on line 4", str(ctx.exception))
self.assertIn("Tag group on line 5", str(ctx.exception))
self.assertIn("Tag environment on line 6", str(ctx.exception))