def test_should_keep_fileending_of_target_file(self): tempfile.mkstemp = self.old_mkstemp with imagemagick.temp_file(self.target) as result: self.assertEquals( self.target.split('.')[-1], result.split('.')[-1]) open(result, 'w').write("hello")
def test_should_overwrite_target_file_if_already_exists(self): open(self.target,'w').write("good bye") with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") self.assertEquals("hello", open(self.target, 'r').read())
def test_should_overwrite_target_file_if_already_exists(self): open(self.target, 'w').write("good bye") with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") self.assertEquals("hello", open(self.target, 'r').read())
def test_should_remove_tempfile_if_failing(self): try: with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") raise Exception except Exception: self.assertFalse(os.path.isfile(self.temp_file))
def test_should_keep_fileending_of_target_file(self): tempfile.mkstemp = self.old_mkstemp with imagemagick.temp_file(self.target) as result: self.assertEquals(self.target.split('.')[-1], result.split('.')[-1]) open(result, 'w').write("hello")
def test_should_remove_tempfile_after_done(self): with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") self.assertFalse(os.path.isfile(self.temp_file))
def test_should_replace_target_with_temp_file(self): with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") self.assertEquals("hello", open(self.target, 'r').read())
def test_should_work_on_temp_file(self): with imagemagick.temp_file(self.target) as result: open(result, 'w').write("hello") self.assertEquals(self.temp_file, result) self.assertTrue(os.path.isfile(self.temp_file))