Esempio n. 1
0
 def test_non_existing(self):
     f = util.AtomicFile(self.path)
     try:
         f.write('test content')
     finally:
         f.close()
     self.assertEqual('test content', util.read_file(self.path))
Esempio n. 2
0
 def test_existing(self):
     util.create_file(self.path, 'Some content')
     self.assertEqual('Some content', util.read_file(self.path))
     with util.AtomicFile(self.path) as f:
         f.write('Some new content')
     self.assertEqual(True, f.closed)
     self.assertEqual('Some new content', util.read_file(self.path))
Esempio n. 3
0
 def _test_unicode_path(self):
     self.path = os.path.join(tempfile.gettempdir(), u'träc-témpfilè')
     f = util.AtomicFile(self.path)
     try:
         f.write('test content')
     finally:
         f.close()
     self.assertEqual('test content', util.read_file(self.path))
Esempio n. 4
0
 def test_existing_open_for_reading(self):
     util.create_file(self.path, 'Initial file content')
     self.assertEqual('Initial file content', util.read_file(self.path))
     with open(self.path) as rf:
         with util.AtomicFile(self.path) as f:
             f.write('Replaced content')
     self.assertEqual(True, rf.closed)
     self.assertEqual(True, f.closed)
     self.assertEqual('Replaced content', util.read_file(self.path))
Esempio n. 5
0
 def test_existing(self):
     util.create_file(self.path, 'Some content')
     self.assertEqual('Some content', util.read_file(self.path))
     f = util.AtomicFile(self.path)
     try:
         f.write('Some new content')
     finally:
         f.close()
     self.assertEqual('Some new content', util.read_file(self.path))
Esempio n. 6
0
        def test_symbolic_link(self):
            link_path = os.path.join(self.dir, 'trac-tempfile-link')
            os.symlink(self.path, link_path)

            with util.AtomicFile(link_path) as f:
                f.write('test content')

            self.assertTrue(os.path.islink(link_path))
            self.assertEqual('test content', util.read_file(link_path))
            self.assertEqual('test content', util.read_file(self.path))
Esempio n. 7
0
 def test_existing_open_for_reading(self):
     util.create_file(self.path, 'Initial file content')
     self.assertEqual('Initial file content', util.read_file(self.path))
     rf = open(self.path)
     try:
         f = util.AtomicFile(self.path)
         try:
             f.write('Replaced content')
         finally:
             f.close()
     finally:
         rf.close()
     self.assertEqual('Replaced content', util.read_file(self.path))
Esempio n. 8
0
 def _test_unicode_path(self):
     self.path = os.path.join(tempfile.gettempdir(), u'träc-témpfilè')
     with util.AtomicFile(self.path) as f:
         f.write('test content')
     self.assertEqual(True, f.closed)
     self.assertEqual('test content', util.read_file(self.path))
Esempio n. 9
0
 def test_non_existing(self):
     with util.AtomicFile(self.path) as f:
         f.write('test content')
     self.assertEqual(True, f.closed)
     self.assertEqual('test content', util.read_file(self.path))