mirror of
https://github.com/TheLocehiliosan/yadm
synced 2026-03-02 03:49:29 +00:00
Merge pull request #203 from jameshclrk/arch-alternative
This commit is contained in:
@@ -74,6 +74,12 @@ def tst_sys():
|
||||
return platform.system()
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def tst_arch():
|
||||
"""Test session's uname value"""
|
||||
return platform.machine()
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def supported_commands():
|
||||
"""List of supported commands
|
||||
|
||||
@@ -82,6 +82,7 @@ def test_relative_link(runner, paths, yadm_alt):
|
||||
@pytest.mark.parametrize('suffix', [
|
||||
'##default',
|
||||
'##default,e.txt', '##default,extension.txt',
|
||||
'##a.$tst_arch', '##arch.$tst_arch', '##architecture.$tst_arch',
|
||||
'##o.$tst_sys', '##os.$tst_sys',
|
||||
'##d.$tst_distro', '##distro.$tst_distro',
|
||||
'##c.$tst_class', '##class.$tst_class',
|
||||
@@ -90,7 +91,7 @@ def test_relative_link(runner, paths, yadm_alt):
|
||||
])
|
||||
def test_alt_conditions(
|
||||
runner, paths,
|
||||
tst_sys, tst_distro, tst_host, tst_user, suffix):
|
||||
tst_arch, tst_sys, tst_distro, tst_host, tst_user, suffix):
|
||||
"""Test conditions supported by yadm alt"""
|
||||
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||
|
||||
@@ -99,6 +100,7 @@ def test_alt_conditions(
|
||||
utils.set_local(paths, 'class', tst_class)
|
||||
|
||||
suffix = string.Template(suffix).substitute(
|
||||
tst_arch=tst_arch,
|
||||
tst_sys=tst_sys,
|
||||
tst_distro=tst_distro,
|
||||
tst_class=tst_class,
|
||||
|
||||
@@ -6,25 +6,29 @@ CONDITION = {
|
||||
'labels': ['default'],
|
||||
'modifier': 0,
|
||||
},
|
||||
'arch': {
|
||||
'labels': ['a', 'arch', 'architecture'],
|
||||
'modifier': 1,
|
||||
},
|
||||
'system': {
|
||||
'labels': ['o', 'os'],
|
||||
'modifier': 1,
|
||||
'modifier': 2,
|
||||
},
|
||||
'distro': {
|
||||
'labels': ['d', 'distro'],
|
||||
'modifier': 2,
|
||||
'modifier': 4,
|
||||
},
|
||||
'class': {
|
||||
'labels': ['c', 'class'],
|
||||
'modifier': 4,
|
||||
'modifier': 8,
|
||||
},
|
||||
'hostname': {
|
||||
'labels': ['h', 'hostname'],
|
||||
'modifier': 8,
|
||||
'modifier': 16,
|
||||
},
|
||||
'user': {
|
||||
'labels': ['u', 'user'],
|
||||
'modifier': 16,
|
||||
'modifier': 32,
|
||||
},
|
||||
}
|
||||
TEMPLATE_LABELS = ['t', 'template', 'yadm']
|
||||
@@ -44,6 +48,12 @@ def calculate_score(filename):
|
||||
label, value = condition.split('.', 1)
|
||||
if label in CONDITION['default']['labels']:
|
||||
score += 1000
|
||||
elif label in CONDITION['arch']['labels']:
|
||||
if value == 'testarch':
|
||||
score += 1000 + CONDITION['arch']['modifier']
|
||||
else:
|
||||
score = 0
|
||||
break
|
||||
elif label in CONDITION['system']['labels']:
|
||||
if value == 'testsystem':
|
||||
score += 1000 + CONDITION['system']['modifier']
|
||||
@@ -82,6 +92,8 @@ def calculate_score(filename):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'default', ['default', None], ids=['default', 'no-default'])
|
||||
@pytest.mark.parametrize(
|
||||
'arch', ['arch', None], ids=['arch', 'no-arch'])
|
||||
@pytest.mark.parametrize(
|
||||
'system', ['system', None], ids=['system', 'no-system'])
|
||||
@pytest.mark.parametrize(
|
||||
@@ -93,10 +105,11 @@ def calculate_score(filename):
|
||||
@pytest.mark.parametrize(
|
||||
'user', ['user', None], ids=['user', 'no-user'])
|
||||
def test_score_values(
|
||||
runner, yadm, default, system, distro, cla, host, user):
|
||||
runner, yadm, default, arch, system, distro, cla, host, user):
|
||||
"""Test score results"""
|
||||
# pylint: disable=too-many-branches
|
||||
local_class = 'testclass'
|
||||
local_arch = 'testarch'
|
||||
local_system = 'testsystem'
|
||||
local_distro = 'testdistro'
|
||||
local_host = 'testhost'
|
||||
@@ -111,6 +124,18 @@ def test_score_values(
|
||||
newfile += ','
|
||||
newfile += label
|
||||
filenames[newfile] = calculate_score(newfile)
|
||||
if arch:
|
||||
for filename in list(filenames):
|
||||
for match in [True, False]:
|
||||
for label in CONDITION[arch]['labels']:
|
||||
newfile = filename
|
||||
if not newfile.endswith('##'):
|
||||
newfile += ','
|
||||
newfile += '.'.join([
|
||||
label,
|
||||
local_arch if match else 'badarch'
|
||||
])
|
||||
filenames[newfile] = calculate_score(newfile)
|
||||
if system:
|
||||
for filename in list(filenames):
|
||||
for match in [True, False]:
|
||||
@@ -176,6 +201,7 @@ def test_score_values(
|
||||
YADM_TEST=1 source {yadm}
|
||||
score=0
|
||||
local_class={local_class}
|
||||
local_arch={local_arch}
|
||||
local_system={local_system}
|
||||
local_distro={local_distro}
|
||||
local_host={local_host}
|
||||
@@ -221,6 +247,7 @@ def test_extensions(runner, yadm, ext):
|
||||
def test_score_values_templates(runner, yadm):
|
||||
"""Test score results"""
|
||||
local_class = 'testclass'
|
||||
local_arch = 'arch'
|
||||
local_system = 'testsystem'
|
||||
local_distro = 'testdistro'
|
||||
local_host = 'testhost'
|
||||
@@ -239,6 +266,7 @@ def test_score_values_templates(runner, yadm):
|
||||
YADM_TEST=1 source {yadm}
|
||||
score=0
|
||||
local_class={local_class}
|
||||
local_arch={local_arch}
|
||||
local_system={local_system}
|
||||
local_distro={local_distro}
|
||||
local_host={local_host}
|
||||
|
||||
Reference in New Issue
Block a user