def test_write(self):
        with common.atomic_write(self.input_file) as fp:
            self.assertNotEqual(self.input_file, fp.name)
            fp.write(self.new_content)

        self.assertFalse(os.path.exists(fp.name))

        with open(self.input_file) as fp:
            self.assertEqual(self.new_content, fp.read())
Exemplo n.º 2
0
    def test_write(self):
        with common.atomic_write(self.input_file) as fp:
            self.assertNotEqual(self.input_file, fp.name)
            fp.write(self.new_content)

        self.assertFalse(os.path.exists(fp.name))

        with open(self.input_file) as fp:
            self.assertEqual(self.new_content, fp.read())
    def test_exception_leaves_unchanged(self):
        try:
            with common.atomic_write(self.input_file) as tf:
                raise IOError()
        except IOError:
            with open(self.input_file) as fp:
                self.assertEqual(self.initial_content, fp.read())

            # Ensure deleted
            self.assertFalse(os.path.exists(tf.name))
Exemplo n.º 4
0
    def test_exception_leaves_unchanged(self):
        try:
            with common.atomic_write(self.input_file) as tf:
                raise IOError()
        except IOError:
            with open(self.input_file) as fp:
                self.assertEqual(self.initial_content, fp.read())

            # Ensure deleted
            self.assertFalse(os.path.exists(tf.name))