Пример #1
0
 def test_same(self):
     f1 = NamedTemporaryFile("wt", delete=False)
     try:
         f1.write("fofo")
         f1.close()
         f2 = NamedTemporaryFile("wt", delete=False)
         try:
             f2.write("fofo")
             f2.close()
             self.assertTrue(same_content(f1.name, f2.name))
         finally:
             os.remove(f2.name)
     finally:
         os.remove(f1.name)
Пример #2
0
def run_with_tempfile(content, function, mode="w"):
    """Create a temporary file with the given content, and execute tbe
    given function after the temporary file has been closed.

    The file is guaranteed to be deleted whether function succeeds or not
    """
    f = NamedTemporaryFile(mode=mode, delete=False)
    try:
        f.write(content)
        f.close()
        return function(f.name)
    finally:
        f.close()
        os.remove(f.name)
Пример #3
0
def run_with_tempfile(content, function, mode="w"):
    """Create a temporary file with the given content, and execute tbe
    given function after the temporary file has been closed.

    The file is guaranteed to be deleted whether function succeeds or not
    """
    f = NamedTemporaryFile(mode=mode, delete=False)
    try:
        f.write(content)
        f.close()
        return function(f.name)
    finally:
        f.close()
        os.remove(f.name)
Пример #4
0
 def test_same(self):
     f1 = NamedTemporaryFile("wt", delete=False)
     try:
         f1.write("fofo")
         f1.close()
         f2 = NamedTemporaryFile("wt", delete=False)
         try:
             f2.write("fofo")
             f2.close()
             self.assertTrue(same_content(f1.name, f2.name))
         finally:
             os.remove(f2.name)
     finally:
         os.remove(f1.name)