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.
81 lines
2.5 KiB
81 lines
2.5 KiB
import pytest
|
|
from collections import OrderedDict
|
|
from calculate.templates.format.patch_format import PatchFormat
|
|
|
|
|
|
@pytest.mark.patch
|
|
class TestParsingMethods:
|
|
def test_if_input_patch_document_contains_only_regular_expressions_without_any_regex_flags__it_correctly_patches_input_document(self):
|
|
input_text = '''
|
|
First line
|
|
Another meaningless line.
|
|
TEXT&DATA
|
|
ParameterName = Value
|
|
Another line of endless sadness.
|
|
'''
|
|
|
|
output_text = '''
|
|
First line
|
|
Another meaningless line.
|
|
TEXT_CONFIG
|
|
ParameterName = NewValue
|
|
Another line of endless sadness.
|
|
'''
|
|
|
|
patch_text = '''<reg>TEXT&DATA</reg>
|
|
<text>TEXT_CONFIG</text>
|
|
<reg>ParameterName\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]*</reg>
|
|
<text>ParameterName = NewValue</text>
|
|
'''
|
|
|
|
patch = PatchFormat(patch_text)
|
|
patch_result = patch.execute_format(input_text)
|
|
|
|
assert patch_result == output_text
|
|
|
|
def test_if_input_patch_document_contains_regular_expressions_with_global_regex_flags_and_flags_as_attributes__it_correctly_patches_input_document_using_regex_flags(self):
|
|
input_text = '''
|
|
#============================== Share Definitions =============================
|
|
[homes]
|
|
comment = Home Directories
|
|
browseable = no
|
|
writable = yes
|
|
|
|
# Un-comment the following and create the netlogon directory for Domain Logons
|
|
[netlogon]
|
|
comment = Network Logon Service
|
|
path = /var/lib/samba/netlogon
|
|
guest ok = yes
|
|
writable = no
|
|
share modes = no
|
|
'''
|
|
|
|
output_text = '''
|
|
#============================== Share Definitions =============================
|
|
[homes]
|
|
comment = Home Directories
|
|
browseable = who knows
|
|
writable = yes
|
|
|
|
# Un-comment the following and create the netlogon directory for Domain Logons
|
|
[netlogon]
|
|
comment = Network Logon Service
|
|
path = /var/lib/samba/netlogon
|
|
writable = yes
|
|
share modes = no
|
|
'''
|
|
|
|
patch_text = '''
|
|
<reg dotall="1" multiline="0">(\\[netlogon\\].*)writable\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]*</reg>
|
|
<text>\\1writable = yes</text>
|
|
<reg multiline="false" dotall="True">(\\[homes\\].*)browseable\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]*</reg>
|
|
<text>\\1browseable = who knows</text>
|
|
<reg>(\\[netlogon\\].*)^\\s*guest ok\\s*=\\s*[a-zA-Z_][a-zA-Z_0-9]*\\n</reg>
|
|
<text>\\1</text>
|
|
'''
|
|
|
|
patch = PatchFormat(patch_text, multiline=True, dotall=True)
|
|
patch_result = patch.execute_format(input_text)
|
|
|
|
assert patch_result == output_text
|