You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
5.9 KiB
125 lines
5.9 KiB
import pytest
|
|
from collections import OrderedDict
|
|
from calculate.templates.format.postfix_format import PostfixFormat
|
|
|
|
|
|
@pytest.mark.postfix
|
|
class TestParsingMethods:
|
|
def test_if_input_document_contains_just_few_parameter_lines__the_initialised_object_contains_correct_dictionary(self):
|
|
document_text = '''parameter_name = /home/divanov/Home
|
|
other_parameter = yes'''
|
|
|
|
result = OrderedDict({('', 'parameter_name'): ['/home/divanov/Home'],
|
|
('', 'other_parameter'): ['yes']})
|
|
|
|
postfix_object = PostfixFormat(document_text)
|
|
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):
|
|
document_text = '''parameter_name = /home/divanov/Home
|
|
|
|
|
|
other_parameter = yes
|
|
|
|
another_parameter = none
|
|
'''
|
|
|
|
result = OrderedDict({('', 'parameter_name'): ['/home/divanov/Home'],
|
|
('', 'other_parameter'): ['yes'],
|
|
('', 'another_parameter'): ['none']})
|
|
|
|
postfix_object = PostfixFormat(document_text)
|
|
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):
|
|
document_text = '''-parameter_name = /home/divanov/Home
|
|
other_parameter = yes
|
|
!another_parameter = 1'''
|
|
|
|
result = OrderedDict({('-', 'parameter_name'): ['/home/divanov/Home'],
|
|
('', 'other_parameter'): ['yes'],
|
|
('!', 'another_parameter'): ['1']})
|
|
|
|
postfix_object = PostfixFormat(document_text)
|
|
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):
|
|
document_text = '''# Comment1
|
|
parameter_name = /home/divanov/Home
|
|
|
|
# Comment2
|
|
# Comment3
|
|
other_parameter = yes
|
|
smtp_tls_note_starttls_offer = yes
|
|
tls_random_source = dev:/dev/urandom
|
|
|
|
# Очень важный комментарий, который нужно удалить.
|
|
!another_parameter = 1'''
|
|
|
|
result = OrderedDict({('', 'parameter_name'):
|
|
['# Comment1', '/home/divanov/Home'],
|
|
('', 'other_parameter'):
|
|
['# Comment2', '# Comment3', 'yes'],
|
|
('', 'smtp_tls_note_starttls_offer'): ['yes'],
|
|
('', 'tls_random_source'): ['dev:/dev/urandom'],
|
|
('!', 'another_parameter'):
|
|
['# Очень важный комментарий, который нужно удалить.','1']})
|
|
|
|
postfix_object = PostfixFormat(document_text)
|
|
assert postfix_object._document_dictionary == result
|
|
|
|
def test_if_the_IgnoreComments_flag_is_set__the_parser_ignores_all_comments(self):
|
|
document_text = '''# Comment1
|
|
parameter_name = /home/divanov/Home
|
|
|
|
# Comment2
|
|
# Comment3
|
|
other_parameter = yes
|
|
smtp_tls_note_starttls_offer = yes
|
|
tls_random_source = dev:/dev/urandom
|
|
|
|
# Очень важный комментарий, который нужно удалить.
|
|
!another_parameter = 1'''
|
|
|
|
result = OrderedDict({('', 'parameter_name'):
|
|
['/home/divanov/Home'],
|
|
('', 'other_parameter'):
|
|
['yes'],
|
|
('', 'smtp_tls_note_starttls_offer'): ['yes'],
|
|
('', 'tls_random_source'): ['dev:/dev/urandom'],
|
|
('!', 'another_parameter'):
|
|
['1']})
|
|
|
|
postfix_object = PostfixFormat(document_text, 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):
|
|
document_text = '''!parameter_name = /home/divanov/Home
|
|
!other_parameter =
|
|
-ignored_line
|
|
!another_parameter'''
|
|
|
|
result = OrderedDict({('!', 'parameter_name'): ['/home/divanov/Home'],
|
|
('!', 'other_parameter'): [],
|
|
('!', 'another_parameter'): []})
|
|
|
|
postfix_object = PostfixFormat(document_text)
|
|
assert postfix_object._document_dictionary == result
|
|
|
|
def test_joining_documents_1(self):
|
|
with open('./tests/templates/format/testfiles/postfix_original', 'r') as original_file:
|
|
original_text = original_file.read()
|
|
postfix_original_object = PostfixFormat(original_text)
|
|
|
|
with open('./tests/templates/format/testfiles/postfix_template', 'r') as template_file:
|
|
template_text = template_file.read()
|
|
postfix_template_object = PostfixFormat(template_text,
|
|
ignore_comments=True)
|
|
|
|
postfix_original_object.join_template(postfix_template_object)
|
|
|
|
with open('./tests/templates/format/testfiles/postfix_result', 'r') as result_file:
|
|
result_text = result_file.read()
|
|
|
|
assert postfix_original_object.get_document_text() == result_text
|