~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

(spiv) Fix edge cases in handling interrupts during _rename_in_limbo.
 (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2548
2548
        self.assertPathDoesNotExist(path)
2549
2549
        self.assertPathDoesNotExist(tt._limbodir)
2550
2550
 
 
2551
    def test_rename_in_limbo_rename_raises_after_rename(self):
 
2552
        tt, trans_id = self.create_transform_and_root_trans_id()
 
2553
        parent1 = tt.new_directory('parent1', tt.root)
 
2554
        child1 = tt.new_file('child1', parent1, 'contents')
 
2555
        parent2 = tt.new_directory('parent2', tt.root)
 
2556
 
 
2557
        class FakeOSModule(object):
 
2558
            def rename(self, old, new):
 
2559
                os.rename(old, new)
 
2560
                raise RuntimeError
 
2561
        self._override_globals_in_method(tt, "_rename_in_limbo",
 
2562
            {"os": FakeOSModule()})
 
2563
        self.assertRaises(
 
2564
            RuntimeError, tt.adjust_path, "child1", parent2, child1)
 
2565
        path = osutils.pathjoin(tt._limbo_name(parent2), "child1")
 
2566
        self.assertPathExists(path)
 
2567
        tt.finalize()
 
2568
        self.assertPathDoesNotExist(path)
 
2569
        self.assertPathDoesNotExist(tt._limbodir)
 
2570
 
 
2571
    def test_rename_in_limbo_rename_raises_before_rename(self):
 
2572
        tt, trans_id = self.create_transform_and_root_trans_id()
 
2573
        parent1 = tt.new_directory('parent1', tt.root)
 
2574
        child1 = tt.new_file('child1', parent1, 'contents')
 
2575
        parent2 = tt.new_directory('parent2', tt.root)
 
2576
 
 
2577
        class FakeOSModule(object):
 
2578
            def rename(self, old, new):
 
2579
                raise RuntimeError
 
2580
        self._override_globals_in_method(tt, "_rename_in_limbo",
 
2581
            {"os": FakeOSModule()})
 
2582
        self.assertRaises(
 
2583
            RuntimeError, tt.adjust_path, "child1", parent2, child1)
 
2584
        path = osutils.pathjoin(tt._limbo_name(parent1), "child1")
 
2585
        self.assertPathExists(path)
 
2586
        tt.finalize()
 
2587
        self.assertPathDoesNotExist(path)
 
2588
        self.assertPathDoesNotExist(tt._limbodir)
 
2589
 
2551
2590
 
2552
2591
class TestTransformMissingParent(tests.TestCaseWithTransport):
2553
2592