cleanup: refactor scripts via entry points

Fixes: https://pagure.io/pungi/issue/1045
JIRA: COMPOSE-2946
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2019-12-06 10:54:11 +08:00
parent ce16e55ebd
commit 3cf16eb42d
20 changed files with 401 additions and 480 deletions

View file

@ -275,10 +275,6 @@ def load_config(data={}, **kwargs):
return conf
def load_bin(name):
return imp.load_source('pungi_cli_fake_' + name, os.path.dirname(__file__) + "/../bin/" + name)
def fake_run_in_threads(func, params, threads=None):
"""Like run_in_threads from Kobo, but actually runs tasks serially."""
for num, param in enumerate(params):

View file

@ -5,9 +5,7 @@ except ImportError:
import unittest
import six
from tests.helpers import load_bin
cli = load_bin("pungi-koji")
from pungi.scripts.pungi_koji import cli_main
class PungiKojiTestCase(unittest.TestCase):
@ -15,10 +13,11 @@ class PungiKojiTestCase(unittest.TestCase):
@mock.patch('sys.argv', new=['prog', '--version'])
@mock.patch('sys.stderr', new_callable=six.StringIO)
@mock.patch('sys.stdout', new_callable=six.StringIO)
@mock.patch('pungi_cli_fake_pungi-koji.get_full_version', return_value='a-b-c.111')
@mock.patch('pungi.scripts.pungi_koji.get_full_version', return_value='a-b-c.111')
def test_version(self, get_full_version, stdout, stderr):
with self.assertRaises(SystemExit):
cli.main()
with self.assertRaises(SystemExit) as cm:
cli_main()
self.assertEqual(cm.exception.code, 0)
# Python 2.7 prints the version to stderr, 3.4+ to stdout.
if six.PY3:
self.assertMultiLineEqual(stdout.getvalue(), 'a-b-c.111\n')

View file

@ -1,30 +1,26 @@
# -*- coding: utf-8 -*-
import mock
import os
import subprocess
import sys
import six
from pungi.scripts.config_validate import cli_main
from tests import helpers
HERE = os.path.abspath(os.path.dirname(__file__))
BINDIR = os.path.join(HERE, '../bin')
PUNGI_CONFIG_VALIDATE = os.path.join(BINDIR, 'pungi-config-validate')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from tests import helpers
DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
class ConfigValidateScriptTest(helpers.PungiTestCase):
def test_validate_dummy_config(self):
DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
p = subprocess.Popen(
[sys.executable, "-W", "ignore", PUNGI_CONFIG_VALIDATE, DUMMY_CONFIG],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout, stderr) = p.communicate()
self.assertEqual(b'', stdout)
self.assertEqual(b'', stderr)
self.assertEqual(0, p.returncode)
@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())