Пример #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)