def test_sed_limit_escaped(self): with tempfile.NamedTemporaryFile() as tfile: tfile.write(SED_CONTENT) tfile.seek(0, 0) path = tfile.name before = "/var/lib/foo" after = "" limit = "^{0}".format(before) filemod.sed(path, before, after, limit=limit) with open(path, "rb") as newfile: self.assertEquals(SED_CONTENT.replace(before, ""), newfile.read())
def test_sed_limit_escaped(self): with tempfile.NamedTemporaryFile() as tfile: tfile.write(SED_CONTENT) tfile.seek(0, 0) path = tfile.name before = '/var/lib/foo' after = '' limit = '^{0}'.format(before) filemod.sed(path, before, after, limit=limit) with open(path, 'rb') as newfile: self.assertEquals(SED_CONTENT.replace(before, ''), newfile.read())
def test_sed_limit_escaped(sed_content, subdir): with salt.utils.files.fopen(str(subdir / "tfile"), "w+") as tfile: tfile.write(sed_content) tfile.seek(0, 0) path = tfile.name before = "/var/lib/foo" after = "" limit = "^{}".format(before) filemod.sed(path, before, after, limit=limit) with salt.utils.files.fopen(path, "r") as newfile: assert sed_content.replace(before, "") == salt.utils.stringutils.to_unicode( newfile.read() )
def test_sed_limit_escaped(self): with tempfile.NamedTemporaryFile(mode='w+') as tfile: tfile.write(SED_CONTENT) tfile.seek(0, 0) path = tfile.name before = '/var/lib/foo' after = '' limit = '^{0}'.format(before) filemod.sed(path, before, after, limit=limit) with salt.utils.fopen(path, 'r') as newfile: self.assertEqual( SED_CONTENT.replace(before, ''), newfile.read() )