Calculate header adding methods is implemented and tested for all formats. Adding of the calculated header is almost tested for directory processor.

packages
Иванов Денис 4 years ago
parent 0b0b498d37
commit c369e80439

@ -352,12 +352,16 @@ class BaseFormat():
r'(?P<template_paths>({0}\s*[/\w\d\-_\.]*\n)+)' +
r'{0}' + r'-' * 79 + r'\n?').format(
self.comment_symbol)
template_paths = [template_path]
template_paths = []
if already_changed:
header_regex = re.compile(header_pattern)
parsing_result = header_regex.search(input_text)
template_paths.extend(parsing_result.groupdict()[
'template_paths'].strip().split('\n'))
for template in parsing_result.\
groupdict()['template_paths'].strip().split('\n'):
if template.startswith(self.comment_symbol):
template = template[len(self.comment_symbol):]
template_paths.append(template.strip())
template_paths.append(template_path)
header = ('{0}' + '-' * 79 + '\n' +
'{0} Modified by Calculate Utilities {1}\n' +
'{0} Processed template files:\n' +

@ -22,8 +22,11 @@ class CompizFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_section_line,
@ -41,6 +44,15 @@ class CompizFormat(BaseFormat):
self._last_comments_list = []
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:

@ -22,8 +22,11 @@ class ContentsFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=None,
template_parser=True):
processing_methods = [self._parse_dir_line,
@ -44,6 +47,15 @@ class ContentsFormat(BaseFormat):
if not self._initialized:
self._initialize_parser()
if add_header and not ignore_comments and template_parser:
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:
@ -160,4 +172,4 @@ class ContentsFormat(BaseFormat):
document_dictionary=self._document_dictionary,
template_parser=self._template_parser_flag
)
return document_text
return '{}{}'.format(self.header, document_text)

@ -25,8 +25,11 @@ class DovecotFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_section_start_line,
@ -46,6 +49,15 @@ class DovecotFormat(BaseFormat):
self._last_comments_list = []
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:

@ -13,8 +13,11 @@ class JSONFormat(BaseFormat):
comment_symbol = False
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = []
super().__init__(processing_methods)
@ -22,6 +25,9 @@ class JSONFormat(BaseFormat):
self._join_before = join_before
self._comments_processing = False
# Пока что не добавляет заголовок, потому что не очень ясно, как это
# делать.
if document_text == '':
self._document_dictionary = OrderedDict()
else:

@ -22,8 +22,11 @@ class KDEFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_section_line,
@ -41,6 +44,15 @@ class KDEFormat(BaseFormat):
self._last_comments_list = []
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:

@ -22,8 +22,11 @@ class KernelFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_parameter_line,
@ -36,6 +39,15 @@ class KernelFormat(BaseFormat):
self._last_comments_list = []
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:

@ -23,8 +23,11 @@ class LDAPFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_type_line,
@ -53,6 +56,15 @@ class LDAPFormat(BaseFormat):
self._last_comments_list = []
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:

@ -22,8 +22,11 @@ class OpenRCFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_parameter_line,
@ -35,6 +38,15 @@ class OpenRCFormat(BaseFormat):
self._last_comments_list = []
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:

@ -22,8 +22,11 @@ class PostfixFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_parameter_line,
@ -35,6 +38,15 @@ class PostfixFormat(BaseFormat):
self._last_comments_list = []
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:

@ -22,8 +22,11 @@ class ProcmailFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_parameter_line,
@ -36,6 +39,15 @@ class ProcmailFormat(BaseFormat):
self._last_comments_list = []
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:

@ -29,8 +29,11 @@ class ProFTPDFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_section_start_line,
@ -53,6 +56,15 @@ class ProFTPDFormat(BaseFormat):
self._last_comments_list = []
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:
@ -449,4 +461,4 @@ class ProFTPDFormat(BaseFormat):
document_text = template.render(
document_dictionary=self._document_dictionary
)
return document_text
return '{}{}'.format(self.header, document_text)

