MCPcopy Create free account
hub / github.com/etingof/apacheconfig / testDumpWholeConfig

Method testDumpWholeConfig

tests/unit/test_loader.py:73–132  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

71 )
72
73 def testDumpWholeConfig(self):
74 text = """\
75
76# a
77a = b
78
79<a block>
80 a = b
81</a>
82a b
83<a a block>
84c "d d"
85b = 三
86</a>
87# a
88"""
89
90 expect_text = """\
91a b
92<a>
93 <block>
94 a b
95 </block>
96</a>
97a b
98<a>
99 <a block>
100 c "d d"
101 b 三
102 </a block>
103</a>
104"""
105
106 ApacheConfigLexer = make_lexer()
107 ApacheConfigParser = make_parser()
108
109 loader = ApacheConfigLoader(
110 ApacheConfigParser(ApacheConfigLexer()))
111
112 config = loader.loads(text)
113 gen_text = loader.dumps(config)
114
115 try:
116 self.assertEqual(expect_text, gen_text)
117 except AssertionError:
118 # Account for non-deterministic ordering of dict items;
119 # swap lines `b 三` and `c "d d"`
120 lines = expect_text.split('\n')
121 lines[9], lines[10] = lines[10], lines[9]
122 expect_text = "\n".join(lines)
123 self.assertEqual(expect_text, gen_text)
124
125 # Testing dump(filepath, config)
126 tmpd = tempfile.mkdtemp()
127 filepath = os.path.join(tmpd, "config")
128 loader.dump(filepath, config)
129 with io.open(filepath, mode='r', encoding='utf-8') as f:
130 text = f.read()

Callers

nothing calls this directly

Calls 7

loadsMethod · 0.95
dumpsMethod · 0.95
dumpMethod · 0.95
make_lexerFunction · 0.90
make_parserFunction · 0.90
ApacheConfigLoaderClass · 0.90
openMethod · 0.80

Tested by

no test coverage detected