Newer
Older
"""
test_pacman-mirrors
----------------------------------
Tests for `pacman-mirrors` module.
"""
import unittest
from unittest.mock import patch
from pacman_mirrors.pacman_mirrors import PacmanMirrors
from . import mock_configuration as conf
class TestCommandLineParse(unittest.TestCase):
"""Pacman Mirrors Test suite"""
def setUp(self):
"""Setup tests"""
pass
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_branch_unstable(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[branch] from ARG '-b unstable'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-b", "unstable"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["branch"] == "unstable"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_branch_testing(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[branch] from ARG '-b testing'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-b", "testing"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["branch"] == "testing"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_method(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[method] from ARG '-m random'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-m", "random"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["method"] == "random"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_mirrordir(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[mirror_dir] from ARG '-d /another/dir'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-d", "/another/dir/"]):
app = PacmanMirrors()
@patch.object(configfn, "build_config")
def test_arg_mirrorlist(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[mirror_list] from ARG '-o /another/list'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-o", "/another/list"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["mirror_list"] == "/another/list"
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_onlycountry(self, mock_build_config, mock_os_getuid):
"""TEST: CLI config[only_country] from ARG '-c France,Germany'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-c", "France,Germany"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.config["only_country"] == ["France", "Germany"]
@patch.object(configfn, "build_config")
def test_arg_custom_country(self, mock_build_config, mock_os_getuid):
"""TEST: CLI custom is True from ARG '-c Denmark'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-c Denmark"]):
app = PacmanMirrors()
@patch.object(configfn, "build_config")
def test_arg_geoip(self, mock_build_config, mock_os_getuid):
"""TEST: CLI geoip is True from ARG '--geoip'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"--geoip"]):
app = PacmanMirrors()
@patch.object(configfn, "build_config")
def test_arg_fasttrack(self, mock_build_config, mock_os_getuid):
"""TEST: CLI fasttrack is 5 from ARG '-f 5'"""
@patch.object(configfn, "build_config")
def test_arg_interactive(self, mock_build_config, mock_os_getuid):
"""TEST: CLI interactive is true from ARG '-i'"""
app.command_line_parse()
assert app.interactive is True
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_max_wait_time(self, mock_build_config, mock_os_getuid):
"""TEST: CLI max_wait_time is 5 from ARG '-t 5'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-t 5"]):
app = PacmanMirrors()
app.command_line_parse()
assert app.max_wait_time == 5
@patch("os.getuid")
@patch.object(configfn, "build_config")
def test_arg_quiet(self, mock_build_config, mock_os_getuid):
"""TEST: CLI quiet is True from ARG '-q'"""
with unittest.mock.patch("sys.argv",
["pacman-mirrors",
"-q"]):
app = PacmanMirrors()