@ -18,8 +18,11 @@ class RegexFormat(BaseFormat):
comment_symbol = '#'
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = OrderedDict()
super().__init__(processing_methods)
@ -30,6 +33,13 @@ class RegexFormat(BaseFormat):
self._dotall_flag = parameters.dotall
self._parsed_patch = None
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 = ''
self._document_text = document_text
self._FLAG_VALUES = {'True': True,
'False': False,
@ -182,4 +192,4 @@ class RegexFormat(BaseFormat):
@property
def document_text(self):
return self._document_text
return '{}{}'.format(self.header, self._document_text)

@ -21,8 +21,11 @@ class SambaFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = [self._parse_comment_line,
self._parse_section_line,
@ -41,6 +44,15 @@ class SambaFormat(BaseFormat):
self._last_comments_list = []
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:

@ -10,6 +10,7 @@ try:
except ImportError:
from xml.etree.ElementTree import Element, SubElement, ElementTree, \
tostring
import re
class XMLGConfFormat(BaseFormat):
@ -24,8 +25,11 @@ class XMLGConfFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = OrderedDict({'gconf': self._gconf,
'entry': self._entry,
@ -41,6 +45,15 @@ class XMLGConfFormat(BaseFormat):
self._initialize_parser()
self._join_before = join_before
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 = "<?xml version='1.0' encoding='UTF-8'?>\n"
document_text = document_text.strip()
self._parse_xml_to_dictionary(document_text)
@classmethod
@ -201,9 +214,8 @@ class XMLGConfFormat(BaseFormat):
document_tree = ElementTree(root)
xml_document = tostring(document_tree,
encoding="UTF-8",
xml_declaration=True,
pretty_print=True).decode()
return xml_document
return '{}{}'.format(self.header, xml_document)
def _build_section(self, current_element, dictionary):
'''Метод для перевода словаря xml-документа обратно в текст документа.
@ -252,3 +264,29 @@ class XMLGConfFormat(BaseFormat):
include_element = SubElement(current_element,
element_tag)
include_element.text = dictionary[dict_element]
def _get_header_and_document_text(self, input_text,
template_path,
already_changed=False):
'''Метод для создания заголовка измененного файла и удаления его из
текста исходного файла.'''
header_pattern = (r'<!--' + r'-' * 76 + r'\n' +
r'\s*Modified by Calculate Utilities [\d\w\.]*\n' +
r'\s*Processed template files:\n' +
r'\s*(?P<template_paths>(\s*[/\w\d\-_\.]*\n)+)' +
r'-' * 77 + r'-->\n?')
template_paths = []
if already_changed:
header_regex = re.compile(header_pattern)
parsing_result = header_regex.search(input_text)
template_paths.extend(parsing_result.groupdict()[
'template_paths'].strip().split('\n'))
template_paths.append(template_path)
header = ("<?xml version='1.0' encoding='UTF-8'?>\n" +
'<!--' + '-' * 76 + '\n' +
'Modified by Calculate Utilities {}\n' +
'Processed template files:\n' +
'\n'.join(template_paths) + '\n' +
'-' * 77 + '-->\n').format(self.CALCULATE_VERSION)
document_text = re.sub(header_pattern, '', input_text)
return header, document_text

@ -10,6 +10,7 @@ try:
except ImportError:
from xml.etree.ElementTree import Element, SubElement, ElementTree, \
tostring
import re
class XMLXfceFormat(BaseFormat):
@ -24,8 +25,11 @@ class XMLXfceFormat(BaseFormat):
return super().__new__(cls)
def __init__(self, document_text: str,
template_path,
ignore_comments=False,
join_before=False,
add_header=False,
already_changed=False,
parameters=ParametersContainer()):
processing_methods = OrderedDict({'channel': self._channel,
'property': self._property,
@ -35,6 +39,15 @@ class XMLXfceFormat(BaseFormat):
self._initialize_parser()
self._join_before = join_before
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 = "<?xml version='1.0' encoding='UTF-8'?>\n"
document_text = document_text.strip()
if document_text == '':
self._document_dictionary = OrderedDict()
else:
@ -146,10 +159,9 @@ class XMLXfceFormat(BaseFormat):
document_tree = ElementTree(root)
xml_document = tostring(document_tree,
encoding="UTF-8",
xml_declaration=True,
pretty_print=True).decode()
return xml_document
return '{}{}'.format(self.header, xml_document)
def _build_section(self, current_element, dictionary):
'''Метод для перевода словаря xml-документа обратно в текст документа.
@ -186,3 +198,29 @@ class XMLXfceFormat(BaseFormat):
element_head.pop('tag'),
**element_head,
value=dictionary[dict_element])
def _get_header_and_document_text(self, input_text,
template_path,
already_changed=False):
'''Метод для создания заголовка измененного файла и удаления его из
текста исходного файла.'''
header_pattern = (r'<!--' + r'-' * 76 + r'\n' +
r'\s*Modified by Calculate Utilities [\d\w\.]*\n' +
r'\s*Processed template files:\n' +
r'\s*(?P<template_paths>(\s*[/\w\d\-_\.]*\n)+)' +
r'-' * 77 + r'-->\n?')
template_paths = []
if already_changed:
header_regex = re.compile(header_pattern)
parsing_result = header_regex.search(input_text)
template_paths.extend(parsing_result.groupdict()[
'template_paths'].strip().split('\n'))
template_paths.append(template_path)
header = ("<?xml version='1.0' encoding='UTF-8'?>\n" +
'<!--' + '-' * 76 + '\n' +
'Modified by Calculate Utilities {}\n' +
'Processed template files:\n' +
'\n'.join(template_paths) + '\n' +
'-' * 77 + '-->\n').format(self.CALCULATE_VERSION)
document_text = re.sub(header_pattern, '', input_text)
return header, document_text

@ -20,7 +20,7 @@ disable-empty-zone "10.in-addr.arpa";
['"10.in-addr.arpa"']
})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary(self):
@ -58,7 +58,7 @@ zone "localhost" IN {
('', 'options'): options_section,
('', 'zone', '"localhost"', 'IN'): zone_section})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively(self):
@ -101,7 +101,7 @@ options {
result = OrderedDict({('', 'acl', '"dns_servers"'): acl_section,
('', 'options'): options_section})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -137,7 +137,7 @@ acl "dns_servers" {
('', 'acl', '"dns_servers"'): acl_section,
('-', 'options'): options_section})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary(self):
@ -201,7 +201,7 @@ acl "dns_servers" {
('', 'acl', '"dns_servers"'): acl_section,
('-', 'options'): options_section})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -252,7 +252,8 @@ acl "dns_servers" {
('', 'acl', '"dns_servers"'): acl_section,
('-', 'options'): options_section})
bind_object = BINDFormat(document_text, ignore_comments=True)
bind_object = BINDFormat(document_text, '/path/to/template',
ignore_comments=True)
assert bind_object._document_dictionary == result
def test_join_before(self):
@ -290,15 +291,18 @@ unspoken-parameter 1;
('', 'parameter-name'):
['/home/divanov/Home'],
('', 'other-parameter'):
['// Comment2', '// Comment3', 'yes']}),
['// Comment2',
'// Comment3', 'yes']}),
('', 'section-name-3'):
OrderedDict({('', 'another-parameter'):
['// Comment', '1'],
('', 'unspoken-parameter'):
['1']})})
bind_original_object = BINDFormat(original_text, join_before=True)
bind_template_object = BINDFormat(template_text, ignore_comments=True)
bind_original_object = BINDFormat(original_text, '/path/to/template',
join_before=True)
bind_template_object = BINDFormat(template_text, '/path/to/template',
ignore_comments=True)
bind_original_object.join_template(bind_template_object)
assert bind_original_object._document_dictionary == result
print('result text:\n{}\n'.format(bind_original_object.document_text))
@ -324,18 +328,22 @@ options {
('!', 'acl', '"dns_servers"'): OrderedDict(),
('', 'options'): options_section})
bind_object = BINDFormat(document_text)
bind_object = BINDFormat(document_text, '/path/to/template')
assert bind_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/bind_original.conf', 'r') as original_file:
with open('./tests/templates/format/testfiles/bind_original.conf',
'r') as original_file:
original_text = original_file.read()
print(original_text)
bind_original_object = BINDFormat(original_text)
bind_original_object = BINDFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/bind_template.conf', 'r') as template_file:
with open('./tests/templates/format/testfiles/bind_template.conf',
'r') as template_file:
template_text = template_file.read()
bind_template_object = BINDFormat(template_text,
'/path/to/template',
ignore_comments=True)
bind_original_object.join_template(bind_template_object)
@ -382,8 +390,187 @@ options {
recursion yes;
};
'''
document_1_object = BINDFormat(document_1)
document_2_object = BINDFormat(document_2)
document_1_object = BINDFormat(document_1, '/path/to/template')
document_2_object = BINDFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
}'''
template_text = '''section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
section-name-3 {
// Comment
unspoken-parameter 1;
};'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
// Comment
unspoken-parameter 1;
};
section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
'''
original_object = BINDFormat(original_text, '/path/to/template',
add_header=True)
template_object = BINDFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
}'''
template_text = '''section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
section-name-3 {
// Comment
unspoken-parameter 1;
};'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
// Comment
unspoken-parameter 1;
};
section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
'''
original_object = BINDFormat(original_text, '/path/to/template',
add_header=True)
template_object = BINDFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
}'''
template_text = '''section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
section-name-3 {
// Comment
unspoken-parameter 1;
};'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
// Comment1
section-name-2 {
parameter-name /home/divanov/Home;
// Comment2
// Comment3
other-parameter yes;
};
section-name-3 {
// Comment
another-parameter 1;
// Comment
unspoken-parameter 1;
};
section-name-1 {
parameter-name /homeless/poorness;
one-more-parameter no;
};
'''
original_object = BINDFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = BINDFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -26,7 +26,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -53,7 +53,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section(self):
@ -77,7 +77,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -97,7 +97,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -136,7 +136,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section_1,
('', 'Other Section'): section_2})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_if_the_ignore_comments_flag_is_set__the_parser_ignores_all_comments(self):
@ -170,7 +170,8 @@ class TestParsingMethods:
result = OrderedDict({('', 'Added Associations'): section_1,
('', 'Other Section'): section_2})
compiz_object = CompizFormat(document_text, ignore_comments=True)
compiz_object = CompizFormat(document_text, '/path/to/template',
ignore_comments=True)
assert compiz_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -197,22 +198,27 @@ class TestParsingMethods:
result = OrderedDict({('-', 'Added Associations'): section_1,
('!', 'Other Section'): section_2})
compiz_object = CompizFormat(document_text)
compiz_object = CompizFormat(document_text, '/path/to/template')
assert compiz_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/compiz_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/compiz_original',
'r') as original_file:
original_text = original_file.read()
compiz_original_object = CompizFormat(original_text)
compiz_original_object = CompizFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/compiz_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/compiz_template',
'r') as template_file:
template_text = template_file.read()
compiz_template_object = CompizFormat(template_text,
'/path/to/template',
ignore_comments=True)
compiz_original_object.join_template(compiz_template_object)
with open('./tests/templates/format/testfiles/compiz_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/compiz_result',
'r') as result_file:
result_text = result_file.read()
assert compiz_original_object.document_text == result_text
@ -250,8 +256,173 @@ video/vnd.mpegurl=smplayer.desktop;
'''
document_1_object = CompizFormat(document_1)
document_2_object = CompizFormat(document_2)
document_1_object = CompizFormat(document_1, '/path/to/template')
document_2_object = CompizFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
application/rtf=libreoffice-writer.desktop;
[Strange Section]
video/mp4=smplayer.desktop;
video/mpeg=smplayer.desktop;
'''
template_text = '''
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
!application/rtf
[!Strange Section]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',
add_header=True)
template_object = CompizFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
application/rtf=libreoffice-writer.desktop;
[Strange Section]
video/mp4=smplayer.desktop;
video/mpeg=smplayer.desktop;
'''
template_text = '''
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
!application/rtf
[!Strange Section]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',
add_header=True)
template_object = CompizFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
application/rtf=libreoffice-writer.desktop;
[Strange Section]
video/mp4=smplayer.desktop;
video/mpeg=smplayer.desktop;
'''
template_text = '''
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
# Comment2
# Comment3
!application/rtf
[!Strange Section]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
# Comment
[Added Associations]
# Comment1
application/illustrator=zzz-gimp.desktop
application/pdf=evince.desktop;
'''
original_object = CompizFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = CompizFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -20,7 +20,7 @@ class TestParsingMethods:
('', '/usr/share/bash-completion/completions'):
[('dir',)]})
contents_object = ContentsFormat(document_text)
contents_object = ContentsFormat(document_text, '/path/to/template')
assert result == contents_object._document_dictionary
def test_if_input_document_contains_a_few_lines_with_some_action_symbols__the_initialised_object_contains_correct_dictionary(self):
@ -38,7 +38,7 @@ class TestParsingMethods:
('!', '/usr/share/bash-completion/completions'):
[('dir',)]})
contents_object = ContentsFormat(document_text)
contents_object = ContentsFormat(document_text, '/path/to/template')
assert result == contents_object._document_dictionary
def test_if_template_parser_flag_is_set_False__the_initialized_object_contains_correct_dictionary_for_contents_util_module(self):
@ -61,22 +61,120 @@ class TestParsingMethods:
'/usr/share/bash-completion/completions':
OrderedDict({'type': 'dir'})})
contents_object = ContentsFormat(document_text, template_parser=False)
contents_object = ContentsFormat(document_text, '/path/to/template',
template_parser=False)
assert result == contents_object._document_dictionary
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/contents_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/contents_original',
'r') as original_file:
original_text = original_file.read()
contents_original_object = ContentsFormat(original_text)
contents_original_object = ContentsFormat(original_text, '/path/to/template')
with open('./tests/templates/format/testfiles/contents_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/contents_template',
'r') as template_file:
template_text = template_file.read()
contents_template_object = ContentsFormat(template_text,
'/path/to/template',
ignore_comments=True)
contents_original_object.join_template(contents_template_object)
with open('./tests/templates/format/testfiles/contents_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/contents_result',
'r') as result_file:
result_text = result_file.read()
assert contents_original_object.document_text == result_text
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
template_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
!sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
dir /usr/share/bash-completion/completions
'''
original_object = ContentsFormat(original_text, '/path/to/template',
add_header=True)
template_object = ContentsFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
template_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
!sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
dir /usr/share/bash-completion/completions
'''
original_object = ContentsFormat(original_text, '/path/to/template',
add_header=True)
template_object = ContentsFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
template_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
!sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
dir /usr/share/bash-completion/completions
'''
original_object = ContentsFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = ContentsFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -27,7 +27,7 @@ class TestParsingMethods:
['domain.com domain2.com']
})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary(self):
@ -54,7 +54,7 @@ class TestParsingMethods:
('', 'local', '127.0.0.2'):
local})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_if_input_document_contains_some_blocks_with_similar_names__the_blocks_join_recursively(self):
@ -98,7 +98,7 @@ class TestParsingMethods:
('', 'local', '127.0.0.2'):
local})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -134,7 +134,7 @@ class TestParsingMethods:
('!', 'local', '127.0.0.2'):
local})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary(self):
@ -170,7 +170,7 @@ class TestParsingMethods:
('', 'section', 'optional_name'):
section})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -204,7 +204,8 @@ class TestParsingMethods:
('', 'section', 'optional_name'):
section})
dovecot_object = DovecotFormat(document_text, ignore_comments=True)
dovecot_object = DovecotFormat(document_text, '/path/to/template',
ignore_comments=True)
assert dovecot_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_values_or_with_empty_block__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -234,17 +235,19 @@ class TestParsingMethods:
('!', 'local', '127.0.0.2'):
OrderedDict()})
dovecot_object = DovecotFormat(document_text)
dovecot_object = DovecotFormat(document_text, '/path/to/template')
assert dovecot_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/dovecot_original.conf', 'r') as original_file:
original_text = original_file.read()
dovecot_original_object = DovecotFormat(original_text)
dovecot_original_object = DovecotFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/dovecot_template.conf', 'r') as template_file:
template_text = template_file.read()
dovecot_template_object = DovecotFormat(template_text,
'/path/to/template',
ignore_comments=True)
dovecot_original_object.join_template(dovecot_template_object)
@ -302,8 +305,123 @@ namespace inbox {
'''
document_1_object = DovecotFormat(document_1, join_before=True)
document_2_object = DovecotFormat(document_2)
document_1_object = DovecotFormat(document_1, '/path/to/template',
join_before=True)
document_2_object = DovecotFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''
section optional_name {
section_setting_key = section_setting_value
subsection optional_subname {
subkey = subvalue
}
}
'''
template_text = '''
section optional_name {
!section_setting_key
}
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
section optional_name {
subsection optional_subname {
subkey = subvalue
}
}
'''
original_object = DovecotFormat(original_text, '/path/to/template',
add_header=True)
template_object = DovecotFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
section optional_name {
section_setting_key = section_setting_value
subsection optional_subname {
subkey = subvalue
}
}
'''
template_text = '''
section optional_name {
!section_setting_key
}
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
section optional_name {
subsection optional_subname {
subkey = subvalue
}
}
'''
original_object = DovecotFormat(original_text, '/path/to/template',
add_header=True)
template_object = DovecotFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
section optional_name {
section_setting_key = section_setting_value
subsection optional_subname {
subkey = subvalue
}
}
'''
template_text = '''
section optional_name {
!section_setting_key
subsection optional_subname {
subkey = subvalue
}
}
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
section optional_name {
subsection optional_subname {
subkey = subvalue
}
}
'''
original_object = DovecotFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = DovecotFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -24,17 +24,17 @@ class TestParsingMethods:
'BlockParam1': blockContent,
'Param3': True})
jsonObject = JSONFormat(documentText)
jsonObject = JSONFormat(documentText, '/path/to/template')
assert jsonObject._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/json_original.json', 'r') as originalFile:
originalText = originalFile.read()
jsonOriginalObject = JSONFormat(originalText)
jsonOriginalObject = JSONFormat(originalText, '/path/to/template')
with open('./tests/templates/format/testfiles/json_template.json', 'r') as templateFile:
templateText = templateFile.read()
jsonTemplateObject = JSONFormat(templateText)
jsonTemplateObject = JSONFormat(templateText, '/path/to/template')
jsonOriginalObject.join_template(jsonTemplateObject)
@ -76,8 +76,8 @@ class TestParsingMethods:
"Param4": 12.3
}'''
document_1_object = JSONFormat(document_1)
document_2_object = JSONFormat(document_2)
document_1_object = JSONFormat(document_1, '/path/to/template')
document_2_object = JSONFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2

