MCPcopy Create free account
hub / github.com/twisted/twisted / test_replaceInFile

Method test_replaceInFile

src/twisted/python/test/test_release.py:287–305  ·  view source on GitHub ↗

L{replaceInFile} replaces data in a file based on a dict. A key from the dict that is found in the file is replaced with the corresponding value.

(self)

Source from the content-addressed store, hash-verified

285 self.assertEqual(cwd, os.getcwd())
286
287 def test_replaceInFile(self):
288 """
289 L{replaceInFile} replaces data in a file based on a dict. A key from
290 the dict that is found in the file is replaced with the corresponding
291 value.
292 """
293 content = "foo\nhey hey $VER\nbar\n"
294 with open("release.replace", "w") as outf:
295 outf.write(content)
296
297 expected = content.replace("$VER", "2.0.0")
298 replaceInFile("release.replace", {"$VER": "2.0.0"})
299 with open("release.replace") as f:
300 self.assertEqual(f.read(), expected)
301
302 expected = expected.replace("2.0.0", "3.0.0")
303 replaceInFile("release.replace", {"2.0.0": "3.0.0"})
304 with open("release.replace") as f:
305 self.assertEqual(f.read(), expected)
306
307
308class FilePathDeltaTests(TestCase):

Callers

nothing calls this directly

Calls 6

replaceInFileFunction · 0.90
replaceMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
assertEqualMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected