pungi/tests/test_config_validate_script.py
Lubomír Sedlář ff5a7e6377 Make python3-mock dependency optional
https://fedoraproject.org/wiki/Changes/RemovePythonMockUsage

Prefer using unittest.mock to a standalone package. The separate
packages should only really be needed on Python 2.7 these days.

The test requirements file is updated to only require mock on old
Python, and the dependency is removed from setup.py to avoid issues
there.

Relates: https://src.fedoraproject.org/rpms/pungi/pull-request/9

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
2024-01-26 09:45:19 +01:00

49 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
try:
from unittest import mock
except ImportError:
import mock
import os
import six
from pungi.scripts.config_validate import cli_main
from tests import helpers
HERE = os.path.abspath(os.path.dirname(__file__))
DUMMY_CONFIG = os.path.join(HERE, "data/dummy-pungi.conf")
SCHEMA_OVERRIDE = os.path.join(HERE, "data/dummy-override.json")
class ConfigValidateScriptTest(helpers.PungiTestCase):
@mock.patch("sys.argv", new=["pungi-config-validate", DUMMY_CONFIG])
@mock.patch("sys.stderr", new_callable=six.StringIO)
@mock.patch("sys.stdout", new_callable=six.StringIO)
def test_validate_dummy_config(self, stdout, stderr):
cli_main()
self.assertEqual("", stdout.getvalue())
self.assertEqual("", stderr.getvalue())
@mock.patch(
"sys.argv",
new=[
"pungi-config-validate",
DUMMY_CONFIG,
"--schema-override",
SCHEMA_OVERRIDE,
],
)
@mock.patch("sys.stderr", new_callable=six.StringIO)
@mock.patch("sys.stdout", new_callable=six.StringIO)
@mock.patch("sys.exit")
def test_schema_override(self, exit, stdout, stderr):
cli_main()
self.assertTrue(
stdout.getvalue().startswith(
"Failed validation in pkgset_source: 'repos' is not one of"
)
)
self.assertEqual("", stderr.getvalue())
exit.assert_called_once_with(1)