@ -10,14 +10,15 @@ class TestParsingMethods:
parameter name = /home/divanov/Home
other parameter = yes'''
param_line_1 = OrderedDict({('', 'parameter name'): ['/home/divanov/Home']})
param_line_1 = OrderedDict({('', 'parameter name'):
['/home/divanov/Home']})
param_line_2 = OrderedDict({('', 'other parameter'): ['yes']})
result = OrderedDict({('', 'section name', 'first', 'second'):
OrderedDict(**param_line_1,
**param_line_2)})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_input_document_contains_parameters_with_values_with_unicode_symbols__the_initialized_object_contains_correct_dictionary(self):
@ -37,11 +38,12 @@ class TestParsingMethods:
('', 'GenericName[bg]'): ['IRC клиент'],
('', 'GenericName[bs]'): ['IRC klijent'],
('', 'GenericName[ca]'): ["Client d'IRC"],
('', 'GenericName[ca@valencia]'): ["Client d'IRC"]})
('', 'GenericName[ca@valencia]'):
["Client d'IRC"]})
result = OrderedDict({('', 'Desktop Entry', 'val'): section})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -59,16 +61,18 @@ class TestParsingMethods:
Exec=konversation -qwindowtitle %c %u
'''
section1Content = OrderedDict({('', 'alignment'): ['132'],
('', 'length'): ['674'],
('', 'thickness'): ['56']})
section_1_content = OrderedDict({('', 'alignment'): ['132'],
('', 'length'): ['674'],
('', 'thickness'): ['56']})
section_2_content = OrderedDict({('', 'Exec'): ['konversation -qwindowtitle %c %u']})
section_2_content = OrderedDict({('', 'Exec'):
['konversation -qwindowtitle %c %u']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section1Content,
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'): section_1_content,
('', 'Desktop Entry'): section_2_content})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_input_document_contains_sections_with_different_names_but_different_parameters__the_parameters_merged_in_one_section(self):
@ -84,13 +88,14 @@ class TestParsingMethods:
'''
section1Content = OrderedDict({('', 'alignment'): ['132'],
('', 'length'): ['674'],
('', 'thickness'): ['56']})
section_1_content = OrderedDict({('', 'alignment'): ['132'],
('', 'length'): ['674'],
('', 'thickness'): ['56']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section1Content})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'): section_1_content})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -101,13 +106,14 @@ class TestParsingMethods:
-thickness = 56
'''
section1Content = OrderedDict({('!', 'alignment'): ['132'],
('', 'length'): ['674'],
('-', 'thickness'): ['56']})
section_1_content = OrderedDict({('!', 'alignment'): ['132'],
('', 'length'): ['674'],
('-', 'thickness'): ['56']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section1Content})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'): section_1_content})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -136,13 +142,15 @@ class TestParsingMethods:
'#Comment 3',
'56']})
section_2_content = OrderedDict({('', 'Exec'): ['# Comment',
'konversation -qwindowtitle %c %u']})
section_2_content = OrderedDict({('', 'Exec'):
['# Comment',
'konversation -qwindowtitle %c %u']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section_1_content,
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'): section_1_content,
('', 'Desktop Entry'): section_2_content})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -167,12 +175,15 @@ class TestParsingMethods:
('', 'length'): ['674'],
('', 'thickness'): ['56']})
section_2_content = OrderedDict({('', 'Exec'): ['konversation -qwindowtitle %c %u']})
section_2_content = OrderedDict({('', 'Exec'):
['konversation -qwindowtitle %c %u']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section_1_content,
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'): section_1_content,
('', 'Desktop Entry'): section_2_content})
kde_object = KDEFormat(document_text, ignore_comments=True)
kde_object = KDEFormat(document_text, '/path/to/template',
ignore_comments=True)
assert kde_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -195,28 +206,36 @@ class TestParsingMethods:
section_2_content = OrderedDict({('', 'alignment'): ['132'],
('', 'panelVisibility'): ['1']})
section_3_content = OrderedDict({('', 'Exec'): ['konversation -qwindowtitle %c %u']})
section_3_content = OrderedDict({('', 'Exec'):
['konversation -qwindowtitle %c %u']})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69', 'Horizontal2048'): section_1_content,
('!', 'PlasmaViews', 'Panel 69'): section_2_content,
('-', 'Desktop Entry'): section_3_content})
result = OrderedDict({('', 'PlasmaViews', 'Panel 69',
'Horizontal2048'):
section_1_content,
('!', 'PlasmaViews', 'Panel 69'):
section_2_content,
('-', 'Desktop Entry'):
section_3_content})
kde_object = KDEFormat(document_text)
kde_object = KDEFormat(document_text, '/path/to/template')
assert kde_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/kde_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/kde_original',
'r') as original_file:
original_text = original_file.read()
kde_original_object = KDEFormat(original_text)
kde_original_object = KDEFormat(original_text, '/path/to/template')
with open('./tests/templates/format/testfiles/kde_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/kde_template',
'r') as template_file:
template_text = template_file.read()
kde_template_object = KDEFormat(template_text,
kde_template_object = KDEFormat(template_text, '/path/to/template',
ignore_comments=True)
kde_original_object.join_template(kde_template_object)
with open('./tests/templates/format/testfiles/kde_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/kde_result',
'r') as result_file:
result_text = result_file.read()
assert kde_original_object.document_text == result_text
@ -252,9 +271,120 @@ Width 1920=747
'''
document_1_object = KDEFormat(document_1)
document_2_object = KDEFormat(document_2)
document_1_object = KDEFormat(document_1, '/path/to/template')
document_2_object = KDEFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''
[PlasmaRunnerManager]
Count=What the freakin count...
pluginWhiteList=shell,bookmarks,locations
[FileDialogSize]
Height 1080=466
Width 1920=747
'''
template_text = '''
[PlasmaRunnerManager]
!Count=What the freakin count...
[!FileDialogSize]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
add_header=True)
template_object = KDEFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
Count=What the freakin count...
pluginWhiteList=shell,bookmarks,locations
[FileDialogSize]
Height 1080=466
Width 1920=747
'''
template_text = '''
[PlasmaRunnerManager]
!Count=What the freakin count...
[!FileDialogSize]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
add_header=True)
template_object = KDEFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
Count=What the freakin count...
pluginWhiteList=shell,bookmarks,locations
[FileDialogSize]
Height 1080=466
Width 1920=747
'''
template_text = '''
[PlasmaRunnerManager]
!Count=What the freakin count...
[!FileDialogSize]
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
[PlasmaRunnerManager]
pluginWhiteList=shell,bookmarks,locations
'''
original_object = KDEFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = KDEFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -14,7 +14,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'CONFIG_CC_IS_GCC'): ['y'],
('', 'CONFIG_GCC_VERSION'): ['90200']})
kernel_object = KernelFormat(document_text)
kernel_object = KernelFormat(document_text, '/path/to/template')
assert kernel_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -34,7 +34,7 @@ class TestParsingMethods:
('', 'CONFIG_CC_HAS_ASM_GOTO'): ['y'],
('', 'CONFIG_IRQ_WORK'): ['y']})
kernel_object = KernelFormat(document_text)
kernel_object = KernelFormat(document_text, '/path/to/template')
assert kernel_object._document_dictionary == result
def test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -48,7 +48,7 @@ class TestParsingMethods:
('', 'CONFIG_CC_IS_GCC'): ['y'],
('!', 'CONFIG_IRQ_WORK'): ['y']})
kernel_object = KernelFormat(document_text)
kernel_object = KernelFormat(document_text, '/path/to/template')
assert kernel_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -77,7 +77,7 @@ class TestParsingMethods:
('!', 'CONFIG_CROSS_MEMORY_ATTACH'):
['# Очень важный комментарий, который нужно удалить.','y']})
kernel_object = KernelFormat(document_text)
kernel_object = KernelFormat(document_text, '/path/to/template')
assert kernel_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -91,22 +91,27 @@ class TestParsingMethods:
('!', 'CONFIG_EXT3_FS_POSIX_ACL'): [],
('!', 'CONFIG_EXT3_FS_SECURITY'): []})
kernel_object = KernelFormat(document_text)
kernel_object = KernelFormat(document_text, '/path/to/template')
assert kernel_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/kernel_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/kernel_original',
'r') as original_file:
original_text = original_file.read()
kernel_original_object = KernelFormat(original_text)
kernel_original_object = KernelFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/kernel_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/kernel_template',
'r') as template_file:
template_text = template_file.read()
kernel_template_object = KernelFormat(template_text,
'/path/to/template',
ignore_comments=True)
kernel_original_object.join_template(kernel_template_object)
with open('./tests/templates/format/testfiles/kernel_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/kernel_result',
'r') as result_file:
result_text = result_file.read()
assert kernel_original_object.document_text == result_text
@ -129,9 +134,102 @@ CONFIG_EXT3_FS_POSIX_ACL=y
CONFIG_EXT3_FS_SECURITY=n
'''
document_1_object = KernelFormat(document_1)
document_2_object = KernelFormat(document_2)
document_1_object = KernelFormat(document_1, '/path/to/template')
document_2_object = KernelFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
template_text = '''
CONFIG_CC_IS_GCC=y
!CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
CONFIG_CC_IS_GCC=y
CONFIG_CLANG_VERSION=0
'''
original_object = KernelFormat(original_text, '/path/to/template',
add_header=True)
template_object = KernelFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
template_text = '''
CONFIG_CC_IS_GCC=y
!CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
CONFIG_CC_IS_GCC=y
CONFIG_CLANG_VERSION=0
'''
original_object = KernelFormat(original_text, '/path/to/template',
add_header=True)
template_object = KernelFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
template_text = '''
CONFIG_CC_IS_GCC=y
!CONFIG_GCC_VERSION=90500
CONFIG_CLANG_VERSION=0
'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
CONFIG_CC_IS_GCC=y
CONFIG_CLANG_VERSION=0
'''
original_object = KernelFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = KernelFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -6,7 +6,9 @@ from calculate.templates.format.ldap_format import LDAPFormat
@pytest.mark.ldap
class TestParsingMethods:
def test_if_logiclines_method_takes_text_with_lines_that_starts_whit_space_symbols__it_returns_joined_lines(self):
with open('./tests/templates/format/testfiles/ldap_logic_lines_test.txt', 'r') as input_file:
with open(
'./tests/templates/format/testfiles/ldap_logic_lines_test.txt',
'r') as input_file:
input_text = input_file.read()
output_lines = ['First string of test file.',
@ -14,7 +16,7 @@ class TestParsingMethods:
'Third string of test file.',
'Fourth string of test file.']
ldap_object = LDAPFormat('')
ldap_object = LDAPFormat('', '/path/to/template')
input_lines = ldap_object._get_list_of_logic_lines(input_text)
assert input_lines == output_lines
@ -37,9 +39,11 @@ directory /var/lib/openldap-data
rootdn "cn=ldaproot,dc=calculate"'''
global_section = OrderedDict({'#': [],
('', 'include', '/etc/openldap/schema/samba.schema'):
('', 'include',
'/etc/openldap/schema/samba.schema'):
[''],
('', 'include', '/etc/openldap/schema/mail.schema'):
('', 'include',
'/etc/openldap/schema/mail.schema'):
[''],
('', 'loglevel'): ['0'],
('', 'allow'): ['bind_v2'],
@ -58,7 +62,7 @@ rootdn "cn=ldaproot,dc=calculate"'''
result = OrderedDict({('', 'global'): global_section,
('', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_input_document_contains_access_to_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_access_to_parameters_and_comments(self):
@ -88,7 +92,8 @@ access to * by * read
access_2 = OrderedDict({'#': ['# Comment3'],
('', '*'): ['read']})
database_section = OrderedDict({('', 'access to', 'attrs=userPassword'):
database_section = OrderedDict({('', 'access to',
'attrs=userPassword'):
access_1,
('', 'access to', '*'):
access_2})
@ -96,7 +101,7 @@ access to * by * read
result = OrderedDict({('', 'global'): OrderedDict(),
('', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_input_document_contains_syncrepl_directive__the_object_s_dictionary_contains_correct_dictionary_with_list_of_syncrepl_parameters_and_comments(self):
@ -125,7 +130,7 @@ syncrepl rid=123
result = OrderedDict({('', 'global'): global_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_input_document_contains_index_directives__the_object_s_dictionary_contains_correct_dictionary_with_index_elements_and_comments(self):
@ -160,7 +165,7 @@ index default sub'''
result = OrderedDict({('', 'global'): global_section,
('', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_input_document_contains_comments_to_type_sections__the_object_s_dictionary_collect_them(self):
@ -193,7 +198,7 @@ cachesize 10000'''
result = OrderedDict({('', 'global'): global_section,
('', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_input_doc_contains_some_type_sections_with_plain_directives_and_action_marks__object_dictionary_contains_correct_dictionary_with_directives_values_and_comments(self):
@ -222,13 +227,15 @@ checkpoint 1024 5
'''
global_section = OrderedDict({'#': [],
('!', 'include', '/etc/openldap/schema/samba.schema'):
('!', 'include',
'/etc/openldap/schema/samba.schema'):
[''],
('-', 'include', '/etc/openldap/schema/mail.schema'):
('-', 'include',
'/etc/openldap/schema/mail.schema'):
['']})
backend_section = OrderedDict({('', 'modulepath'):
['/usr/lib/openldap/openldap']})
['/usr/lib/openldap/openldap']})
database_section = OrderedDict({('', 'checkpoint'): ['1024 5'],
('!', 'directory'):
@ -246,7 +253,7 @@ checkpoint 1024 5
('-', 'backend', 'hdb'): backend_section,
('!', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_if_template_text_contains_some_access_to_constuctions_with_same_what_value_and_without_action_marks_for_whole_constructions__they_join_in_one_access_to_construction(self):
@ -283,7 +290,8 @@ access to attrs=sambaLMPassword,sambaNTPassword
result = OrderedDict({('', 'global'): global_section})
ldap_object = LDAPFormat(document_text, ignore_comments=True)
ldap_object = LDAPFormat(document_text, '/path/to/template',
ignore_comments=True)
assert ldap_object._document_dictionary == result
def test_if_input_document_contains_syncrepl_and_access_to_constructions_with_action_marks__object_dictionary_contains_correct_dictionary_with_action_marks(self):
@ -335,30 +343,37 @@ database bdb
('!', 'syncrepl', 'rid=001'):
OrderedDict({'#': ['# Comment1']})})
database_section = OrderedDict({('!', 'access to', 'attrs=userPassword'):
database_section = OrderedDict({('!', 'access to',
'attrs=userPassword'):
access_1,
('!', 'access to', 'dn.base="cn=proxyuser,dc=calculate"'):
('!', 'access to',
'dn.base="cn=proxyuser,dc=calculate"'):
OrderedDict({'#': ['# Comment3']})})
result = OrderedDict({('', 'global'): global_section,
('', 'database', 'bdb'): database_section})
ldap_object = LDAPFormat(document_text)
ldap_object = LDAPFormat(document_text, '/path/to/template')
assert ldap_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/ldap_original.conf', 'r') as original_file:
with open('./tests/templates/format/testfiles/ldap_original.conf',
'r') as original_file:
original_text = original_file.read()
ldap_original_object = LDAPFormat(original_text)
ldap_original_object = LDAPFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/ldap_template.conf', 'r') as template_file:
with open('./tests/templates/format/testfiles/ldap_template.conf',
'r') as template_file:
template_text = template_file.read()
ldap_template_object = LDAPFormat(template_text,
'/path/to/template',
ignore_comments=True)
ldap_original_object.join_template(ldap_template_object)
with open('./tests/templates/format/testfiles/ldap_result.conf', 'r') as result_file:
with open('./tests/templates/format/testfiles/ldap_result.conf',
'r') as result_file:
result_text = result_file.read()
assert ldap_original_object.document_text == result_text

@ -18,13 +18,13 @@ class TestParsingMethods:
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text)
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
document_text = '''
rc_interactive="NO"
INSTANCE="openldap${SVCNAME#slapd}"
@ -39,7 +39,7 @@ class TestParsingMethods:
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text)
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
def test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -55,7 +55,7 @@ class TestParsingMethods:
('', 'opts_conf'): ['"-f /etc/${INSTANCE}/slapd.conf"'],
('!', 'opts'): ['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text)
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -84,7 +84,7 @@ class TestParsingMethods:
('', 'opts'):
['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text)
openrc_object = OpenRCFormat(document_text, '/path/to/template')
assert openrc_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -111,7 +111,8 @@ class TestParsingMethods:
('', 'opts'):
['"${OPTS_CONF} -h \'ldaps:// ldap:// ldapi://%2fvar%2frun%2fopenldap%2fslapd.sock\'"']})
openrc_object = OpenRCFormat(document_text, ignore_comments=True)
openrc_object = OpenRCFormat(document_text, '/path/to/template',
ignore_comments=True)
assert openrc_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -125,22 +126,28 @@ class TestParsingMethods:
('!', 'instance'): [],
('!', 'opts_conf'): []})
openrc_object = OpenRCFormat(document_text)
openrc_object = OpenRCFormat(document_text,
'/path/to/template')
assert openrc_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/openrc_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/openrc_original',
'r') as original_file:
original_text = original_file.read()
openrc_original_object = OpenRCFormat(original_text)
openrc_original_object = OpenRCFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/openrc_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/openrc_template',
'r') as template_file:
template_text = template_file.read()
openrc_template_object = OpenRCFormat(template_text,
'/path/to/template',
ignore_comments=True)
openrc_original_object.join_template(openrc_template_object)
with open('./tests/templates/format/testfiles/openrc_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/openrc_result',
'r') as result_file:
result_text = result_file.read()
assert openrc_original_object.document_text == result_text
@ -188,8 +195,8 @@ rc_send_sighup="YES"
'''
document_1_object = OpenRCFormat(document_1)
document_2_object = OpenRCFormat(document_2)
document_1_object = OpenRCFormat(document_1, '/path/to/template')
document_2_object = OpenRCFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)

@ -12,7 +12,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'parameter_name'): ['/home/divanov/Home'],
('', 'other_parameter'): ['yes']})
postfix_object = PostfixFormat(document_text)
postfix_object = PostfixFormat(document_text, '/path/to/template')
assert postfix_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -28,7 +28,7 @@ class TestParsingMethods:
('', 'other_parameter'): ['yes'],
('', 'another_parameter'): ['none']})
postfix_object = PostfixFormat(document_text)
postfix_object = PostfixFormat(document_text, '/path/to/template')
assert postfix_object._document_dictionary == result
def test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -40,7 +40,7 @@ class TestParsingMethods:
('', 'other_parameter'): ['yes'],
('!', 'another_parameter'): ['1']})
postfix_object = PostfixFormat(document_text)
postfix_object = PostfixFormat(document_text, '/path/to/template')
assert postfix_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -65,7 +65,7 @@ class TestParsingMethods:
('!', 'another_parameter'):
['# Очень важный комментарий, который нужно удалить.','1']})
postfix_object = PostfixFormat(document_text)
postfix_object = PostfixFormat(document_text, '/path/to/template')
assert postfix_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -90,7 +90,8 @@ class TestParsingMethods:
('!', 'another_parameter'):
['1']})
postfix_object = PostfixFormat(document_text, ignore_comments=True)
postfix_object = PostfixFormat(document_text, '/path/to/template',
ignore_comments=True)
assert postfix_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -103,22 +104,25 @@ class TestParsingMethods:
('!', 'other_parameter'): [],
('!', 'another_parameter'): []})
postfix_object = PostfixFormat(document_text)
postfix_object = PostfixFormat(document_text, '/path/to/template')
assert postfix_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/postfix_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/postfix_original',
'r') as original_file:
original_text = original_file.read()
postfix_original_object = PostfixFormat(original_text)
postfix_original_object = PostfixFormat(original_text, '/path/to/template')
with open('./tests/templates/format/testfiles/postfix_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/postfix_template',
'r') as template_file:
template_text = template_file.read()
postfix_template_object = PostfixFormat(template_text,
postfix_template_object = PostfixFormat(template_text, '/path/to/template',
ignore_comments=True)
postfix_original_object.join_template(postfix_template_object)
with open('./tests/templates/format/testfiles/postfix_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/postfix_result',
'r') as result_file:
result_text = result_file.read()
assert postfix_original_object.document_text == result_text
@ -171,8 +175,8 @@ mail_owner = postfix
'''
document_1_object = PostfixFormat(document_1)
document_2_object = PostfixFormat(document_2)
document_1_object = PostfixFormat(document_1, '/path/to/template')
document_2_object = PostfixFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)

@ -15,7 +15,7 @@ class TestParsingMethods:
('', 'parameter_name'): ['/home/divanov/Home'],
('', 'other_parameter'): ['yes']})
procmail_object = ProcmailFormat(document_text)
procmail_object = ProcmailFormat(document_text, '/path/to/template')
assert procmail_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -31,7 +31,7 @@ class TestParsingMethods:
('', 'parameter_name'): ['/home/divanov/Home'],
('', 'other_parameter'): ['yes']})
procmail_object = ProcmailFormat(document_text)
procmail_object = ProcmailFormat(document_text, '/path/to/template')
assert procmail_object._document_dictionary == result
def test_if_input_document_contains_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -50,7 +50,7 @@ class TestParsingMethods:
('', 'parameter_name'): ['/home/divanov/Home'],
('-', 'other_parameter'): ['yes']})
procmail_object = ProcmailFormat(document_text)
procmail_object = ProcmailFormat(document_text, '/path/to/template')
assert procmail_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -73,7 +73,7 @@ class TestParsingMethods:
('!', 'other_parameter'): ['# Comment',
'yes']})
procmail_object = ProcmailFormat(document_text)
procmail_object = ProcmailFormat(document_text, '/path/to/template')
assert procmail_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -93,7 +93,8 @@ class TestParsingMethods:
('', 'parameter_name'): ['/home/divanov/Home'],
('!', 'other_parameter'): ['yes']})
procmail_object = ProcmailFormat(document_text, ignore_comments=True)
procmail_object = ProcmailFormat(document_text, '/path/to/template',
ignore_comments=True)
assert procmail_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -109,22 +110,27 @@ class TestParsingMethods:
('!', 'parameter_name'): [],
('!', 'other_parameter'): []})
procmail_object = ProcmailFormat(document_text)
procmail_object = ProcmailFormat(document_text, '/path/to/template')
assert procmail_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/procmail_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/procmail_original',
'r') as original_file:
original_text = original_file.read()
procmail_original_object = ProcmailFormat(original_text)
procmail_original_object = ProcmailFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/procmail_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/procmail_template',
'r') as template_file:
template_text = template_file.read()
procmail_template_object = ProcmailFormat(template_text,
'/path/to/template',
ignore_comments=True)
procmail_original_object.join_template(procmail_template_object)
with open('./tests/templates/format/testfiles/procmail_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/procmail_result',
'r') as result_file:
result_text = result_file.read()
assert procmail_original_object.document_text == result_text
@ -154,8 +160,8 @@ net.ipv4.icmp_echo_ignore_broadcasts=1
'''
document_1_object = ProcmailFormat(document_1)
document_2_object = ProcmailFormat(document_2)
document_1_object = ProcmailFormat(document_1, '/path/to/template')
document_2_object = ProcmailFormat(document_2, '/path/to/template')
template = document_1_object.make_template(document_2_object)
document_1_object.join_template(template)

@ -22,7 +22,7 @@ class TestParsingMethods:
('', '', 'MaxInstances'):
['30']})
proftpd_object = ProFTPDFormat(document_text)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template')
assert proftpd_object._document_dictionary == result
def test_if_input_document_contains_some_block_of_parameters__the_initialised_object_contains_correct_dictionary(self):
@ -69,7 +69,7 @@ class TestParsingMethods:
('', (('Anonymous', '~ftp'), ('Limit', 'WRITE')),
'Deny from', 'all'): ['']})
proftpd_object = ProFTPDFormat(document_text)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template')
assert proftpd_object._document_dictionary == result
def test_if_input_document_contains_blocks_and_parameters_with_action_marks__the_key_tuples_of_parameters_s_have_it_as_its_first_element_inherited(self):
@ -105,7 +105,7 @@ class TestParsingMethods:
('!', (('Limit', 'WRITE'), ),
'Deny from', 'all'): ['']})
proftpd_object = ProFTPDFormat(document_text)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template')
assert proftpd_object._document_dictionary == result
def test_if_parameters_and_blocks_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value_or_with_special_key_in_block_dictionary(self):
@ -147,7 +147,7 @@ class TestParsingMethods:
('!', (('Limit', 'WRITE'), ),
'Deny from', 'all'): ['# Comment 4', '']})
proftpd_object = ProFTPDFormat(document_text)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template')
assert proftpd_object._document_dictionary == result
def test_if_the_ignoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -187,7 +187,8 @@ class TestParsingMethods:
('!', (('Limit', 'WRITE'), ),
'Deny from', 'all'): ['']})
proftpd_object = ProFTPDFormat(document_text, ignore_comments=True)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template',
ignore_comments=True)
assert proftpd_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_any_values_the_document_object_contains_dictionary_with_this_items_to_delete(self):
@ -216,17 +217,20 @@ class TestParsingMethods:
('!', (('Limit', 'WRITE'), ),
'Allow from', '10.0.0'): ['']})
proftpd_object = ProFTPDFormat(document_text, ignore_comments=True)
proftpd_object = ProFTPDFormat(document_text, '/path/to/template',
ignore_comments=True)
assert proftpd_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/proftpd_original.conf', 'r') as original_file:
original_text = original_file.read()
proftpd_original_object = ProFTPDFormat(original_text)
proftpd_original_object = ProFTPDFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/proftpd_template.conf', 'r') as template_file:
template_text = template_file.read()
proftpd_template_object = ProFTPDFormat(template_text,
'/path/to/template',
ignore_comments=True)
proftpd_original_object.join_template(proftpd_template_object)

