master
Иванов Денис 3 роки тому
джерело e59a4511d6
коміт 327d0ae56a

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

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

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

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

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

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

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

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

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

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

@ -3,10 +3,6 @@
from .base_format import Format
from calculate.utils.files import Process
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
@ -16,8 +12,7 @@ class PatchFormat(Format):
def __init__(self, patch_text: str,
template_path: str,
parameters: ParametersContainer,
datavars: Union[Datavars, NamespaceNode, Variables]):
**kwargs):
self._patch_text = patch_text
self._cwd_path = '/'
self._last_level = 0
@ -28,7 +23,8 @@ class PatchFormat(Format):
# Предупреждения.
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
if not path.isdir(self._cwd_path):

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

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

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

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

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

@ -26,7 +26,8 @@ class SambaFormat(Format):
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
parameters=ParametersContainer(),
**kwargs):
processing_methods = [self._parse_comment_line,
self._parse_section_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,\
Optional
from .base_format import Format, FormatError
from ..template_engine import ParametersContainer
from collections import OrderedDict
try:
from lxml.etree import Element, SubElement, ElementTree, tostring
except ImportError:
from xml.etree.ElementTree import Element, SubElement, ElementTree, \
tostring
from pprint import pprint
class XMLGConfFormat(Format):
@ -32,7 +30,7 @@ class XMLGConfFormat(Format):
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
**kwargs):
processing_methods = OrderedDict({'gconf': self._gconf,
'entry': self._entry,
'dir': self._dir,

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

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

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

@ -587,17 +587,15 @@ class PackageAtomParser:
'''Метод для разбора значения package, после разбора инициирует
проверку полученных значений. Возвращает объект PackageAtomName.'''
self.package_atom = package_atom
print(f'value: {package_atom}')
if isinstance(package_atom, str):
atom_dictionary = self.parse_atom_name(package_atom)
atom_dictionary['package_atom'] = package_atom
print(f'atom_dict: {atom_dictionary}')
elif isinstance(package_atom, dict):
atom_dictionary = package_atom
if 'package_atom' not in atom_dictionary:
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_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_cfg_prefix(file_path)
removed = OrderedDict()
print(f"REMOVE {file_path} FROM PACKAGE {self.package_name}")
if file_path not in self.contents_dictionary:
return

@ -23,6 +23,8 @@ markers =
samba: marker for running tests for samba format.
xml_xfce: marker for running tests for xml xfce 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.
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'
@pytest.mark.formats
@pytest.mark.backgrounds
def test_make_tmp_dir():
if not os.path.exists(TMP_DIR):
shutil.copytree(TMP_BACKUP_DIR, TMP_DIR)
@pytest.mark.formats
@pytest.mark.backgrounds
@pytest.mark.parametrize('case', [
{
@ -127,7 +129,8 @@ def test_resize_and_convert_of_different_formats(case):
'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
images_format, resolutions = case["result"]
@ -152,6 +155,7 @@ def test_resize_and_convert_of_different_formats(case):
# assert False
@pytest.mark.formats
@pytest.mark.backgrounds
@pytest.mark.parametrize('case', [
{
@ -183,7 +187,8 @@ def test_scretch_parameter(case):
'stretch': case["stretch"]})
backgrounds_object = BackgroundsFormat(case["template_text"],
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
for resolution, result in case["result"].items():
@ -197,6 +202,7 @@ def test_scretch_parameter(case):
int(height))
# @pytest.mark.formats
# @pytest.mark.backgrounds
# def test_to_create():
# 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)
@pytest.mark.formats
@pytest.mark.backgrounds
def test_if_template_has_been_already_used__it_will_not_be_reused():
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})
backgrounds_object = BackgroundsFormat("1650x1050\n1024x768",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not changed_files
@pytest.mark.backgrounds_slow
@pytest.mark.formats
@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():
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})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.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.formats
@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():
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})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert os.path.exists(f"{target_path}1440x1080.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.formats
@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():
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})
backgrounds_object = BackgroundsFormat("1440x1080\n1280x960",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
changed_files = backgrounds_object.execute_format(target_path)
assert not os.path.exists(f"{target_path}1650x1050.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"}
@pytest.mark.formats
@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():
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': ''})
backgrounds_object = BackgroundsFormat("100x100\n60x60",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
backgrounds_object.execute_format(target_path)
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"))
@pytest.mark.formats
@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():
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': ''})
backgrounds_object = BackgroundsFormat("100x100",
"path/to/template",
parameters, datavars)
parameters=parameters,
datavars=datavars)
with pytest.raises(FormatError):
backgrounds_object.execute_format(target_path)
@pytest.mark.formats
@pytest.mark.backgrounds
def test_remove_tmp():
if os.path.exists(TMP_DIR):

@ -2,6 +2,7 @@ import pytest
from calculate.templates.format.base_format import Format
@pytest.mark.formats
@pytest.mark.base
class TestJoinMethod:
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
@pytest.mark.formats
@pytest.mark.bind
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.compiz
class TestParsingMethods:
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')
@pytest.mark.formats
@pytest.mark.contents
class TestExecutingFormat:
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,
'/etc/dir_3/link_0')).st_mtime))
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name,
@ -105,9 +104,7 @@ dir /etc/dir_1
dir /etc/dir_3
'''
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format.execute_format('target/path', chroot_path=chroot_path)
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
'''
contents_format = ContentsFormat(template_text, '/path/to/template',
ParametersContainer(),
NamespaceNode())
contents_format = ContentsFormat(template_text, '/path/to/template')
contents_format.execute_format('target/path', chroot_path=chroot_path)
test_package = Package(test_package_name,

@ -3,6 +3,7 @@ from collections import OrderedDict
from calculate.templates.format.dovecot_format import DovecotFormat
@pytest.mark.formats
@pytest.mark.dovecot
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.json
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.kde
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.kernel
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.ldap
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.openrc
class TestParsingMethods:
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):

@ -1,9 +1,6 @@
import pytest
import shutil
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
import os
import re
@ -17,6 +14,7 @@ TEST_ROOT_PATH = os.path.join(os.getcwd(),
'tests/templates/format/testfiles/patch/root')
@pytest.mark.formats
@pytest.mark.patch
class TestExecuteMethods:
def test_create_testfiles(self):
@ -33,9 +31,7 @@ class TestExecuteMethods:
with open(path.join(cwd_path, 'diff_1.patch')) as patch_file:
patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path',
ParametersContainer(),
NamespaceNode("<root>"))
diff_patch = PatchFormat(patch_text, '/template/path')
output = diff_patch.execute_format(target_path=cwd_path)
if output:
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:
patch_text = patch_file.read()
diff_patch = PatchFormat(patch_text, '/template/path',
ParametersContainer(),
NamespaceNode("<root>"))
diff_patch = PatchFormat(patch_text, '/template/path')
diff_patch.execute_format(target_path=cwd_path)
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
@pytest.mark.formats
@pytest.mark.postfix
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.procmail
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.proftpd
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.raw
class TestParsingMethods:
def test_first(self):

@ -3,6 +3,7 @@ from calculate.templates.format.regex_format import RegexFormat
from calculate.templates.template_engine import ParametersContainer
@pytest.mark.formats
@pytest.mark.regex
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.samba
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.xml_gconf
class TestParsingMethods:
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
@pytest.mark.formats
@pytest.mark.xml_xfce
class TestParsingMethods:
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
def test_backgrounds_format_making_no_changes():
print("id datavars:", id(datavars))
datavars.main['cl_template_path'] = os.path.join(CHROOT_PATH,
'templates_69')

Завантаження…
Відмінити
Зберегти