示例#1
0
文件: file_test.py 项目: herlo/salt
    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())
示例#2
0
    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())
示例#3
0
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()
            )
示例#4
0
    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()
                )