From dbf841c689d3eeda28ee680a9121a5bf7eb0d00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=81?= Date: Tue, 1 Dec 2020 15:03:31 +0300 Subject: [PATCH] Using of the import_variables function in the variables files is available now. fixed #49 --- calculate/templates/template_processor.py | 4 +- calculate/variables/loader.py | 15 +- calculate/vars/main/cl/__init__.py | 73 ++++++---- calculate/vars/os/gentoo/__init__.py | 129 +++++++++--------- .../testfiles/variables_1/level/__init__.py | 100 +++++++------- .../variables_1/level/level_2/__init__.py | 10 +- .../testfiles/variables_10/main/__init__.py | 6 +- .../variables_10/main/cl/system/__init__.py | 32 ++--- .../testfiles/variables_10/os/__init__.py | 78 ++++++----- tests/vars/test_vars.py | 50 ++++--- 10 files changed, 274 insertions(+), 223 deletions(-) diff --git a/calculate/templates/template_processor.py b/calculate/templates/template_processor.py index c5429ee..8c1c680 100644 --- a/calculate/templates/template_processor.py +++ b/calculate/templates/template_processor.py @@ -2764,8 +2764,8 @@ class DirectoryProcessor: return False elif parameters.action.startswith('!'): action_matching = (parameters.action[1:].strip() not in - self.action) - elif parameters.action not in self.action: + self.action) + elif parameters.action not in self.action: action_matching = False else: action_matching = True diff --git a/calculate/variables/loader.py b/calculate/variables/loader.py index 693d8ae..2b1e9cb 100644 --- a/calculate/variables/loader.py +++ b/calculate/variables/loader.py @@ -245,7 +245,8 @@ class NamespaceIniFiller: self.current_namespace = None return - self.current_namespace = self.current_namespace._namespaces[section] + self.current_namespace = self.current_namespace.\ + _namespaces[section] def clear_section(self, sections: list, lineno) -> None: '''Метод для очистки пространства имен.''' @@ -310,7 +311,8 @@ class NamespaceIniFiller: table_name, section)) self.current_namespace = None return - self.current_namespace = self.current_namespace._namespaces[section] + self.current_namespace = self.current_namespace.\ + _namespaces[section] if table_name not in self.current_namespace._variables: if not self.modify_only: @@ -605,10 +607,12 @@ class VariableLoader: # importlib.import_module('{}.{}'.format(package, file_name)) spec = importlib.util.spec_from_file_location( - '{}.{}'.format(package, file_name), - file_node.path) + '{}.{}'.format(package, file_name), + file_node.path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) + if hasattr(module, 'import_variables'): + module.import_variables() # Обходим остальные директории. for directory_node in directory_nodes: @@ -752,7 +756,8 @@ class Datavars: # ini-файлах. try: self.variables_to_save = {target: dict() for target in - self.main.cl.system.env_order if target in + self.main.cl.system.env_order + if target in self.main.cl.system.env_path} except VariableNotFoundError: self.variables_to_save = dict() diff --git a/calculate/vars/main/cl/__init__.py b/calculate/vars/main/cl/__init__.py index 0ee1a23..6fe9472 100644 --- a/calculate/vars/main/cl/__init__.py +++ b/calculate/vars/main/cl/__init__.py @@ -1,11 +1,19 @@ import os from calculate.utils.fs import readFile -from calculate.variables.datavars import Variable, Namespace, Dependence, \ - StringType, BooleanType, HashType, Calculate +from calculate.variables.datavars import ( + Variable, + Namespace, + StringType, + BooleanType, + HashType, + Calculate + ) + def get_ebuild_phase(): return os.environ.get("EBUILD_PHASE", "") + def get_chroot_status(): """Detect chroot mode by different mountinfo""" pid = os.getpid() @@ -19,25 +27,16 @@ def get_chroot_status(): except Exception: return False + def is_system_boot(): if os.readlink('/proc/self/fd/0') == '/dev/console': return True else: return False -Variable("ebuild_phase", type=StringType, - source=Calculate(get_ebuild_phase)) -Variable("chroot_status", type=BooleanType, - source=Calculate(get_chroot_status)) -Variable("system_boot_set", type=BooleanType, - source=Calculate(is_system_boot)) - -# Переменная, в которую будут помещаться пути к текущим шаблонам. -Variable("current_template", type=StringType, source="") class CmdlineParams(object): - """ - Параметры опции загрузки ядра calculate= + """Параметры опции загрузки ядра calculate= """ # названия параметров Calculate = "calculate" @@ -56,6 +55,7 @@ class CmdlineParams(object): Audio = "audio" Clock = "clock" + def get_cmdline_parameter(paramname): cmdLine = "/proc/cmdline" for param in readFile(cmdLine).split(" "): @@ -64,6 +64,7 @@ def get_cmdline_parameter(paramname): return value return None + def get_calculate_cmdline(): names = ( CmdlineParams.Locale, @@ -77,7 +78,7 @@ def get_calculate_cmdline(): CmdlineParams.Audio, CmdlineParams.Clock) # try get timezone from kernel calculate param - params = {x:"" for x in names} + params = {x: "" for x in names} try: value = get_cmdline_parameter(CmdlineParams.Calculate) if value is not None: @@ -89,27 +90,45 @@ def get_calculate_cmdline(): pass return params + def get_isoscan_filename(): value = get_cmdline_parameter(CmdlineParams.IsoscanFile) if value is not None: return value return "" + def get_isoscan_fullpath(base_path, filename): if filename: return os.path.join(base_path.value, filename.value.lstrip("/")) return "" -with Namespace('cmdline'): - Variable("calculate", type=HashType.fixed, - source=Calculate(get_calculate_cmdline)) - Variable("isoscan_filename", type=StringType, - source=Calculate(get_isoscan_filename)) - -with Namespace('isoscan'): - Variable("base_path", type=StringType, - source="/run/initramfs/isoscan") - Variable("full_path", type=StringType, - source=Calculate(get_isoscan_fullpath, - '.base_path', 'main.cl.cmdline.isoscan_filename' - )) + +def import_variables(): + Variable("ebuild_phase", type=StringType, + source=Calculate(get_ebuild_phase)) + + Variable("chroot_status", type=BooleanType, + source=Calculate(get_chroot_status)) + + Variable("system_boot_set", type=BooleanType, + source=Calculate(is_system_boot)) + + # Переменная, в которую будут помещаться пути к текущим шаблонам. + Variable("current_template", type=StringType, source="") + + with Namespace('cmdline'): + Variable("calculate", type=HashType.fixed, + source=Calculate(get_calculate_cmdline)) + + Variable("isoscan_filename", type=StringType, + source=Calculate(get_isoscan_filename)) + + with Namespace('isoscan'): + Variable("base_path", type=StringType, + source="/run/initramfs/isoscan") + + Variable("full_path", type=StringType, + source=Calculate(get_isoscan_fullpath, + '.base_path', + 'main.cl.cmdline.isoscan_filename')) diff --git a/calculate/vars/os/gentoo/__init__.py b/calculate/vars/os/gentoo/__init__.py index 90b7890..3ac57c9 100644 --- a/calculate/vars/os/gentoo/__init__.py +++ b/calculate/vars/os/gentoo/__init__.py @@ -3,78 +3,79 @@ from calculate.utils.files import stderr_devnull from calculate.utils.files import read_link, FilesError from calculate.variables.datavars import Variable, Namespace, Dependence,\ StringType, TableType -''' -gentoo: - make_profile -> string - profile: - path -> string - name -> string - repositories[*]{name, path} -> table - config -> undefined -''' -# Путь до файла, указывающего на активный профиль -Variable('make_profile', type=StringType, source='/etc/portage/make.profile') -# Параметры текущего профиля. -with Namespace('profile'): - def get_profile_link(make_profile): - make_profile_dir = os.path.dirname(make_profile.value) - try: - profile_link = read_link(make_profile.value) - except FilesError: - return "" +def import_variables(): + ''' + gentoo: + make_profile -> string + profile: + path -> string + name -> string + repositories[*]{name, path} -> table + config -> undefined + ''' - if profile_link: - profile_link = os.path.normpath( - os.path.join(make_profile_dir, profile_link)) - return profile_link - else: - return "" - # Абсолютный путь до профиля - Variable('path', type=StringType, - source=Dependence('..make_profile', depend=get_profile_link)) + # Путь до файла, указывающего на активный профиль + Variable('make_profile', type=StringType, + source='/etc/portage/make.profile') - def get_profile_name(path, repositories): - profile_path = path.value - if not profile_path: - return "" + # Параметры текущего профиля. + with Namespace('profile'): + def get_profile_link(make_profile): + make_profile_dir = os.path.dirname(make_profile.value) + try: + profile_link = read_link(make_profile.value) + except FilesError: + return "" - for repository in repositories.value: - repository_path = repository['path'] - repository_name = repository['name'] - remove_part = os.path.normpath(os.path.join(repository_path, - "profiles")) - if profile_path.startswith(remove_part): - return "{}:{}".format(repository_name, - profile_path[len(remove_part) + 1:]) - return profile_path - # Название профиля - Variable('name', type=StringType, - source=Dependence('.path', '..repositories', - depend=get_profile_name)) + if profile_link: + profile_link = os.path.normpath(os.path.join(make_profile_dir, + profile_link)) + return profile_link + else: + return "" + # Абсолютный путь до профиля + Variable('path', type=StringType, + source=Dependence('..make_profile', depend=get_profile_link)) + def get_profile_name(path, repositories): + profile_path = path.value + if not profile_path: + return "" -def get_repository_table(config): - return [{'name': name, - 'path': path} - for path, name in config.value.repositories.location_map.items()] + for repository in repositories.value: + repository_path = repository['path'] + repository_name = repository['name'] + remove_part = os.path.normpath(os.path.join(repository_path, + "profiles")) + if profile_path.startswith(remove_part): + return "{}:{}".format(repository_name, + profile_path[len(remove_part) + 1:]) + return profile_path + # Название профиля + Variable('name', type=StringType, + source=Dependence('.path', '..repositories', + depend=get_profile_name)) + def get_repository_table(config): + return [{'name': name, + 'path': path} + for path, name + in config.value.repositories.location_map.items()] -# Информация о репозиториях -# name: имя репозитория -# path: полный путь до репозитория -Variable('repositories', type=TableType, - source=Dependence('.config', depend=get_repository_table)) + # Информация о репозиториях + # name: имя репозитория + # path: полный путь до репозитория + Variable('repositories', type=TableType, + source=Dependence('.config', depend=get_repository_table)) + def get_config_object(chroot_path): + from portage.package.ebuild.config import config + if chroot_path.value == '/': + with stderr_devnull(): + return config() -def get_config_object(chroot_path): - from portage.package.ebuild.config import config - if chroot_path.value == '/': - with stderr_devnull(): - return config() - - -# Объект текущей конфигурации Portage -Variable('config', source=Dependence('main.cl_chroot_path', - depend=get_config_object)) + # Объект текущей конфигурации Portage + Variable('config', source=Dependence('main.cl_chroot_path', + depend=get_config_object)) diff --git a/tests/variables/testfiles/variables_1/level/__init__.py b/tests/variables/testfiles/variables_1/level/__init__.py index 37d9d80..b32967e 100644 --- a/tests/variables/testfiles/variables_1/level/__init__.py +++ b/tests/variables/testfiles/variables_1/level/__init__.py @@ -1,62 +1,68 @@ -from calculate.variables.datavars import Namespace, Variable, Dependence,\ - StringType, HashType, TableType,\ - ListType, FloatType - - -Variable('simple', type=StringType, source='simple value') - -Variable('use_local_simple', type=StringType, - source=Dependence('.simple', - depend=lambda simple: 'Using {}'.format( +def import_variables(): + from calculate.variables.datavars import ( + Namespace, + Variable, + Dependence, + StringType, + HashType, + TableType, + ListType, + FloatType + ) + + Variable('simple', type=StringType, source='simple value') + + Variable('use_local_simple', type=StringType, + source=Dependence('.simple', + depend=lambda simple: 'Using {}'.format( simple.value))) -Variable('use_full_simple', type=StringType, - source=Dependence('level.simple', - depend=lambda simple: 'Using {}'.format( + Variable('use_full_simple', type=StringType, + source=Dependence('level.simple', + depend=lambda simple: 'Using {}'.format( simple.value))) -Variable('disks', type=ListType, - source=["/dev/sda1", "/dev/sda2", "/dev/sda3"]) + Variable('disks', type=ListType, + source=["/dev/sda1", "/dev/sda2", "/dev/sda3"]) -Variable('version', type=FloatType, source='1.0') + Variable('version', type=FloatType, source='1.0') -Variable('my_shortname', type=StringType, source='CLD') + Variable('my_shortname', type=StringType, source='CLD') -Variable('linux', type=HashType, - source=Dependence('.version', '.my_shortname', - depend=lambda version, my_shortname: - {'version': version.value, - 'shortname': my_shortname.value})) + Variable('linux', type=HashType, + source=Dependence('.version', '.my_shortname', + depend=lambda version, my_shortname: + {'version': version.value, + 'shortname': my_shortname.value})) -Variable('shortname_test', type=StringType, - source=Dependence('.linux.shortname', - depend=lambda shortname: '{} test'.format( + Variable('shortname_test', type=StringType, + source=Dependence('.linux.shortname', + depend=lambda shortname: '{} test'.format( shortname.value))) -Variable('device_list', type=ListType, - source=["/dev/sda", "/dev/sdb"]) - - -def get_device_table(device_list): - map_data = {'/dev/sda': ["hdd", "Samsung SSD"], - '/dev/sdb': ["flash", "Transcend 64GB"], - '/dev/sdc': ["usbhdd", "WD 1TB"]} - default_value = ["hdd", "Unknown"] - print('device_list = {}'.format(device_list.value)) - return [{"dev": device, - "type": map_data.get(device, default_value)[0], - "name": map_data.get(device, default_value)[1]} - for device in device_list.value] + Variable('device_list', type=ListType, + source=["/dev/sda", "/dev/sdb"]) + def get_device_table(device_list): + map_data = {'/dev/sda': ["hdd", "Samsung SSD"], + '/dev/sdb': ["flash", "Transcend 64GB"], + '/dev/sdc': ["usbhdd", "WD 1TB"]} + default_value = ["hdd", "Unknown"] + print('device_list = {}'.format(device_list.value)) + return [{"dev": device, + "type": map_data.get(device, default_value)[0], + "name": map_data.get(device, default_value)[1]} + for device in device_list.value] -Variable('device', type=TableType, source=Dependence('.device_list', - depend=get_device_table)) + Variable('device', type=TableType, source=Dependence( + '.device_list', + depend=get_device_table)) -Variable('device_child', type=StringType, - source=Dependence('.device', - depend=lambda device: device.value[0]['type'])) + Variable('device_child', type=StringType, + source=Dependence('.device', + depend=lambda device: device.value[0]['type'])) -with Namespace('level_3'): - Variable('my_var_1', type=StringType, source='testing') + with Namespace('level_3'): + Variable('my_var_1', type=StringType, source='testing') - Variable('my_var_2', type=StringType, source='testing_2') + Variable('my_var_2', type=StringType, source='testing_2') diff --git a/tests/variables/testfiles/variables_1/level/level_2/__init__.py b/tests/variables/testfiles/variables_1/level/level_2/__init__.py index 5d066ae..b27e455 100644 --- a/tests/variables/testfiles/variables_1/level/level_2/__init__.py +++ b/tests/variables/testfiles/variables_1/level/level_2/__init__.py @@ -1,6 +1,6 @@ -from calculate.variables.datavars import Variable, StringType, Calculate +def import_variables(): + from calculate.variables.datavars import Variable, StringType, Calculate - -Variable('vargetter', type=StringType, - source=Calculate(lambda chroot: '{} test'.format(chroot.value), - 'main.chroot')) + Variable('vargetter', type=StringType, + source=Calculate(lambda chroot: '{} test'.format(chroot.value), + 'main.chroot')) diff --git a/tests/variables/testfiles/variables_10/main/__init__.py b/tests/variables/testfiles/variables_10/main/__init__.py index 43d6a38..6e440ee 100644 --- a/tests/variables/testfiles/variables_10/main/__init__.py +++ b/tests/variables/testfiles/variables_10/main/__init__.py @@ -1,4 +1,4 @@ -from calculate.variables.datavars import Variable, StringType +def import_variables(): + from calculate.variables.datavars import Variable, StringType - -Variable('chroot', type=StringType.readonly, source='/') + Variable('chroot', type=StringType.readonly, source='/') diff --git a/tests/variables/testfiles/variables_10/main/cl/system/__init__.py b/tests/variables/testfiles/variables_10/main/cl/system/__init__.py index 4b3f3cb..bd8504c 100644 --- a/tests/variables/testfiles/variables_10/main/cl/system/__init__.py +++ b/tests/variables/testfiles/variables_10/main/cl/system/__init__.py @@ -1,19 +1,17 @@ -import os -from calculate.variables.datavars import Variable, ListType, HashType -''' -system: - env_order -> list - env_path -> hash -''' +def import_variables(): + ''' + system: + env_order -> list + env_path -> hash + ''' + import os + from calculate.variables.datavars import Variable, ListType, HashType + TESTFILES_PATH = os.path.join(os.getcwd(), 'tests/variables/testfiles') + # Список мест, где есть calculate.ini файлы. + Variable('env_order', type=ListType, source=['system', 'local']) -TESTFILES_PATH = os.path.join(os.getcwd(), 'tests/variables/testfiles') - - -# Список мест, где есть calculate.ini файлы. -Variable('env_order', type=ListType, source=['system', 'local']) - -# Отображение множества мест, где есть calculate.ini файлы, на пути к ним. -Variable('env_path', type=HashType, - source={'system': os.path.join(TESTFILES_PATH, - 'ini_vars/calculate_6.ini')}) + # Отображение множества мест, где есть calculate.ini файлы, на пути к ним. + Variable('env_path', type=HashType, + source={'system': os.path.join(TESTFILES_PATH, + 'ini_vars/calculate_6.ini')}) diff --git a/tests/variables/testfiles/variables_10/os/__init__.py b/tests/variables/testfiles/variables_10/os/__init__.py index 65d101c..8b17c1b 100644 --- a/tests/variables/testfiles/variables_10/os/__init__.py +++ b/tests/variables/testfiles/variables_10/os/__init__.py @@ -1,50 +1,60 @@ -from calculate.variables.datavars import Namespace, Variable, Dependence,\ - StringType, HashType, TableType,\ - ListType, IntegerType, FloatType +def import_variables(): + from calculate.variables.datavars import ( + Namespace, + Variable, + Dependence, + StringType, + HashType, + TableType, + IntegerType, + FloatType + ) -with Namespace('linux'): - Variable('shortname', source='', type=StringType) + with Namespace('linux'): + Variable('shortname', source='', type=StringType) - Variable('ver', source='', type=StringType) + Variable('ver', source='', type=StringType) - Variable('fullname', source='', type=StringType) + Variable('fullname', source='', type=StringType) - Variable('subname', source='', type=StringType) + Variable('subname', source='', type=StringType) - Variable('arch', source='', type=StringType) + Variable('arch', source='', type=StringType) - Variable('test_1', source=12, type=IntegerType) + Variable('test_1', source=12, type=IntegerType) - Variable('test_2', source=1.2, type=FloatType) + Variable('test_2', source=1.2, type=FloatType) - def get_title(subname, fullname, ver): - if subname.value: - return '{} {} {}'.format(fullname.value, subname.value, ver.value) - else: - return '{} {}'.format(fullname.value, ver.value) - Variable('title', type=StringType, - source=Dependence('.subname', '.fullname', '.ver', - depend=get_title)) + def get_title(subname, fullname, ver): + if subname.value: + return '{} {} {}'.format(fullname.value, + subname.value, + ver.value) + else: + return '{} {}'.format(fullname.value, ver.value) + Variable('title', type=StringType, + source=Dependence('.subname', '.fullname', '.ver', + depend=get_title)) -Variable('hashvar', source={'value1': 'test1', - 'value2': 'test2'}, type=HashType) + Variable('hashvar', source={'value1': 'test1', + 'value2': 'test2'}, type=HashType) -Variable('hashvar_0', source={'value1': 'test1', - 'value2': 'test2'}, type=HashType) + Variable('hashvar_0', source={'value1': 'test1', + 'value2': 'test2'}, type=HashType) -Variable('hashvar_1', source={'key1': 'value1', - 'key2': 'value2'}, type=HashType) + Variable('hashvar_1', source={'key1': 'value1', + 'key2': 'value2'}, type=HashType) -Variable('hashvar_2', source={'id_1': 1349, - 'id_2': 1575}, type=HashType) + Variable('hashvar_2', source={'id_1': 1349, + 'id_2': 1575}, type=HashType) -Variable('calculate', type=StringType, - source=Dependence('.hashvar_0', - depend=lambda hashvar: "{} {}".format( + Variable('calculate', type=StringType, + source=Dependence('.hashvar_0', + depend=lambda hashvar: "{} {}".format( hashvar.value['value1'], hashvar.value['value2']))) -Variable('tablevar', type=TableType, source=[{"dev": "/dev/sdb1", - "mount": "/"}, - {"dev": "/dev/sdb2", - "mount": "/var/calculate"}]) + Variable('tablevar', type=TableType, source=[{"dev": "/dev/sdb1", + "mount": "/"}, + {"dev": "/dev/sdb2", + "mount": "/var/calculate"}]) diff --git a/tests/vars/test_vars.py b/tests/vars/test_vars.py index cf50ebe..9662680 100644 --- a/tests/vars/test_vars.py +++ b/tests/vars/test_vars.py @@ -7,11 +7,14 @@ import calculate.vars.install.os.func as install_os import mock from itertools import chain + class Var: def __init__(self, value): self.value = value -@pytest.mark.parametrize('case', + +@pytest.mark.parametrize( + 'case', [ { "name": "failed xdpyinfo", @@ -21,7 +24,7 @@ class Var: }, { "name": "worked xdpyinfo", "failed": False, - "data": open('tests/vars/xdpyinfo.output','r').read(), + "data": open('tests/vars/xdpyinfo.output', 'r').read(), "result": "1920x1080" }, { @@ -31,15 +34,17 @@ class Var: "result": "" }, ], - ids=lambda x:x["name"]) + ids=lambda x: x["name"]) @pytest.mark.calculate_vars def test_main_os_x11_resolution(case): with mock.patch('calculate.vars.main.os.x11.Process.failed') as failed: - with mock.patch('calculate.vars.main.os.x11.Process.read_lines') as read_lines: + with mock.patch('calculate.vars.main.os.x11.Process.read_lines' + ) as read_lines: failed.return_value = case["failed"] read_lines.return_value = case["data"].split("\n") assert main_os_x11.get_resolution_by_xdpyinfo() == case["result"] + empty_calculate_cmdhash = { CmdlineParams.Locale: "", CmdlineParams.Keymap: "", @@ -53,10 +58,13 @@ empty_calculate_cmdhash = { CmdlineParams.Clock: "" } + def concat_dict(d1, **d2): - return {x:y for x,y in chain(d1.items(),d2.items())} + return {x: y for x, y in chain(d1.items(), d2.items())} -@pytest.mark.parametrize('case', + +@pytest.mark.parametrize( + 'case', [ { "name": "empty cmdline", @@ -89,7 +97,7 @@ def concat_dict(d1, **d2): "result": concat_dict(empty_calculate_cmdhash, video="nvidia", resolution="1920x1080") }, ], - ids=lambda x:x["name"]) + ids=lambda x: x["name"]) @pytest.mark.calculate_vars def test_main_cl_cmdline(case): with mock.patch('calculate.vars.main.cl.readFile') as readFile: @@ -97,7 +105,8 @@ def test_main_cl_cmdline(case): assert main_cl.get_calculate_cmdline() == case["result"] -@pytest.mark.parametrize('case', +@pytest.mark.parametrize( + 'case', [ { "source": "i686", @@ -112,18 +121,19 @@ def test_main_cl_cmdline(case): "result": "amd64" }, ], - ids=lambda x:"{}->{}".format(x["source"],x["result"])) + ids=lambda x: "{}->{}".format(x["source"], x["result"])) @pytest.mark.calculate_vars def test_main_os_get_arch_gentoo(case): assert main_os.get_arch_gentoo(Var(case["source"])) == case["result"] -@pytest.mark.parametrize('case', +@pytest.mark.parametrize( + 'case', [ { "name": "pulseaudio exists", "exists": True, - "result": ["alsa","pulseaudio"] + "result": ["alsa", "pulseaudio"] }, { "name": "pulseaudio not exists", @@ -131,18 +141,20 @@ def test_main_os_get_arch_gentoo(case): "result": ["alsa"] }, ], - ids=lambda x:x["name"]) + ids=lambda x: x["name"]) @pytest.mark.calculate_vars def test_install_os_get_available_audio_system(case): with mock.patch('calculate.vars.install.os.func.PackageAtomParser.is_package_exists') as exists: exists.return_value = case["exists"] assert install_os.get_available_audio_system() == case["result"] -@pytest.mark.parametrize('case', + +@pytest.mark.parametrize( + 'case', [ { "name": "default all available", - "available_systems": ["alsa","pulseaudio"], + "available_systems": ["alsa", "pulseaudio"], "cmdline_audio": "", "result": "pulseaudio" }, @@ -154,19 +166,19 @@ def test_install_os_get_available_audio_system(case): }, { "name": "all available alsa selected", - "available_systems": ["alsa","pulseaudio"], + "available_systems": ["alsa", "pulseaudio"], "cmdline_audio": "alsa", "result": "alsa" }, { "name": "all available pulse selected", - "available_systems": ["alsa","pulseaudio"], + "available_systems": ["alsa", "pulseaudio"], "cmdline_audio": "pulseaudio", "result": "pulseaudio" }, { "name": "all available wrong cmd line", - "available_systems": ["alsa","pulseaudio"], + "available_systems": ["alsa", "pulseaudio"], "cmdline_audio": "wrong", "result": "pulseaudio" }, @@ -177,9 +189,9 @@ def test_install_os_get_available_audio_system(case): "result": "alsa" }, ], - ids=lambda x:x["name"]) + ids=lambda x: x["name"]) @pytest.mark.calculate_vars -def test_install_os_get_available_audio_system(case): +def test_install_os_get_available_audio_system_other(case): assert install_os.get_audio_selected( Var(case["available_systems"]), Var(case["cmdline_audio"])) == case["result"]