File: test_base.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 (65 lines) | stat: -rw-r--r-- 1,532 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""Test (abstract) base FS class."""

from __future__ import unicode_literals

import unittest

from fs import errors
from fs.base import FS


class DummyFS(FS):
    def getinfo(self, path, namespaces=None):
        pass

    def listdir(self, path):
        pass

    def makedir(self, path, permissions=None, recreate=False):
        pass

    def openbin(self, path, mode="r", buffering=-1, **options):
        pass

    def remove(self, path):
        pass

    def removedir(self, path):
        pass

    def setinfo(self, path, info):
        pass


class TestBase(unittest.TestCase):
    def setUp(self):
        self.fs = DummyFS()

    def test_validatepath(self):
        """Test validatepath method."""
        with self.assertRaises(TypeError):
            self.fs.validatepath(b"bytes")

        self.fs._meta["invalid_path_chars"] = "Z"
        with self.assertRaises(errors.InvalidCharsInPath):
            self.fs.validatepath("Time for some ZZZs")

        self.fs.validatepath("fine")
        self.fs.validatepath("good.fine")

        self.fs._meta["invalid_path_chars"] = ""
        self.fs.validatepath("Time for some ZZZs")

        def mock_getsyspath(path):
            return path

        self.fs.getsyspath = mock_getsyspath

        self.fs._meta["max_sys_path_length"] = 10

        self.fs.validatepath("0123456789")
        self.fs.validatepath("012345678")
        self.fs.validatepath("01234567")

        with self.assertRaises(errors.InvalidPath):
            self.fs.validatepath("0123456789A")