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.
123 lines
4.8 KiB
123 lines
4.8 KiB
import pytest
|
|
from calculate.vars.vars_loader import CalculateIniParser, Define
|
|
|
|
|
|
@pytest.mark.vars
|
|
@pytest.mark.calculateini
|
|
class TestCalculateIni:
|
|
def test_empty_calculate_ini(self):
|
|
pass
|
|
# ns = Namespace(varPath=None)
|
|
# assert ns.varPath is None
|
|
|
|
def test_section_values(self):
|
|
ini_parser = CalculateIniParser()
|
|
|
|
input_text = ("[section]\n"
|
|
"varval1 = value1\n")
|
|
|
|
parsed_lines = [{'start_section': (['section'],)},
|
|
{'define_key': (['section'], 'varval1',
|
|
'value1', Define.assign)},
|
|
]
|
|
|
|
parse_result = list(ini_parser.parse(input_text))
|
|
for parsed_line, result_line in zip(parsed_lines, parse_result):
|
|
assert parsed_line == result_line
|
|
|
|
def test_simple_calculate_ini_with_comments(self):
|
|
ini_parser = CalculateIniParser()
|
|
|
|
input_text = ("[section]\n"
|
|
"varval1 = value1\n"
|
|
"# some comment\n"
|
|
"varval2 += value2\n"
|
|
"varval3 -= value3\n")
|
|
|
|
parsed_lines = [{'start_section': (['section'],)},
|
|
{'define_key': (['section'], 'varval1',
|
|
'value1', Define.assign)},
|
|
{'define_key': (['section'], 'varval2',
|
|
'value2', Define.append)},
|
|
{'define_key': (['section'], 'varval3',
|
|
'value3', Define.remove)},
|
|
]
|
|
|
|
parse_result = list(ini_parser.parse(input_text))
|
|
for parsed_line, result_line in zip(parsed_lines, parse_result):
|
|
assert parsed_line == result_line
|
|
|
|
def test_some_complex_section_calculate_ini(self):
|
|
ini_parser = CalculateIniParser()
|
|
|
|
input_text = ("[section][sub]\n"
|
|
"varval1 = value1\n"
|
|
"varval2 = value2\n"
|
|
"[section][sub2]\n"
|
|
"varval1 = value1\n"
|
|
"\n"
|
|
"[section2]\n"
|
|
"varval1 = value1\n")
|
|
|
|
parsed_lines = [{'start_section': (['section', 'sub'],)},
|
|
{'define_key': (['section', 'sub'],
|
|
'varval1', 'value1', Define.assign)},
|
|
{'define_key': (['section', 'sub'],
|
|
'varval2', 'value2', Define.assign)},
|
|
{'start_section': (['section', 'sub2'],)},
|
|
{'define_key': (['section', 'sub2'],
|
|
'varval1', 'value1', Define.assign)},
|
|
{'start_section': (['section2'],)},
|
|
{'define_key': (['section2'], 'varval1',
|
|
'value1', Define.assign)}]
|
|
|
|
parse_result = list(ini_parser.parse(input_text))
|
|
for parsed_line, result_line in zip(parsed_lines, parse_result):
|
|
assert parsed_line == result_line
|
|
|
|
def test_error(self):
|
|
ini_parser = CalculateIniParser()
|
|
|
|
input_text = ("[section\n"
|
|
"varval1 = value1\n"
|
|
"varval2 = value2\n"
|
|
"[section][sub2]\n"
|
|
"varval1 = value1\n"
|
|
"eee\n"
|
|
"\n"
|
|
"[section2\n"
|
|
"varval4 = value4\n"
|
|
"[section][]\n"
|
|
"[section][][sub]\n"
|
|
"[section][][sub][]\n")
|
|
|
|
parsed_lines = [{'start_section': (['section', 'sub2'],)},
|
|
{'define_key': (['section', 'sub2'],
|
|
'varval1', 'value1', Define.assign)},
|
|
{'define_key': (['section', 'sub2'],
|
|
'varval4', 'value4', Define.assign)},
|
|
{'clear_section': (['section'],)}
|
|
]
|
|
|
|
errors = [('[section', 1, 1),
|
|
('varval1 = value1', 2, 1),
|
|
('varval2 = value2', 3, 1),
|
|
('eee', 6, 1),
|
|
('[section2', 8, 1),
|
|
('[section][][sub]', 11, 1),
|
|
('[section][][sub][]', 12, 1),
|
|
]
|
|
|
|
parse_result = list(ini_parser.parse(input_text))
|
|
|
|
for error, parsed_error in zip(errors, ini_parser.errors):
|
|
assert parsed_error == error
|
|
for parsed_line, result_line in zip(parsed_lines, parse_result):
|
|
assert parsed_line == result_line
|
|
|
|
def test_clear_section(self):
|
|
ini_parser = CalculateIniParser()
|
|
|
|
parse_result = next(ini_parser.parse("[section][test][]\n"))
|
|
assert parse_result == {'clear_section': (['section', 'test'],)}
|