Added format 'world'.

master
Иванов Денис 3 years ago
parent e59a4511d6
commit 327d0ae56a

@ -19,9 +19,11 @@ class BackgroundsFormat(Format):
def __init__(self, template_text: str, def __init__(self, template_text: str,
template_path: str, template_path: str,
parameters: ParametersContainer, parameters: ParametersContainer = ParametersContainer(),
datavars: Union[Datavars, NamespaceNode, Variables], datavars: Union[Datavars,
chroot_path: str = "/"): NamespaceNode,
Variables] = NamespaceNode("<root>"),
**kwargs):
self._lines: List[str] = [line for line self._lines: List[str] = [line for line
in template_text.strip().split('\n') if line] in template_text.strip().split('\n') if line]
self._datavars: Union[Datavars, NamespaceNode, Variables] = datavars self._datavars: Union[Datavars, NamespaceNode, Variables] = datavars
@ -55,7 +57,6 @@ class BackgroundsFormat(Format):
if not self._check_source(self._source, target_path, self._mirror): if not self._check_source(self._source, target_path, self._mirror):
return self.changed_files return self.changed_files
print(f"FAKE_CHROOT: {self._fake_chroot}")
self._magician = ImageMagick( self._magician = ImageMagick(
chroot=chroot_path if not self._fake_chroot else "/") chroot=chroot_path if not self._fake_chroot else "/")
source_resolution = self._magician.get_image_resolution(self._source) source_resolution = self._magician.get_image_resolution(self._source)
@ -276,7 +277,6 @@ class BackgroundsFormat(Format):
"""Метод для получения md5-суммы текущего действия шаблона, """Метод для получения md5-суммы текущего действия шаблона,
рассчитываемой из последовательности байтов изображения и списка рассчитываемой из последовательности байтов изображения и списка
разрешений, в которые данный файл должен быть конвертирован.""" разрешений, в которые данный файл должен быть конвертирован."""
print("RESOLUTIONS:", resolutions)
with open(source, "rb") as source_file: with open(source, "rb") as source_file:
md5_object = hashlib.md5(source_file.read()) md5_object = hashlib.md5(source_file.read())
for width, height in resolutions: for width, height in resolutions:

@ -4,7 +4,6 @@
# не весь файл -- выдаем ошибку. # не весь файл -- выдаем ошибку.
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, OneOrMore, Word, alphanums, Literal,\ from pyparsing import originalTextFor, OneOrMore, Word, alphanums, Literal,\
ZeroOrMore, Forward, Optional, Group, restOfLine,\ ZeroOrMore, Forward, Optional, Group, restOfLine,\
@ -26,7 +25,7 @@ class BINDFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [] processing_methods = []
super().__init__(processing_methods) super().__init__(processing_methods)

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
alphanums, ParseException, restOfLine, Group, Optional,\ alphanums, ParseException, restOfLine, Group, Optional,\
@ -27,7 +26,7 @@ class CompizFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_section_line, self._parse_section_line,
self._parse_parameter_line, self._parse_parameter_line,

@ -5,11 +5,7 @@ from .base_format import Format, FormatError
from calculate.utils.files import join_paths from calculate.utils.files import join_paths
from pyparsing import Literal, Regex, SkipTo, LineEnd, lineno, LineStart from pyparsing import Literal, Regex, SkipTo, LineEnd, lineno, LineStart
from calculate.utils.package import PackageAtomParser, Package, PackageNotFound from calculate.utils.package import PackageAtomParser, Package, PackageNotFound
from ..template_engine import ParametersContainer, Variables
from ...variables.datavars import NamespaceNode
from ...variables.loader import Datavars
from fnmatch import fnmatch from fnmatch import fnmatch
from typing import Union
from glob import iglob from glob import iglob
@ -29,8 +25,7 @@ class ContentsFormat(Format):
def __init__(self, template_text: str, def __init__(self, template_text: str,
template_path: str, template_path: str,
parameters: ParametersContainer, **kwargs):
datavars: Union[Datavars, NamespaceNode, Variables]):
self._command_methods = {ADD: self._add_command, self._command_methods = {ADD: self._add_command,
REMOVE: self._remove_command, REMOVE: self._remove_command,
MOVE: self._move_command} MOVE: self._move_command}

@ -4,7 +4,6 @@
# документа. # документа.
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, Word, printables, alphanums,\ from pyparsing import originalTextFor, Literal, Word, printables, alphanums,\
ParseException, Regex, Group, Optional, alphas, lineEnd,\ ParseException, Regex, Group, Optional, alphas, lineEnd,\
@ -30,7 +29,7 @@ class DovecotFormat(Format):
join_before: bool = False, join_before: bool = False,
add_header: bool = False, add_header: bool = False,
already_changed: bool = False, already_changed: bool = False,
parameters: ParametersContainer = ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_section_start_line, self._parse_section_start_line,
self._parse_include_line, self._parse_include_line,

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
import json import json
@ -16,9 +15,7 @@ class JSONFormat(Format):
template_path: str, template_path: str,
ignore_comments: bool = False, ignore_comments: bool = False,
join_before: bool = False, join_before: bool = False,
add_header: bool = False, **kwargs):
already_changed: bool = False,
parameters: ParametersContainer = ParametersContainer()):
processing_methods: list = [] processing_methods: list = []
super().__init__(processing_methods) super().__init__(processing_methods)
self._ignore_comments: bool = ignore_comments self._ignore_comments: bool = ignore_comments

