예제 #1
0
 def test_makereadonly_dir(self):
     temp = tempfile.mkdtemp()
     try:
         self.assertTrue(is_writable(temp))
         make_readonly(temp)
         self.assertFalse(is_writable(temp))
     finally:
         rmtree_readonly(temp)
예제 #2
0
 def test_makereadonly_dir(self):
     temp = tempfile.mkdtemp()
     try:
         self.assertTrue(is_writable(temp))
         make_readonly(temp)
         self.assertFalse(is_writable(temp))
     finally:
         rmtree_readonly(temp)
예제 #3
0
 def test_makereadonly_dir(self):
     temp = tempfile.mkdtemp()
     try:
         path = Path(temp)
         self.assertTrue(stat.S_IWUSR & path.stat()[stat.ST_MODE])
         make_readonly(temp)
         self.assertFalse(stat.S_IWUSR & path.stat()[stat.ST_MODE])
     finally:
         rmtree_readonly(temp)
예제 #4
0
 def test_rmtree_readonly(self):
     d = tempfile.mkdtemp()
     path = Path(d)
     try:
         (path / 'a file').open('w')
         (path / 'a directory').mkdir()
         (path / 'a directory' / 'another file').open('w')
         make_readonly(path)
         self.assertTrue(path.is_dir())
     finally:
         rmtree_readonly(path)
         self.assertFalse(path.is_dir())
예제 #5
0
 def test_rmtree_readonly(self):
     d = tempfile.mkdtemp()
     path = Path(d)
     try:
         (path / 'a file').open('w')
         (path / 'a directory').mkdir()
         (path / 'a directory' / 'another file').open('w')
         make_readonly(path)
         self.assertTrue(path.is_dir())
     finally:
         rmtree_readonly(path)
         self.assertFalse(path.is_dir())
예제 #6
0
def temp_directory_with_files(*paths):
    """A context manager that creates a temporary directory and copies all
    paths to it. The temporary directory is unlinked when the context is exited.
    """
    temp = tempfile.mkdtemp()
    try:
        temp = Path(temp)
        for p in paths:
            shutil.copy(str(p), str(temp / Path(p).name))
        yield temp
    finally:
        rmtree_readonly(temp)
예제 #7
0
    def test_save_crops_read_only_directory(self):
        "Can't write crops to a read-only directory"
        # This case is doing more than simply testing filesystem behavour
        # because it tests the failure code in InselectImage
        temp = tempfile.mkdtemp()
        try:
            make_readonly(temp)

            i = InselectImage(TESTDATA / 'test_segment.png')
            with self.assertRaises(InselectError):
                i.save_crops([Rect(0, 0, 1, 1)], [Path(temp) / 'x.png'])
        finally:
            rmtree_readonly(temp)
예제 #8
0
    def test_save_crops_read_only_directory(self):
        "Can't write crops to a read-only directory"
        # This case is doing more than simply testing filesystem behavour
        # because it tests the failure code in InselectImage
        temp = tempfile.mkdtemp()
        try:
            make_readonly(temp)

            i = InselectImage(TESTDATA / 'test_segment.png')
            with self.assertRaises(InselectError):
                i.save_crops([Rect(0, 0, 1, 1)], [Path(temp) / 'x.png'])
        finally:
            rmtree_readonly(temp)
예제 #9
0
 def tearDown(self):
     try:
         rmtree_readonly(self.inbox)
     finally:
         rmtree_readonly(self.docs)
예제 #10
0
 def tearDown(self):
     try:
         rmtree_readonly(self.inbox)
     finally:
         rmtree_readonly(self.docs)