File: test_parsers.py

package info (click to toggle)
python-pathable 0.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 188 kB
  • sloc: python: 968; makefile: 3
file content (102 lines) | stat: -rw-r--r-- 2,315 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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pytest

from pathable.parsers import parse_args
from pathable.parsers import parse_parts
from pathable.paths import BasePath


class TestParseParts:

    separator = "/"

    def test_empty(self):
        parts = []

        result = parse_parts(parts, self.separator)

        assert result == []

    def test_one(self):
        parts = ["test"]

        result = parse_parts(parts, self.separator)

        assert result == ["test"]

    def test_simple(self):
        parts = ["test", "test1", "test2"]

        result = parse_parts(parts, self.separator)

        assert result == ["test", "test1", "test2"]

    def test_none(self):
        parts = ["test", None, "test1", None, "test2"]

        result = parse_parts(parts, self.separator)

        assert result == ["test", "test1", "test2"]

    def test_relative(self):
        parts = ["test", ".", "test1", ".", "test2"]

        result = parse_parts(parts, self.separator)

        assert result == ["test", "test1", "test2"]

    def test_separator(self):
        sep_part = "test1{sep}test2{sep}test3".format(sep=self.separator)
        parts = ["test", sep_part]

        result = parse_parts(parts, self.separator)

        assert result == ["test", "test1", "test2", "test3"]

    def test_separator_with_relative(self):
        sep_part = "test1{sep}.{sep}test2{sep}.{sep}test3".format(
            sep=self.separator
        )
        parts = ["test", sep_part]

        result = parse_parts(parts, self.separator)

        assert result == ["test", "test1", "test2", "test3"]


class TestParseArgs:

    separator = "/"

    def test_empty(self):
        args = []

        result = parse_args(args, self.separator)

        assert result == []

    def test_string(self):
        args = ["test"]

        result = parse_args(args, self.separator)

        assert result == ["test"]

    def test_string_many(self):
        args = ["test", "test2"]

        result = parse_args(args, self.separator)

        assert result == ["test", "test2"]

    def test_path(self):
        args = [BasePath("test")]

        result = parse_args(args, self.separator)

        assert result == ["test"]

    def test_invalid_part(self):
        args = [(2,), (3,)]

        with pytest.raises(TypeError):
            parse_args(args, self.separator)