1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""
import pytest
from dataproperty import LineBreakHandling, Preprocessor
class Test_Preprocessor_update:
def test_normal(self):
preprocessor = Preprocessor()
assert preprocessor.strip_str is None
assert preprocessor.replace_tabs_with_spaces is True
assert preprocessor.tab_length == 2
assert preprocessor.line_break_handling is LineBreakHandling.NOP
assert preprocessor.line_break_repl == " "
assert preprocessor.dequote is False
assert preprocessor.is_escape_html_tag is False
assert preprocessor.is_escape_formula_injection is False
assert preprocessor.update(
strip_str='"',
replace_tabs_with_spaces=False,
tab_length=4,
line_break_handling=LineBreakHandling.REPLACE,
line_break_repl="<br>",
dequote=True,
is_escape_html_tag=True,
is_escape_formula_injection=True,
)
assert preprocessor.strip_str == '"'
assert preprocessor.replace_tabs_with_spaces is False
assert preprocessor.tab_length == 4
assert preprocessor.line_break_handling is LineBreakHandling.REPLACE
assert preprocessor.line_break_repl == "<br>"
assert preprocessor.dequote is True
assert preprocessor.is_escape_html_tag is True
assert preprocessor.is_escape_formula_injection is True
assert not preprocessor.update(strip_str='"')
assert preprocessor.update(strip_str="")
class Test_Preprocessor_preprocess:
@pytest.mark.parametrize(
["value", "expected"],
[
['abc "efg"', 'abc "efg"'],
['"abc efg"', "abc efg"],
["'abc efg'", "abc efg"],
['"abc" "efg"', '"abc" "efg"'],
["'abc' 'efg'", "'abc' 'efg'"],
["\"abc 'efg'\"", "abc 'efg'"],
],
)
def test_normal_dequote(self, value, expected):
preprocessor = Preprocessor(
dequote=True,
)
data, no_ansi_escape_data = preprocessor.preprocess(value)
assert data == expected
class Test_Preprocessor_preprocess_string:
@pytest.mark.parametrize(
["value", "expected"],
[
[{"1": 1}, {"1": 1}],
[{"1"}, {"1"}],
],
)
def test_not_str(self, value, expected):
preprocessor = Preprocessor(dequote=True)
data, _ = preprocessor._Preprocessor__preprocess_string(value)
assert data == expected
|