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.

83 lines
4.0 KiB

import pytest
from collections import OrderedDict
from calculate.templates.format.contents_format import ContentsFormat
@pytest.mark.contents
class TestParsingMethods:
def test_if_input_document_contains_a_few_lines_without_any_action_symbols__the_initialised_object_contains_correct_dictionary(self):
document_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
result = OrderedDict({('', '/usr/bin/vim'):
[('obj', '30acc0f256e11c1ecdb1bd80b688d238',
'1573538056')],
('', '/usr/share/bash-completion/completions/ex'):
[('sym', 'vim', '1573538054')],
('', '/usr/share/bash-completion/completions'):
[('dir',)]})
contents_object = ContentsFormat(document_text)
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):
document_text = '''
!obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
-sym /usr/share/bash-completion/completions/ex -> vim 1573538054
!dir /usr/share/bash-completion/completions
'''
result = OrderedDict({('!', '/usr/bin/vim'):
[('obj', '30acc0f256e11c1ecdb1bd80b688d238',
'1573538056')],
('-', '/usr/share/bash-completion/completions/ex'):
[('sym', 'vim', '1573538054')],
('!', '/usr/share/bash-completion/completions'):
[('dir',)]})
contents_object = ContentsFormat(document_text)
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):
document_text = '''
obj /usr/bin/vim 30acc0f256e11c1ecdb1bd80b688d238 1573538056
sym /usr/share/bash-completion/completions/ex -> vim 1573538054
dir /usr/share/bash-completion/completions
'''
result = OrderedDict({'/usr/bin/vim':
OrderedDict(
{'type': 'obj',
'md5': '30acc0f256e11c1ecdb1bd80b688d238',
'mtime': '1573538056'}),
'/usr/share/bash-completion/completions/ex':
OrderedDict(
{'type': 'sym',
'target': 'vim',
'mtime': '1573538054'}),
'/usr/share/bash-completion/completions':
OrderedDict({'type': 'dir'})})
contents_object = ContentsFormat(document_text, 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:
original_text = original_file.read()
contents_original_object = ContentsFormat(original_text)
with open('./tests/templates/format/testfiles/contents_template', 'r') as template_file:
template_text = template_file.read()
contents_template_object = ContentsFormat(template_text,
ignore_comments=True)
contents_original_object.join_template(contents_template_object)
with open('./tests/templates/format/testfiles/contents_result', 'r') as result_file:
result_text = result_file.read()
assert contents_original_object.get_document_text() == result_text