@ -27,7 +27,7 @@ class KDEFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_section_line, self._parse_section_line,
self._parse_parameter_line, self._parse_parameter_line,

@ -27,7 +27,7 @@ class KernelFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_parameter_line, self._parse_parameter_line,
self._parse_to_delete_line] self._parse_to_delete_line]

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
alphanums, ParseException, restOfLine, nums,\ alphanums, ParseException, restOfLine, nums,\
@ -27,7 +26,7 @@ class LDAPFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_type_line, self._parse_type_line,
self._parse_access_line, self._parse_access_line,

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, printables, originalTextFor, OneOrMore,\ from pyparsing import Word, Literal, printables, originalTextFor, OneOrMore,\
ParseException, restOfLine, Group, Optional, Regex ParseException, restOfLine, Group, Optional, Regex
@ -26,7 +25,7 @@ class OpenRCFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_parameter_line, self._parse_parameter_line,
self._parse_to_delete_line] self._parse_to_delete_line]

@ -3,10 +3,6 @@
from .base_format import Format from .base_format import Format
from calculate.utils.files import Process from calculate.utils.files import Process
from calculate.templates.format.base_format import FormatError from calculate.templates.format.base_format import FormatError
from ..template_engine import ParametersContainer, Variables
from ...variables.datavars import NamespaceNode
from ...variables.loader import Datavars
from typing import Union
from os import path from os import path
@ -16,8 +12,7 @@ class PatchFormat(Format):
def __init__(self, patch_text: str, def __init__(self, patch_text: str,
template_path: str, template_path: str,
parameters: ParametersContainer, **kwargs):
datavars: Union[Datavars, NamespaceNode, Variables]):
self._patch_text = patch_text self._patch_text = patch_text
self._cwd_path = '/' self._cwd_path = '/'
self._last_level = 0 self._last_level = 0
@ -28,7 +23,8 @@ class PatchFormat(Format):
# Предупреждения. # Предупреждения.
self._warnings: list = [] self._warnings: list = []
def execute_format(self, target_path, chroot_path='/'): def execute_format(self, target_path: str,
chroot_path: str = '/') -> dict:
'''Метод для запуска работы формата.''' '''Метод для запуска работы формата.'''
self._cwd_path = target_path self._cwd_path = target_path
if not path.isdir(self._cwd_path): if not path.isdir(self._cwd_path):

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, alphanums, originalTextFor, OneOrMore,\ from pyparsing import Word, Literal, alphanums, originalTextFor, OneOrMore,\
ParseException, Group, Optional, printables, Regex ParseException, Group, Optional, printables, Regex
@ -26,7 +25,7 @@ class PostfixFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_parameter_line, self._parse_parameter_line,
self._parse_to_delete_line] self._parse_to_delete_line]

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\ from pyparsing import Word, Literal, alphanums, printables, originalTextFor,\
OneOrMore, ParseException, restOfLine, Group, Optional,\ OneOrMore, ParseException, restOfLine, Group, Optional,\
@ -27,7 +26,7 @@ class ProcmailFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_parameter_line, self._parse_parameter_line,
self._parse_to_delete_line] self._parse_to_delete_line]

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format, FormatError from .base_format import Format, FormatError
from ..template_engine import ParametersContainer
from jinja2 import Environment, PackageLoader from jinja2 import Environment, PackageLoader
from collections import OrderedDict from collections import OrderedDict
from pyparsing import originalTextFor, Literal, Word, printables, Regex,\ from pyparsing import originalTextFor, Literal, Word, printables, Regex,\
@ -34,7 +33,7 @@ class ProFTPDFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_section_start_line, self._parse_section_start_line,
self._parse_section_end_line, self._parse_section_end_line,

@ -16,7 +16,8 @@ class RawFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): parameters=ParametersContainer(),
**kwargs):
self.comment_symbol = parameters.comment or "" self.comment_symbol = parameters.comment or ""
self._before = join_before self._before = join_before
@ -36,7 +37,7 @@ class RawFormat(Format):
sep = "" sep = ""
if self._before: if self._before:
if (template._document_text if (template._document_text
and not template._document_text.endswith("\n")): and not template._document_text.endswith("\n")):
sep = "\n" sep = "\n"
self._document_text = '{0}{1}{2}'.format( self._document_text = '{0}{1}{2}'.format(
template._document_text, sep, template._document_text, sep,

@ -23,7 +23,8 @@ class RegexFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): parameters=ParametersContainer(),
**kwargs):
processing_methods = OrderedDict() processing_methods = OrderedDict()
super().__init__(processing_methods) super().__init__(processing_methods)

