File: test_tempfs.py

package info (click to toggle)
python-fs 2.4.16-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: python: 13,048; makefile: 226; sh: 3
file content (35 lines) | stat: -rw-r--r-- 829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import unicode_literals

import os

from fs import errors
from fs.tempfs import TempFS

from .test_osfs import TestOSFS

try:
    from unittest import mock
except ImportError:
    import mock


class TestTempFS(TestOSFS):
    """Test OSFS implementation."""

    def make_fs(self):
        return TempFS()

    def test_clean(self):
        t = TempFS()
        _temp_dir = t.getsyspath("/")
        self.assertTrue(os.path.isdir(_temp_dir))
        t.close()
        self.assertFalse(os.path.isdir(_temp_dir))

    @mock.patch("shutil.rmtree", create=True)
    def test_clean_error(self, rmtree):
        rmtree.side_effect = Exception("boom")
        with self.assertRaises(errors.OperationFailed):
            t = TempFS(ignore_clean_errors=False)
            t.writebytes("foo", b"bar")
            t.close()