File: test_compat.py

package info (click to toggle)
python-scantree 0.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 228 kB
  • sloc: python: 1,040; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download
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
from os import DirEntry, scandir

import pytest

from scantree.compat import fspath


class TestFSPath:
    def test_string(self):
        assert fspath("path/to") == "path/to"

    def test__fspath__(self):
        class Path:
            def __init__(self, path):
                self.path = path

            def __fspath__(self):
                return self.path

        assert fspath(Path("path/to/this")) == "path/to/this"

    def test_not_supported(self):
        with pytest.raises(TypeError):
            fspath(1)


class TestScandir:
    def test_basic(self, tmpdir):
        tmpdir.join("file").ensure()
        for path_like in [tmpdir, str(tmpdir)]:
            [de] = list(scandir(path_like))
            assert isinstance(de, DirEntry)
            assert de.name == "file"

    def test_none_path(self, tmpdir):
        tmpdir.join("file").ensure()
        with tmpdir.as_cwd():
            [de] = list(scandir(None))
            assert isinstance(de, DirEntry)
            assert de.name == "file"