21 with pytest.raises(DuplicateFieldException):
22 upto = upt([
"a",
"b",
"a"],
":",
"\n")
25 with pytest.raises(EmptyFieldNameException):
26 upto = upt([
"a",
"",
"a"],
":",
"\n")
29 with pytest.raises(EmptyFieldNameException):
30 upto = upt([
"a",
None,
"a"],
":",
"\n")
33 with pytest.raises(SeparatorEmptyException):
34 upto = upt([
"a",
"b",
"c"],
"",
"\n")
37 with pytest.raises(SeparatorEmptyException):
38 upto = upt([
"a",
"b",
"c"],
None,
"\n")
41 with pytest.raises(NewlineEmptyException):
42 upto = upt([
"a",
"b",
"c"],
":",
"")
45 with pytest.raises(NewlineEmptyException):
46 upto = upt([
"a",
"b",
"c"],
":",
None)
49 with pytest.raises(InvalidFileFormatException):
50 upto = upt([
"a",
"b",
"c"],
":",
"\n")
51 upto.add_line_from_text(
"a:b:c:d")
54 with pytest.raises(InvalidFileFormatException):
55 upto = upt([
"a",
"b",
"c"],
":",
"\n")
56 upto.load_text(
"a:b:c\nd:e:f\ng:h:i\ny:\na:b:d:c")
58 @pytest.mark.parametrize(
"arg,expected",
[
("1:1:1", {"a": "1", "b": "1", "c": "1"}),
59 (
"1:2:3", {
"a":
"1",
"b":
"2",
"c":
"3"}),
60 (
"a:b:c", {
"a":
"a",
"b":
"b",
"c":
"c"}),
61 (
"f:e:d", {
"a":
"f",
"b":
"e",
"c":
"d"}),
63 "some longer string:with more data:exe",
64 {
"a":
"some longer string",
"b":
"with more data",
"c":
"exe"},
69 a = upt([
"a",
"b",
"c"])
70 result = a.parse_line(arg)
71 assert result == expected
73 @pytest.mark.parametrize(
"arg,expected",
[
({"a": "1", "b": "1", "c": "1"}, "1:1:1"),
74 ({
"a":
"1",
"b":
"2",
"c":
"3"},
"1:2:3"),
75 ({
"a":
"a",
"b":
"b",
"c":
"c"},
"a:b:c"),
76 ({
"a":
"f",
"b":
"e",
"c":
"d"},
"f:e:d"),
78 {
"a":
"some longer string",
"b":
"with more data",
"c":
"exe"},
79 "some longer string:with more data:exe",
84 a = upt([
"a",
"b",
"c"])
85 result = a.create_line(arg)
86 assert result == expected
88 @pytest.mark.parametrize(
"arg",
[
({"a": "1", "b": "1", "c": "1"}),
89 ({
"a":
"1",
"b":
"2",
"c":
"3"}),
90 ({
"a":
"a",
"b":
"b",
"c":
"c"}),
91 ({
"a":
"f",
"b":
"e",
"c":
"d"}),
92 ({
"a":
"some longer string",
"b":
"with more data",
"c":
"exe"}),
96 a = upt([
"a",
"b",
"c"])
97 before = len(a.text_lines)
99 after = len(a.text_lines)
100 assert after > before
102 @pytest.mark.parametrize(
"arg",
[
("1:1:1"),
106 (
"some longer string:with more data:exe"),
110 a = upt([
"a",
"b",
"c"])
111 before = len(a.text_lines)
112 a.add_line_from_text(arg)
113 after = len(a.text_lines)
114 assert after > before
117 a = upt([
"a",
"b",
"c"])
118 a.add_line_from_text(
"a:b:C")
119 a.add_new_line({
"a": 1,
"b": 2,
"c": 3})
120 assert a.dump_text() ==
"a:b:C\n1:2:3\n"
123 a = upt([
"a",
"b",
"c"])
124 a.load_text(
"a:b:C\n1:2:3\n")
125 a.add_line_from_text(
"a:b:C")
126 a.add_new_line({
"a": 1,
"b": 2,
"c": 3})
127 assert a.dump_text() ==
"a:b:C\n1:2:3\na:b:C\n1:2:3\n"
130 if __name__ ==
"__main__":
132
def test_load_then_dump_text_ok(self)
def test_upt_none_keyname(self)
def test_dump_text_ok(self)
def test_upt_none_newline(self)
def test_upt_duplicate_keynames(self)
def test_upt_add_new_line_ok(self, arg)
def test_upt_invalid_line(self)
def test_upt_create_line_ok(self, arg, expected)
def test_upt_invalid_block(self)
def test_upt_parse_line_ok(self, arg, expected)
def test_upt_none_separator(self)
def test_upt_empty_newline(self)
def test_upt_add_line_from_text_ok(self, arg)
def test_upt_empty_keyname(self)
def test_upt_empty_separator(self)
This module provides utlilities related to creating, reading, writing and parsing of linux-style pass...