@ -26,7 +26,8 @@ class SambaFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): parameters=ParametersContainer(),
**kwargs):
processing_methods = [self._parse_comment_line, processing_methods = [self._parse_comment_line,
self._parse_section_line, self._parse_section_line,
self._parse_parameter_line, self._parse_parameter_line,

@ -0,0 +1,161 @@
# vim: fileencoding=utf-8
#
from .base_format import Format
from calculate.utils.package import (
PackageAtomParser,
PackageNotFound,
PackageAtomError
)
from collections import OrderedDict
from typing import List
import os
class WorldFormat(Format):
FORMAT = 'world'
EXECUTABLE = False
_initialized = False
comment_symbol = '#'
def __init__(self, document_text: str,
template_path: str,
ignore_comments: bool = False,
add_header: bool = False,
already_changed: bool = False,
chroot_path="/",
**kwargs):
processing_methods = []
self._atom_parser = PackageAtomParser(chroot_path=chroot_path)
super().__init__(processing_methods)
self._template_name = os.path.basename(template_path)
self._action_symbols = ["!!", "!"]
self.warnings = []
if add_header and not ignore_comments:
self.header, document_text = self._get_header_and_document_text(
document_text,
template_path,
already_changed=already_changed)
else:
self.header = ''
document_text = document_text.strip()
if document_text == '':
self._document_dictionary = OrderedDict()
else:
document_lines = self._get_list_of_logic_lines(document_text)
self._document_dictionary = self._lines_to_dictionary(
document_lines)
def _lines_to_dictionary(self, document_lines: List[str]) -> OrderedDict:
output = OrderedDict()
for line in document_lines:
action = None
for action_symbol in self._action_symbols:
if line.startswith(action_symbol):
action = action_symbol
line = line[len(action_symbol):]
break
name_only = line.split(':')[0]
if "/" not in name_only:
line = f"{self._template_name}/{line}"
atom_dict = self._atom_parser.parse_atom_name(line)
atom_dict['package_atom'] = (
f'{atom_dict["category"]}/{atom_dict["name"]}')
if action == "!!":
action = "!"
print("WITH EXISTANCE CHECK")
try:
self._atom_parser._check_package_existance(atom_dict)
print("PACKAGE WAS FOUND")
except (PackageNotFound, PackageAtomError):
print("PACKAGE WAS NOT FOUND")
self.warnings.append(f"package '{line}' not found")
levels = [atom_dict["category"], atom_dict["name"]]
level = output
for next_level in levels:
if next_level not in level:
level[next_level] = OrderedDict()
level = level[next_level]
level[atom_dict["slot"]] = action
return output
def join_template(self, template):
self._document_dictionary = self._change_categories(
template._document_dictionary,
self._document_dictionary)
def _change_categories(self, template: OrderedDict,
original: OrderedDict) -> OrderedDict:
for category, names in template.items():
if category in original:
original_names = original[category]
else:
original_names = OrderedDict()
changed_names = self._change_names(names, original_names)
if not changed_names:
original.pop(category)
else:
original[category] = changed_names
return original
def _change_names(self, template_names: OrderedDict,
original_names: OrderedDict) -> OrderedDict:
for name, slots in template_names.items():
if name in original_names:
original_slots = original_names[name]
else:
original_slots = OrderedDict()
changed_slots = self._change_slots(slots, original_slots)
if not changed_slots:
original_names.pop(name)
else:
original_names[name] = changed_slots
return original_names
def _change_slots(self, template_slots: OrderedDict,
original_slots: OrderedDict) -> OrderedDict:
for slot, action in template_slots.items():
if slot == "*":
if action == "!":
original_slots.clear()
continue
else:
if action == "!" and slot in original_slots:
original_slots.pop(slot)
continue
if action is None and slot not in original_slots:
original_slots[slot] = None
continue
return original_slots
def _get_document_text(self) -> str:
lines = []
categories = sorted(self._document_dictionary.keys())
for category in categories:
names_dict = self._document_dictionary[category]
names = sorted(names_dict.keys())
for name in names:
slots = sorted(names_dict[name].keys())
for slot in slots:
slot = '' if slot is None else f":{slot}"
lines.append(f"{category}/{name}{slot}")
lines.append('')
return "\n".join(lines)
@property
def document_text(self) -> str:
return "{}{}".format(self.header, self._get_document_text())

@ -3,14 +3,12 @@
from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
Optional Optional
from .base_format import Format, FormatError from .base_format import Format, FormatError
from ..template_engine import ParametersContainer
from collections import OrderedDict from collections import OrderedDict
try: try:
from lxml.etree import Element, SubElement, ElementTree, tostring from lxml.etree import Element, SubElement, ElementTree, tostring
except ImportError: except ImportError:
from xml.etree.ElementTree import Element, SubElement, ElementTree, \ from xml.etree.ElementTree import Element, SubElement, ElementTree, \
tostring tostring
from pprint import pprint
class XMLGConfFormat(Format): class XMLGConfFormat(Format):
@ -32,7 +30,7 @@ class XMLGConfFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = OrderedDict({'gconf': self._gconf, processing_methods = OrderedDict({'gconf': self._gconf,
'entry': self._entry, 'entry': self._entry,
'dir': self._dir, 'dir': self._dir,

@ -1,7 +1,6 @@
# vim: fileencoding=utf-8 # vim: fileencoding=utf-8
# #
from .base_format import Format from .base_format import Format
from ..template_engine import ParametersContainer
from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\ from pyparsing import originalTextFor, Literal, Word, printables, OneOrMore,\
Optional Optional
from collections import OrderedDict from collections import OrderedDict
@ -31,7 +30,7 @@ class XMLXfceFormat(Format):
join_before=False, join_before=False,
add_header=False, add_header=False,
already_changed=False, already_changed=False,
parameters=ParametersContainer()): **kwargs):
processing_methods = OrderedDict({'channel': self._channel, processing_methods = OrderedDict({'channel': self._channel,
'property': self._property, 'property': self._property,
'value': self._value, 'value': self._value,

@ -1042,7 +1042,8 @@ class TemplateExecutor:
parsed_template = template_format( parsed_template = template_format(
template_object.template_text, template_object.template_text,
template_object.template_path, template_object.template_path,
ignore_comments=True) ignore_comments=True,
chroot_path=self.chroot_path)
# Действия для шаблонов не являющихся исполнительными. # Действия для шаблонов не являющихся исполнительными.
output_paths = [output_path] output_paths = [output_path]
@ -1095,10 +1096,10 @@ class TemplateExecutor:
self._chmod_file(save_path, chmod) self._chmod_file(save_path, chmod)
elif template_object.format_class.EXECUTABLE: elif template_object.format_class.EXECUTABLE:
parsed_template = template_format( parsed_template = template_format(
template_object.template_text, template_object.template_text,
template_object.template_path, template_object.template_path,
template_object.parameters, parameters=template_object.parameters,
self.datavars_module) datavars=self.datavars_module)
changed_files = parsed_template.execute_format( changed_files = parsed_template.execute_format(
template_object.target_path, template_object.target_path,
chroot_path=self.chroot_path) chroot_path=self.chroot_path)

@ -13,9 +13,8 @@ class CalculateIniParser:
def __init__(self): def __init__(self):
self.operations = {"=": self.Define.assign, self.operations = {"=": self.Define.assign,
"+=": self.Define.append, "+=": self.Define.append,
"-=": self.Define.remove} "-=": self.Define.remove}
lbrack = Literal("[") lbrack = Literal("[")
rbrack = Literal("]") rbrack = Literal("]")

@ -587,17 +587,15 @@ class PackageAtomParser:
'''Метод для разбора значения package, после разбора инициирует '''Метод для разбора значения package, после разбора инициирует
проверку полученных значений. Возвращает объект PackageAtomName.''' проверку полученных значений. Возвращает объект PackageAtomName.'''
self.package_atom = package_atom self.package_atom = package_atom
print(f'value: {package_atom}')
if isinstance(package_atom, str): if isinstance(package_atom, str):
atom_dictionary = self.parse_atom_name(package_atom) atom_dictionary = self.parse_atom_name(package_atom)
atom_dictionary['package_atom'] = package_atom atom_dictionary['package_atom'] = package_atom
print(f'atom_dict: {atom_dictionary}')
elif isinstance(package_atom, dict): elif isinstance(package_atom, dict):
atom_dictionary = package_atom atom_dictionary = package_atom
if 'package_atom' not in atom_dictionary: if 'package_atom' not in atom_dictionary:
atom_dictionary['package_atom'] = ( atom_dictionary['package_atom'] = (
f'{atom_dictionary["category"]}{atom_dictionary["name"]}') f'{atom_dictionary["category"]}/{atom_dictionary["name"]}')
atom_dictionary = self._check_package_existance(atom_dictionary) atom_dictionary = self._check_package_existance(atom_dictionary)
atom_name_object = PackageAtomName(atom_dictionary) atom_name_object = PackageAtomName(atom_dictionary)
@ -1093,7 +1091,6 @@ class Package(metaclass=PackageCreator):
file_path = self.remove_chroot_path(file_path) file_path = self.remove_chroot_path(file_path)
file_path = self.remove_cfg_prefix(file_path) file_path = self.remove_cfg_prefix(file_path)
removed = OrderedDict() removed = OrderedDict()
print(f"REMOVE {file_path} FROM PACKAGE {self.package_name}")
if file_path not in self.contents_dictionary: if file_path not in self.contents_dictionary:
return return

@ -23,6 +23,8 @@ markers =
samba: marker for running tests for samba format. samba: marker for running tests for samba format.
xml_xfce: marker for running tests for xml xfce format. xml_xfce: marker for running tests for xml xfce format.
xml_gconf: marker for running tests for xml gconf format. xml_gconf: marker for running tests for xml gconf format.
world: marker for running tests for world format.
formats: marker for running tests for all formats.
files_utils: marker for running tests for calculate.utils.files module. files_utils: marker for running tests for calculate.utils.files module.
package_utils: marker for running tests for calculate.utils.contents module. package_utils: marker for running tests for calculate.utils.contents module.

@ -17,12 +17,14 @@ TMP_BACKUP_DIR = 'tests/templates/format/testfiles/backgrounds/tmp.backup'
TMP_DIR = 'tests/templates/format/testfiles/backgrounds/tmp' TMP_DIR = 'tests/templates/format/testfiles/backgrounds/tmp'
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_make_tmp_dir(): def test_make_tmp_dir():
if not os.path.exists(TMP_DIR): if not os.path.exists(TMP_DIR):
shutil.copytree(TMP_BACKUP_DIR, TMP_DIR) shutil.copytree(TMP_BACKUP_DIR, TMP_DIR)
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
@pytest.mark.parametrize('case', [ @pytest.mark.parametrize('case', [
{ {
@ -127,7 +129,8 @@ def test_resize_and_convert_of_different_formats(case):
'stretch': case["stretch"]}) 'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"], backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
images_format, resolutions = case["result"] images_format, resolutions = case["result"]
@ -152,6 +155,7 @@ def test_resize_and_convert_of_different_formats(case):
# assert False # assert False
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
@pytest.mark.parametrize('case', [ @pytest.mark.parametrize('case', [
{ {
@ -183,7 +187,8 @@ def test_scretch_parameter(case):
'stretch': case["stretch"]}) 'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"], backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
for resolution, result in case["result"].items(): for resolution, result in case["result"].items():
@ -197,6 +202,7 @@ def test_scretch_parameter(case):
int(height)) int(height))
# @pytest.mark.formats
# @pytest.mark.backgrounds # @pytest.mark.backgrounds
# def test_to_create(): # def test_to_create():
# target_path = os.path.join(TMP_BACKUP_DIR, "result_13-") # target_path = os.path.join(TMP_BACKUP_DIR, "result_13-")
@ -210,6 +216,7 @@ def test_scretch_parameter(case):
# backgrounds_object.execute_format(target_path) # backgrounds_object.execute_format(target_path)
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_has_been_already_used__it_will_not_be_reused(): def test_if_template_has_been_already_used__it_will_not_be_reused():
target_path = os.path.join(TMP_DIR, "result_10-") target_path = os.path.join(TMP_DIR, "result_10-")
@ -219,12 +226,14 @@ def test_if_template_has_been_already_used__it_will_not_be_reused():
'stretch': False}) 'stretch': False})
backgrounds_object = BackgroundsFormat("1650x1050\n1024x768", backgrounds_object = BackgroundsFormat("1650x1050\n1024x768",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
assert not changed_files assert not changed_files
@pytest.mark.backgrounds_slow @pytest.mark.backgrounds_slow
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_is_using_in_directory_but_other_template_has_been_already_used_for_the_same_image_name__latest_template_will_remove_old_images_and_md5sum_file_and_create_new_ones(): def test_if_template_is_using_in_directory_but_other_template_has_been_already_used_for_the_same_image_name__latest_template_will_remove_old_images_and_md5sum_file_and_create_new_ones():
target_path = os.path.join(TMP_DIR, "result_11-") target_path = os.path.join(TMP_DIR, "result_11-")
@ -234,7 +243,8 @@ def test_if_template_is_using_in_directory_but_other_template_has_been_already_u
'stretch': False}) 'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960", backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.png") assert not os.path.exists(f"{target_path}1650x1050.png")
assert os.path.exists(f"{target_path}1440x1080.png") assert os.path.exists(f"{target_path}1440x1080.png")
@ -249,6 +259,7 @@ def test_if_template_is_using_in_directory_but_other_template_has_been_already_u
@pytest.mark.backgrounds_slow @pytest.mark.backgrounds_slow
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_is_using_in_directory_which_contains_md5sum_file_without_any_images__the_template_will_remove_md5sum_file_and_create_new_one_and_images(): def test_if_template_is_using_in_directory_which_contains_md5sum_file_without_any_images__the_template_will_remove_md5sum_file_and_create_new_one_and_images():
target_path = os.path.join(TMP_DIR, "result_12-") target_path = os.path.join(TMP_DIR, "result_12-")
@ -258,7 +269,8 @@ def test_if_template_is_using_in_directory_which_contains_md5sum_file_without_an
'stretch': False}) 'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960", backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
assert os.path.exists(f"{target_path}1440x1080.png") assert os.path.exists(f"{target_path}1440x1080.png")
assert os.path.exists(f"{target_path}1280x960.png") assert os.path.exists(f"{target_path}1280x960.png")
@ -269,6 +281,7 @@ def test_if_template_is_using_in_directory_which_contains_md5sum_file_without_an
@pytest.mark.backgrounds_slow @pytest.mark.backgrounds_slow
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_is_using_in_directory_which_contains_some_image_files_without_md5sum_file__the_template_will_remove_all_images_and_create_new_ones_and_new_md5sum_file(): def test_if_template_is_using_in_directory_which_contains_some_image_files_without_md5sum_file__the_template_will_remove_all_images_and_create_new_ones_and_new_md5sum_file():
target_path = os.path.join(TMP_DIR, "result_13-") target_path = os.path.join(TMP_DIR, "result_13-")
@ -278,7 +291,8 @@ def test_if_template_is_using_in_directory_which_contains_some_image_files_witho
'stretch': False}) 'stretch': False})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960", backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path) changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.png") assert not os.path.exists(f"{target_path}1650x1050.png")
assert os.path.exists(f"{target_path}1440x1080.png") assert os.path.exists(f"{target_path}1440x1080.png")
@ -292,6 +306,7 @@ def test_if_template_is_using_in_directory_which_contains_some_image_files_witho
f"{target_path}1280x960.png": "N"} f"{target_path}1280x960.png": "N"}
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_two_or_more_resolution_values__the_output_files_name_will_contains_its_resolutions_only(): def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_two_or_more_resolution_values__the_output_files_name_will_contains_its_resolutions_only():
target_path = os.path.join(TMP_DIR, "result_14-") target_path = os.path.join(TMP_DIR, "result_14-")
@ -302,7 +317,8 @@ def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_tw
'name': ''}) 'name': ''})
backgrounds_object = BackgroundsFormat("100x100\n60x60", backgrounds_object = BackgroundsFormat("100x100\n60x60",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
backgrounds_object.execute_format(target_path) backgrounds_object.execute_format(target_path)
assert os.path.exists(os.path.join(TMP_DIR, "100x100.jpeg")) assert os.path.exists(os.path.join(TMP_DIR, "100x100.jpeg"))
@ -310,6 +326,7 @@ def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_tw
assert os.path.exists(os.path.join(TMP_DIR, "md5sum")) assert os.path.exists(os.path.join(TMP_DIR, "md5sum"))
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_one_resolution_value__the_format_will_raise_FormatError_exception(): def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_one_resolution_value__the_format_will_raise_FormatError_exception():
target_path = os.path.join(TMP_DIR, "result_15-") target_path = os.path.join(TMP_DIR, "result_15-")
@ -320,11 +337,13 @@ def test_if_template_s_name_parameter_is_the_empty_line_and_its_text_contents_on
'name': ''}) 'name': ''})
backgrounds_object = BackgroundsFormat("100x100", backgrounds_object = BackgroundsFormat("100x100",
"path/to/template", "path/to/template",
parameters, datavars) parameters=parameters,
datavars=datavars)
with pytest.raises(FormatError): with pytest.raises(FormatError):
backgrounds_object.execute_format(target_path) backgrounds_object.execute_format(target_path)
@pytest.mark.formats
@pytest.mark.backgrounds @pytest.mark.backgrounds
def test_remove_tmp(): def test_remove_tmp():
if os.path.exists(TMP_DIR): if os.path.exists(TMP_DIR):