@ -29,8 +29,8 @@ Another line of endless sadness.
<text>ParameterName = NewValue</text>
'''
patch_original = RegexFormat(input_text)
patch_template = RegexFormat(patch_text)
patch_original = RegexFormat(input_text, '/path/to/template')
patch_template = RegexFormat(patch_text, '/path/to/template')
patch_original.join_template(patch_template)
assert patch_original.document_text == output_text
@ -78,8 +78,10 @@ Another line of endless sadness.
parameters = ParametersContainer({'multiline': True, 'dotall': True})
patch_original = RegexFormat(input_text, parameters=parameters)
patch_template = RegexFormat(patch_text, parameters=parameters)
patch_original = RegexFormat(input_text, '/path/to/template',
parameters=parameters)
patch_template = RegexFormat(patch_text, '/path/to/template',
parameters=parameters)
patch_original.join_template(patch_template)
assert patch_original.document_text == output_text

@ -16,7 +16,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'section name'): OrderedDict(**param_line_1,
**param_line_2)})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_input_document_contains_few_parameter_lines_and_some_empty_lines__the_initialized_object_contains_correct_dictionary(self):
@ -35,7 +35,8 @@ class TestParsingMethods:
'''
section_1_content = OrderedDict({('', 'parameter name'): ['/home/divanov/Home'],
section_1_content = OrderedDict({('', 'parameter name'):
['/home/divanov/Home'],
('', 'other parameter'): ['yes'],
('', 'second parameter'): ['1']})
@ -44,7 +45,7 @@ class TestParsingMethods:
result = OrderedDict({('', 'section name1'): section_1_content,
('', 'section name2'): section_2_content})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_input_document_contains_sections_with_similar_names_but_different_parameters__the_parameters_merged_in_one_section(self):
@ -55,12 +56,13 @@ class TestParsingMethods:
[section name]
another parameter = 1'''
section_content = OrderedDict({('', 'parameter name'): ['/home/divanov/Home'],
section_content = OrderedDict({('', 'parameter name'):
['/home/divanov/Home'],
('', 'other parameter'): ['yes'],
('', 'another parameter'): ['1']})
result = OrderedDict({('', 'section name'): section_content})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_input_document_contains_sections_with_parameters_with_action_marks__the_key_tuples_of_object_s_dictionary_have_it_as_its_first_element(self):
@ -69,12 +71,13 @@ class TestParsingMethods:
other parameter = yes
!another parameter = 1'''
section_content = OrderedDict({('-', 'parameter name'): ['/home/divanov/Home'],
section_content = OrderedDict({('-', 'parameter name'):
['/home/divanov/Home'],
('', 'other parameter'): ['yes'],
('!', 'another parameter'): ['1']})
result = OrderedDict({('', 'section name'): section_content})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_parameter_in_input_document_has_some_comments__the_comments_will_be_collected_in_the_list_of_parameter_value(self):
@ -101,7 +104,7 @@ class TestParsingMethods:
('!', 'another parameter'):
['#Comment', '1']})})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
@ -117,7 +120,8 @@ class TestParsingMethods:
#Comment
!another parameter = 1'''
section_1 = OrderedDict({('', 'parameter name'): ['/home/divanov/Home'],
section_1 = OrderedDict({('', 'parameter name'):
['/home/divanov/Home'],
('', 'other parameter'): ['yes']})
section_2 = OrderedDict({('!', 'another parameter'): ['1']})
@ -125,7 +129,8 @@ class TestParsingMethods:
result = OrderedDict({('', 'section name1'): section_1,
('', 'section name2'): section_2})
samba_object = SambaFormat(document_text, ignore_comments=True)
samba_object = SambaFormat(document_text, '/path/to/template',
ignore_comments=True)
assert samba_object._document_dictionary == result
def test_if_input_document_contains_parameters_to_delete_without_assign_symbol_and_any_values_and_sections_to_delete__the_document_object_contains_dictionary_with_item_to_delete(self):
@ -139,7 +144,8 @@ class TestParsingMethods:
[-section name3]
parameter = no'''
section_1 = OrderedDict({('!', 'parameter name'): ['/home/divanov/Home'],
section_1 = OrderedDict({('!', 'parameter name'):
['/home/divanov/Home'],
('!', 'other parameter'): [],
('!', 'another parameter'): []})
section_2 = OrderedDict({('', 'parameter'): ['no']})
@ -148,7 +154,7 @@ class TestParsingMethods:
('!', 'section name2'): section_2,
('-', 'section name3'): section_2})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_if_joinBefore_flag_is_set__the_document_object_contains_dictionary_with_sections_added_in_the_top_of_it(self):
@ -191,8 +197,10 @@ class TestParsingMethods:
('', 'unspoken parameter'):
['1']})})
samba_original_object = SambaFormat(original_text, join_before=True)
samba_template_object = SambaFormat(template_text, ignore_comments=True)
samba_original_object = SambaFormat(original_text, '/path/to/template',
join_before=True)
samba_template_object = SambaFormat(template_text, '/path/to/template',
ignore_comments=True)
samba_original_object.join_template(samba_template_object)
assert samba_original_object._document_dictionary == result
@ -208,22 +216,27 @@ class TestParsingMethods:
result = OrderedDict({('', 'section'): OrderedDict(**param_line_1,
**param_line_2)})
samba_object = SambaFormat(document_text)
samba_object = SambaFormat(document_text, '/path/to/template')
assert samba_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/samba_original', 'r') as original_file:
with open('./tests/templates/format/testfiles/samba_original',
'r') as original_file:
original_text = original_file.read()
samba_original_object = SambaFormat(original_text)
samba_original_object = SambaFormat(original_text,
'/path/to/template')
with open('./tests/templates/format/testfiles/samba_template', 'r') as template_file:
with open('./tests/templates/format/testfiles/samba_template',
'r') as template_file:
template_text = template_file.read()
samba_template_object = SambaFormat(template_text,
'/path/to/template',
ignore_comments=True)
samba_original_object.join_template(samba_template_object)
with open('./tests/templates/format/testfiles/samba_result', 'r') as result_file:
with open('./tests/templates/format/testfiles/samba_result',
'r') as result_file:
result_text = result_file.read()
assert samba_original_object.document_text == result_text
@ -251,8 +264,166 @@ class TestParsingMethods:
one more parameter = oh no
'''
document_1_object = SambaFormat(document_1)
document_2_object = SambaFormat(document_2)
document_1_object = SambaFormat(document_1, '/path/to/template')
document_2_object = SambaFormat(document_2, '/path/to/template')
template_object = document_1_object.make_template(document_2_object)
document_1_object.join_template(template_object)
assert document_1_object.document_text == document_2
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1'''
template_text = '''[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
[section name3]
# Comment
unspoken parameter = 1'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1
# Comment
unspoken parameter = 1
[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
'''
original_object = SambaFormat(original_text, '/path/to/template',
add_header=True)
template_object = SambaFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1'''
template_text = '''[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
[section name3]
# Comment
unspoken parameter = 1'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/template
#-------------------------------------------------------------------------------
# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1
# Comment
unspoken parameter = 1
[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
'''
original_object = SambaFormat(original_text, '/path/to/template',
add_header=True)
template_object = SambaFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
#-------------------------------------------------------------------------------
# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1'''
template_text = '''[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
[section name3]
# Comment
unspoken parameter = 1'''
join_result = '''#-------------------------------------------------------------------------------
# Modified by Calculate Utilities 4.0
# Processed template files:
# /path/to/ancient/template
# /path/to/template
#-------------------------------------------------------------------------------
# Comment1
[section name2]
parameter name = /home/divanov/Home
# Comment2
# Comment3
other parameter = yes
[section name3]
#Comment
another parameter = 1
# Comment
unspoken parameter = 1
[section name1]
parameter name = /homeless/poorness
one more parameter = oh no
'''
original_object = SambaFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = SambaFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

@ -37,7 +37,7 @@ class TestParsingMethods:
('', 'entry', ('name', 'logo_icon_name'), ('mtime', '1342486180'), ('type', 'string')):
OrderedDict({('', 'stringvalue'): 'distributor'})})})})})
xml_gconf_object = XMLGConfFormat(document_text)
xml_gconf_object = XMLGConfFormat(document_text, '/path/to/template')
assert xml_gconf_object._document_dictionary == result
def test_if_input_document_is_simple_gconf__the_format_object_contains_correct_dictionary(self):
@ -69,17 +69,17 @@ class TestParsingMethods:
('', 'entry', ('name', 'hinting'), ('mtime', '1298136657'), ('type', 'list')):
OrderedDict({('', 'stringvalue'): 'full'})})})
xml_gconf_object = XMLGConfFormat(document_text)
xml_gconf_object = XMLGConfFormat(document_text, '/path/to/template')
assert xml_gconf_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/xml_gconf_original.xml', 'r') as original_file:
original_text = original_file.read()
xml_gconf_original_object = XMLGConfFormat(original_text)
xml_gconf_original_object = XMLGConfFormat(original_text, '/path/to/template')
with open('./tests/templates/format/testfiles/xml_gconf_template.xml', 'r') as template_file:
template_text = template_file.read()
xml_gconf_template_object = XMLGConfFormat(template_text)
xml_gconf_template_object = XMLGConfFormat(template_text, '/path/to/template')
xml_gconf_original_object.join_template(xml_gconf_template_object)
@ -87,3 +87,200 @@ class TestParsingMethods:
result_text = result_file.read()
assert xml_gconf_original_object.document_text == result_text
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
<entry name="logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="!logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/template
------------------------------------------------------------------------------->
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
</dir>
</dir>
</gconf>
'''
original_object = XMLGConfFormat(original_text, '/path/to/template',
add_header=True)
template_object = XMLGConfFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
print(original_object.document_text)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
------------------------------------------------------------------------------->
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
<entry name="logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="!logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/template
------------------------------------------------------------------------------->
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
</dir>
</dir>
</gconf>
'''
original_object = XMLGConfFormat(original_text, '/path/to/template',
add_header=True)
template_object = XMLGConfFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
print(original_object.document_text)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
------------------------------------------------------------------------------->
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
<entry name="logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="!logo_icon_name" mtime="1342486180" type="string">
<stringvalue>distributor</stringvalue>
</entry>
</dir>
</dir>
</gconf>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
/path/to/template
------------------------------------------------------------------------------->
<gconf>
<dir name="gnome">
<dir name="ymsgr">
<entry name="needs_terminal">
<default type="string">
<stringvalue>Something I can never have.</stringvalue>
</default>
<local_schema short_desc="Run the command in a terminal">
<longdesc>True if the command used to handle this type of URL should be run in a terminal.</longdesc>
</local_schema>
</entry>
</dir>
</dir>
</gconf>
'''
original_object = XMLGConfFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = XMLGConfFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
print(original_object.document_text)
assert original_object.document_text == join_result

@ -32,17 +32,17 @@ class TestParsingMethods:
result = OrderedDict({('', 'channel', 'xsettings', '1.0'): channel_content})
xml_xfce_object = XMLXfceFormat(document_text)
xml_xfce_object = XMLXfceFormat(document_text, '/path/to/template')
assert xml_xfce_object._document_dictionary == result
def test_joining_documents_1(self):
with open('./tests/templates/format/testfiles/xml_xfce_original.xml', 'r') as original_file:
original_text = original_file.read()
xml_xfce_original_object = XMLXfceFormat(original_text)
xml_xfce_original_object = XMLXfceFormat(original_text, '/path/to/template')
with open('./tests/templates/format/testfiles/xml_xfce_template.xml', 'r') as template_file:
template_text = template_file.read()
xml_xfce_template_object = XMLXfceFormat(template_text)
xml_xfce_template_object = XMLXfceFormat(template_text, '/path/to/template')
xml_xfce_original_object.join_template(xml_xfce_template_object)
@ -50,3 +50,125 @@ class TestParsingMethods:
result_text = result_file.read()
assert xml_xfce_original_object.document_text == result_text
def test_if_input_documents_are_an_original_document_without_calculate_header_and_a_template_and_the_add_header_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
<property name="HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="!HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/template
------------------------------------------------------------------------------->
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
</property>
</channel>
'''
original_object = XMLXfceFormat(original_text, '/path/to/template',
add_header=True)
template_object = XMLXfceFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_not_set__the_format_object_removes_calculate_header_from_original_document__joins_an_original_document_and_a_template_and_adds_the_calculate_header(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
------------------------------------------------------------------------------->
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
<property name="HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="!HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/template
------------------------------------------------------------------------------->
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
</property>
</channel>
'''
original_object = XMLXfceFormat(original_text, '/path/to/template',
add_header=True)
template_object = XMLXfceFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result
def test_if_input_documents_are_an_original_document_with_calculate_header_and_a_template_the_add_header_flag_is_set_and_the_already_changed_flag_is_set__the_format_object_joins_an_original_document_and_a_template_and_adds_the_calculate_header_with_a_template_paths_from_the_old_header_and_paths_to_a_current_template(self):
original_text = '''<?xml version="1.0" encoding="UTF-8"?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
------------------------------------------------------------------------------->
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
<property name="HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
template_text = '''<?xml version="1.0" encoding="UTF-8"?>
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="!HintStyle" type="string" value="hintmedium"/>
</property>
</channel>
'''
join_result = '''<?xml version='1.0' encoding='UTF-8'?>
<!------------------------------------------------------------------------------
Modified by Calculate Utilities 4.0
Processed template files:
/path/to/ancient/template
/path/to/template
------------------------------------------------------------------------------->
<channel name="xsettings" version="1.0">
<property name="Xft" type="empty">
<property name="Antialias" type="int" value="1"/>
</property>
</channel>
'''
original_object = XMLXfceFormat(original_text, '/path/to/template',
add_header=True, already_changed=True)
template_object = XMLXfceFormat(template_text, '/path/to/template')
original_object.join_template(template_object)
assert original_object.document_text == join_result

Loading…
Cancel
Save