2018-06-22 06:58:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
try:
|
|
|
|
import unittest2 as unittest
|
|
|
|
except ImportError:
|
|
|
|
import unittest
|
|
|
|
import tempfile
|
2018-10-12 12:50:46 +00:00
|
|
|
from textwrap import dedent
|
2018-06-22 06:58:54 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
|
|
|
|
from pungi.wrappers import fus
|
|
|
|
|
2018-10-12 12:50:46 +00:00
|
|
|
from .helpers import touch, PungiTestCase
|
2018-06-22 06:58:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestGetCmd(unittest.TestCase):
|
|
|
|
def test_minimum_command(self):
|
2018-10-12 12:50:46 +00:00
|
|
|
cmd = fus.get_cmd("conf", "x86_64", repos=[], lookasides=[])
|
|
|
|
self.assertEqual(cmd, ["fus", "--verbose", "--arch", "x86_64", "@conf"])
|
2018-06-22 06:58:54 +00:00
|
|
|
|
|
|
|
def test_full_command(self):
|
|
|
|
cmd = fus.get_cmd(
|
2018-10-12 12:50:46 +00:00
|
|
|
"conf",
|
2018-06-22 06:58:54 +00:00
|
|
|
"x86_64",
|
|
|
|
["/tmp/first", "/tmp/second"],
|
|
|
|
["/tmp/fst", "/tmp/snd"],
|
|
|
|
platform="f29",
|
2018-10-16 10:29:00 +00:00
|
|
|
filter_packages=["foo", "bar"],
|
2018-06-22 06:58:54 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
cmd,
|
|
|
|
[
|
|
|
|
"fus",
|
|
|
|
"--verbose",
|
|
|
|
"--arch",
|
|
|
|
"x86_64",
|
|
|
|
"--repo=lookaside-0,lookaside,/tmp/fst",
|
|
|
|
"--repo=lookaside-1,lookaside,/tmp/snd",
|
2018-10-03 11:19:38 +00:00
|
|
|
"--repo=repo-0,repo,/tmp/first",
|
|
|
|
"--repo=repo-1,repo,/tmp/second",
|
2018-06-22 06:58:54 +00:00
|
|
|
"--platform=f29",
|
2018-10-16 10:29:00 +00:00
|
|
|
"--exclude=bar",
|
|
|
|
"--exclude=foo",
|
2018-10-12 12:50:46 +00:00
|
|
|
"@conf",
|
2018-06-22 06:58:54 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2018-10-03 07:45:14 +00:00
|
|
|
def test_strip_file_protocol(self):
|
2018-10-12 12:50:46 +00:00
|
|
|
cmd = fus.get_cmd("conf", "x86_64", ["file:///tmp"], [])
|
2018-10-03 07:45:14 +00:00
|
|
|
self.assertEqual(
|
2018-10-12 12:50:46 +00:00
|
|
|
cmd,
|
|
|
|
[
|
|
|
|
"fus",
|
|
|
|
"--verbose",
|
|
|
|
"--arch",
|
|
|
|
"x86_64",
|
|
|
|
"--repo=repo-0,repo,/tmp",
|
|
|
|
"@conf",
|
|
|
|
],
|
2018-10-03 07:45:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_fail_on_http_repo(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2018-10-12 12:50:46 +00:00
|
|
|
fus.get_cmd("conf", "x86_64", ["http:///tmp"], [])
|
2018-10-03 07:45:14 +00:00
|
|
|
|
|
|
|
def test_strip_file_protocol_lookaside(self):
|
2018-10-12 12:50:46 +00:00
|
|
|
cmd = fus.get_cmd("conf", "x86_64", [], ["file:///r"])
|
2018-10-03 07:45:14 +00:00
|
|
|
self.assertEqual(
|
|
|
|
cmd,
|
2018-10-12 12:50:46 +00:00
|
|
|
[
|
|
|
|
"fus",
|
|
|
|
"--verbose",
|
|
|
|
"--arch",
|
|
|
|
"x86_64",
|
|
|
|
"--repo=lookaside-0,lookaside,/r",
|
|
|
|
"@conf",
|
|
|
|
],
|
2018-10-03 07:45:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_fail_on_http_repo_lookaside(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2018-10-12 12:50:46 +00:00
|
|
|
fus.get_cmd("conf", "x86_64", [], ["http:///tmp"])
|
|
|
|
|
|
|
|
|
|
|
|
class TestWriteConfig(PungiTestCase):
|
|
|
|
|
|
|
|
def test_write_sorted_mix(self):
|
|
|
|
f = os.path.join(self.topdir, "solvables")
|
|
|
|
fus.write_config(f, ["moda:master"], ["pkg", "foo"])
|
|
|
|
self.assertFileContent(
|
|
|
|
f,
|
|
|
|
dedent(
|
|
|
|
"""\
|
|
|
|
module(moda:master)
|
|
|
|
pkg
|
|
|
|
foo
|
|
|
|
"""
|
|
|
|
),
|
|
|
|
)
|
2018-10-03 07:45:14 +00:00
|
|
|
|
2018-06-22 06:58:54 +00:00
|
|
|
|
|
|
|
class TestParseOutput(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
_, self.file = tempfile.mkstemp(prefix="test-parse-fus-out-")
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
os.remove(self.file)
|
|
|
|
|
|
|
|
def test_skips_debug_line(self):
|
|
|
|
touch(self.file, "debug line\n")
|
2018-10-03 10:19:33 +00:00
|
|
|
packages, modules = fus.parse_output(self.file)
|
2018-06-22 06:58:54 +00:00
|
|
|
self.assertItemsEqual(packages, [])
|
2018-10-03 10:19:33 +00:00
|
|
|
self.assertItemsEqual(modules, [])
|
2018-06-22 06:58:54 +00:00
|
|
|
|
|
|
|
def test_separates_arch(self):
|
|
|
|
touch(self.file, "pkg-1.0-1.x86_64@repo-0\npkg-1.0-1.i686@repo-0\n")
|
2018-10-03 10:19:33 +00:00
|
|
|
packages, modules = fus.parse_output(self.file)
|
2018-06-22 06:58:54 +00:00
|
|
|
self.assertItemsEqual(
|
|
|
|
packages,
|
2018-07-31 12:01:19 +00:00
|
|
|
[("pkg-1.0-1", "x86_64", frozenset()), ("pkg-1.0-1", "i686", frozenset())],
|
2018-06-22 06:58:54 +00:00
|
|
|
)
|
2018-10-03 10:19:33 +00:00
|
|
|
self.assertItemsEqual(modules, [])
|
2018-06-22 06:58:54 +00:00
|
|
|
|
2018-07-31 12:01:19 +00:00
|
|
|
def test_marks_modular(self):
|
|
|
|
touch(self.file, "*pkg-1.0-1.x86_64@repo-0\n")
|
2018-10-03 10:19:33 +00:00
|
|
|
packages, modules = fus.parse_output(self.file)
|
2018-07-31 12:01:19 +00:00
|
|
|
self.assertItemsEqual(
|
|
|
|
packages,
|
|
|
|
[("pkg-1.0-1", "x86_64", frozenset(["modular"]))],
|
|
|
|
)
|
2018-10-03 10:19:33 +00:00
|
|
|
self.assertItemsEqual(modules, [])
|
|
|
|
|
|
|
|
def test_extracts_modules(self):
|
|
|
|
touch(self.file, "module:mod:master:20181003:cafebeef.x86_64@repo-0\n")
|
|
|
|
packages, modules = fus.parse_output(self.file)
|
|
|
|
self.assertItemsEqual(packages, [])
|
|
|
|
self.assertItemsEqual(modules, ["mod:master:20181003:cafebeef"])
|