@ -2,6 +2,7 @@ import pytest
from calculate.templates.format.base_format import Format from calculate.templates.format.base_format import Format
@pytest.mark.formats
@pytest.mark.base @pytest.mark.base
class TestJoinMethod: class TestJoinMethod:
def test_if_inputs_are_dictionaries_with_string_keys_without_any_action_marks__the_dictionaties_just_merged(self, StringDictionaries): def test_if_inputs_are_dictionaries_with_string_keys_without_any_action_marks__the_dictionaties_just_merged(self, StringDictionaries):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.bind_format import BINDFormat from calculate.templates.format.bind_format import BINDFormat
@pytest.mark.formats
@pytest.mark.bind @pytest.mark.bind
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -4,6 +4,7 @@ from calculate.templates.format.compiz_format import CompizFormat
from pprint import pprint from pprint import pprint
@pytest.mark.formats
@pytest.mark.compiz @pytest.mark.compiz
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -12,6 +12,7 @@ TESTFILES_PATH = os.path.join(os.getcwd(),
'tests/templates/format/testfiles/contents') 'tests/templates/format/testfiles/contents')
@pytest.mark.formats
@pytest.mark.contents @pytest.mark.contents
class TestExecutingFormat: class TestExecutingFormat:
def test_copy_testfiles(self): def test_copy_testfiles(self):
@ -56,9 +57,7 @@ sym /etc/dir_3/link_0 -> ../dir_1/file_0 {2}
int(os.lstat(join_paths(chroot_path, int(os.lstat(join_paths(chroot_path,
'/etc/dir_3/link_0')).st_mtime)) '/etc/dir_3/link_0')).st_mtime))
contents_format = ContentsFormat(template_text, '/path/to/template', contents_format = ContentsFormat(template_text, '/path/to/template')
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path) contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name, test_package = Package(test_package_name,
@ -105,9 +104,7 @@ dir /etc/dir_1
dir /etc/dir_3 dir /etc/dir_3
''' '''
contents_format = ContentsFormat(template_text, '/path/to/template', contents_format = ContentsFormat(template_text, '/path/to/template')
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path) contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name, test_package = Package(test_package_name,
@ -183,9 +180,7 @@ dir /etc/dir_5
sym /etc/dir_5/link_0 -> ../dir_1/file_0 1601991426 sym /etc/dir_5/link_0 -> ../dir_1/file_0 1601991426
''' '''
contents_format = ContentsFormat(template_text, '/path/to/template', contents_format = ContentsFormat(template_text, '/path/to/template')
ParametersContainer(),
NamespaceNode())
contents_format.execute_format('target/path', chroot_path=chroot_path) contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name, test_package = Package(test_package_name,

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.dovecot_format import DovecotFormat from calculate.templates.format.dovecot_format import DovecotFormat
@pytest.mark.formats
@pytest.mark.dovecot @pytest.mark.dovecot
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.json_format import JSONFormat from calculate.templates.format.json_format import JSONFormat
@pytest.mark.formats
@pytest.mark.json @pytest.mark.json
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameters_and_parameter_blocks__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.kde_format import KDEFormat from calculate.templates.format.kde_format import KDEFormat
@pytest.mark.formats
@pytest.mark.kde @pytest.mark.kde
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.kernel_format import KernelFormat from calculate.templates.format.kernel_format import KernelFormat
@pytest.mark.formats
@pytest.mark.kernel @pytest.mark.kernel
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.ldap_format import LDAPFormat from calculate.templates.format.ldap_format import LDAPFormat
@pytest.mark.formats
@pytest.mark.ldap @pytest.mark.ldap
class TestParsingMethods: class TestParsingMethods:
def test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines(self): def test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.openrc_format import OpenRCFormat from calculate.templates.format.openrc_format import OpenRCFormat
@pytest.mark.formats
@pytest.mark.openrc @pytest.mark.openrc
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -1,9 +1,6 @@
import pytest import pytest
import shutil import shutil
from calculate.templates.format.patch_format import PatchFormat from calculate.templates.format.patch_format import PatchFormat
from calculate.templates.template_engine import ParametersContainer
from calculate.variables.datavars import NamespaceNode
from calculate.utils.files import Process
from os import path from os import path
import os import os
import re import re
@ -17,6 +14,7 @@ TEST_ROOT_PATH = os.path.join(os.getcwd(),
'tests/templates/format/testfiles/patch/root') 'tests/templates/format/testfiles/patch/root')
@pytest.mark.formats
@pytest.mark.patch @pytest.mark.patch
class TestExecuteMethods: class TestExecuteMethods:
def test_create_testfiles(self): def test_create_testfiles(self):
@ -33,9 +31,7 @@ class TestExecuteMethods:
with open(path.join(cwd_path, 'diff_1.patch')) as patch_file: with open(path.join(cwd_path, 'diff_1.patch')) as patch_file:
patch_text = patch_file.read() patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path', diff_patch = PatchFormat(patch_text, '/template/path')
ParametersContainer(),
NamespaceNode("<root>"))
output = diff_patch.execute_format(target_path=cwd_path) output = diff_patch.execute_format(target_path=cwd_path)
if output: if output:
for changed_file, change_type in diff_patch.changed_files.items(): for changed_file, change_type in diff_patch.changed_files.items():
@ -66,9 +62,7 @@ class TestExecuteMethods:
with open(path.join(patch_path)) as patch_file: with open(path.join(patch_path)) as patch_file:
patch_text = patch_file.read() patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path', diff_patch = PatchFormat(patch_text, '/template/path')
ParametersContainer(),
NamespaceNode("<root>"))
diff_patch.execute_format(target_path=cwd_path) diff_patch.execute_format(target_path=cwd_path)
for changed_file, change_type in diff_patch.changed_files.items(): for changed_file, change_type in diff_patch.changed_files.items():

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.postfix_format import PostfixFormat from calculate.templates.format.postfix_format import PostfixFormat
@pytest.mark.formats
@pytest.mark.postfix @pytest.mark.postfix
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.procmail_format import ProcmailFormat from calculate.templates.format.procmail_format import ProcmailFormat
@pytest.mark.formats
@pytest.mark.procmail @pytest.mark.procmail
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -4,6 +4,7 @@ from calculate.templates.format.proftpd_format import ProFTPDFormat
from pprint import pprint from pprint import pprint
@pytest.mark.formats
@pytest.mark.proftpd @pytest.mark.proftpd
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from calculate.templates.format.raw_format import RawFormat
from calculate.templates.template_engine import ParametersContainer from calculate.templates.template_engine import ParametersContainer
@pytest.mark.formats
@pytest.mark.raw @pytest.mark.raw
class TestParsingMethods: class TestParsingMethods:
def test_first(self): def test_first(self):

@ -3,6 +3,7 @@ from calculate.templates.format.regex_format import RegexFormat
from calculate.templates.template_engine import ParametersContainer from calculate.templates.template_engine import ParametersContainer
@pytest.mark.formats
@pytest.mark.regex @pytest.mark.regex
class TestParsingMethods: class TestParsingMethods:
def test_if_input_patch_document_contains_only_regular_expressions_without_any_regex_flags__it_correctly_patches_input_document(self): def test_if_input_patch_document_contains_only_regular_expressions_without_any_regex_flags__it_correctly_patches_input_document(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.samba_format import SambaFormat from calculate.templates.format.samba_format import SambaFormat
@pytest.mark.formats
@pytest.mark.samba @pytest.mark.samba
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -0,0 +1,199 @@
import pytest
from collections import OrderedDict
from calculate.templates.format.world_format import WorldFormat
import os
CHROOT_PATH = os.path.join(os.getcwd(),
"tests/templates/format/testfiles/world")
@pytest.mark.formats
@pytest.mark.world
def test_parsing_document():
original_text = """www-client/chromium:unstable
dev-python/pip
dev-util/cmake
clementine
"""
original_object = WorldFormat(original_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
result_dict = OrderedDict({"www-client":
OrderedDict({"chromium":
OrderedDict({"unstable": None})}),
"dev-python":
OrderedDict({"pip":
OrderedDict({None: None})}),
"dev-util":
OrderedDict({"cmake":
OrderedDict({None: None})}),
"media-sound":
OrderedDict({"clementine":
OrderedDict({None: None})})})
assert original_object._document_dictionary == result_dict
@pytest.mark.formats
@pytest.mark.world
def test_parsing_template():
template_text = """www-client/chromium:stable
!!www-client/chromium:unstable
!www-client/chromium
dev-util/cmake
alsa-utils
"""
template_object = WorldFormat(template_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
result_dict = OrderedDict({"www-client":
OrderedDict({"chromium":
OrderedDict({"stable": None,
"unstable": '!',
None: '!'})}),
"dev-util":
OrderedDict({"cmake":
OrderedDict({None: None})}),
"media-sound":
OrderedDict({"alsa-utils":
OrderedDict({None: None})})})
assert template_object._document_dictionary == result_dict
@pytest.mark.formats
@pytest.mark.world
def test_parsing_template_with_warning():
template_text = """www-client/chromium:stable
!!www-client/chromium:not_exist
!www-client/chromium
dev-util/cmake
alsa-utils
"""
template_object = WorldFormat(template_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
result_dict = OrderedDict({"www-client":
OrderedDict({"chromium":
OrderedDict({"stable": None,
"not_exist": '!',
None: '!'})}),
"dev-util":
OrderedDict({"cmake":
OrderedDict({None: None})}),
"media-sound":
OrderedDict({"alsa-utils":
OrderedDict({None: None})})})
assert template_object.warnings == [
"package 'www-client/chromium:not_exist' not found"]
assert template_object._document_dictionary == result_dict
@pytest.mark.formats
@pytest.mark.world
def test_joining_template():
original_text = """www-client/chromium:unstable
dev-python/pip
dev-util/cmake
clementine
"""
template_text = """www-client/chromium:stable
!!www-client/chromium:unstable
!www-client/chromium
dev-util/cmake
alsa-utils
"""
original_object = WorldFormat(original_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
template_object = WorldFormat(template_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
result_dict = OrderedDict({"www-client":
OrderedDict({"chromium":
OrderedDict({"stable": None})}),
"dev-python":
OrderedDict({"pip":
OrderedDict({None: None})}),
"dev-util":
OrderedDict({"cmake":
OrderedDict({None: None})}),
"media-sound":
OrderedDict({"clementine":
OrderedDict({None: None}),
"alsa-utils":
OrderedDict({None: None})})})
original_object.join_template(template_object)
assert original_object._document_dictionary == result_dict
@pytest.mark.formats
@pytest.mark.world
def test_joining_and_get_text_without_header():
original_text = """www-client/chromium:unstable
dev-python/pip
dev-util/cmake
clementine
"""
template_text = """www-client/chromium:stable
!!www-client/chromium:unstable
!www-client/chromium
dev-util/cmake
alsa-utils
"""
result_text = """dev-python/pip
dev-util/cmake
media-sound/alsa-utils
media-sound/clementine
www-client/chromium:stable
"""
original_object = WorldFormat(original_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
template_object = WorldFormat(template_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
original_object.join_template(template_object)
assert original_object.document_text == result_text
@pytest.mark.formats
@pytest.mark.world
def test_joining_and_get_text_with_header():
original_text = """www-client/chromium:unstable
dev-python/pip
dev-util/cmake
clementine
"""
template_text = """www-client/chromium:stable
!!www-client/chromium:unstable
!www-client/chromium
dev-util/cmake
alsa-utils
"""
result_text = """#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template/media-sound
#-------------------------------------------------------------------------------
dev-python/pip
dev-util/cmake
media-sound/alsa-utils
media-sound/clementine
www-client/chromium:stable
"""
original_object = WorldFormat(original_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH,
add_header=True)
template_object = WorldFormat(template_text,
"/path/to/template/media-sound",
chroot_path=CHROOT_PATH)
original_object.join_template(template_object)
assert original_object.document_text == result_text

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.xml_gconf_format import XMLGConfFormat from calculate.templates.format.xml_gconf_format import XMLGConfFormat
@pytest.mark.formats
@pytest.mark.xml_gconf @pytest.mark.xml_gconf
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary(self): def test_if_input_document_is_simple_gconf_tree__the_format_object_contains_correct_dictionary(self):

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.xml_xfce_format import XMLXfceFormat from calculate.templates.format.xml_xfce_format import XMLXfceFormat
@pytest.mark.formats
@pytest.mark.xml_xfce @pytest.mark.xml_xfce
class TestParsingMethods: class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self): def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -2097,6 +2097,7 @@ def test_backgrounds_format_with_single_resolution():
@pytest.mark.directory_processor @pytest.mark.directory_processor
def test_backgrounds_format_making_no_changes(): def test_backgrounds_format_making_no_changes():
print("id datavars:", id(datavars))
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH, datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_69') 'templates_69')

Loading…
Cancel
Save