Пример #1
0
class TestBasePathEq(object):

    @pytest.mark.parametrize(
        'part1,part2,expected',
        (
            [
                u(''), u(''), True
            ],
            [
                u(''), u('part'), False
            ],
            [
                u('part'), u(''), False
            ],
            [
                u('part'), u('part'), True
            ],
            [
                u('part'), BasePath(u('part')), True
            ],
            [
                BasePath(u('part')), u('part'), True
            ],
            [
                BasePath(u('part')), BasePath(u('part')), True
            ],
        )
    )
    def test_parts(self, part1, part2, expected):
        result = BasePath(part1) == BasePath(part2)

        assert result is expected
Пример #2
0
    def test_part_path(self):
        part = u('part')
        p1 = BasePath(part)
        p = BasePath(p1)

        assert p.parts == [part, ]
        assert p.separator == SEPARATOR
Пример #3
0
    def test_part_path_many(self):
        part1 = u('part1')
        part2 = u('part2')
        p1 = BasePath(part1)
        p2 = BasePath(part2)
        p = BasePath(p1, p2)

        assert p.parts == [part1, part2]
        assert p.separator == SEPARATOR
Пример #4
0
    def test_combined_different_separators(self):
        part11 = u('part11')
        part12 = u('part12')
        part21 = u('part21')
        part22 = u('part22')
        separator1 = '.'
        part1 = SEPARATOR.join([part11, part12])
        part2 = SEPARATOR.join([part21, part22])
        p1 = BasePath(part2)
        p = BasePath(part1, separator=separator1) / p1

        assert p.parts == [part11, part12, part21, part22]
        assert p.separator == separator1
Пример #5
0
    def test_part_binary_many(self):
        part1 = b('part1')
        part2 = b('part2')
        p = BasePath(part1, part2)

        assert p.parts == [u('part1'), u('part2')]
        assert p.separator == SEPARATOR
Пример #6
0
    def test_parts_unparsed(self):
        parts = [u('part1'), u('part2')]
        part = SEPARATOR.join(parts)
        p = BasePath._from_parts([part])

        assert p.parts == parts
        assert p.separator == SEPARATOR
Пример #7
0
    def test_parts_unparsed(self):
        part = SEPARATOR.join(['part1', 'part2'])
        parts = [part]
        p = BasePath._from_parsed_parts(parts)

        assert p.parts == parts
        assert p.separator == SEPARATOR
Пример #8
0
    def test_separator(self):
        parts = []
        separator = '.'
        p = BasePath._from_parsed_parts(
            parts, separator=separator)

        assert p.parts == parts
        assert p.separator == separator
Пример #9
0
    def test_combined(self):
        part11 = u('part11')
        part12 = u('part12')
        part21 = u('part21')
        part22 = u('part22')
        part1 = SEPARATOR.join([part11, part12])
        part2 = SEPARATOR.join([part21, part22])
        p = part1 / BasePath(part2)

        assert p.parts == [part11, part12, part21, part22]
        assert p.separator == SEPARATOR
Пример #10
0
    def test_parts(self, part1, part2, expected):
        result = BasePath(part1) == BasePath(part2)

        assert result is expected
Пример #11
0
    def test_default(self):
        p = BasePath()

        assert p.parts == []
        assert p.separator == SEPARATOR
Пример #12
0
    def test_separator(self):
        separator = '.'
        p = BasePath(separator=separator)

        assert p.parts == []
        assert p.separator == separator
Пример #13
0
    def test_part_binary(self):
        part = b('part')
        p = BasePath(part)

        assert p.parts == [u('part'), ]
        assert p.separator == SEPARATOR
Пример #14
0
class TestBasePathTruediv(object):

    def test_default_empty(self):
        p = BasePath() / u('')

        assert p.parts == []
        assert p.separator == SEPARATOR

    @pytest.mark.parametrize(
        'part1,part2,parts,separator',
        (
            [
                u(''), u(''),
                [], SEPARATOR,
            ],
            [
                u(''), u('part1'),
                ['part1'], SEPARATOR,
            ],
            [
                u('part1'), u(''),
                ['part1'], SEPARATOR,
            ],
            [
                u('part1'), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                b(''), u(''),
                [], SEPARATOR,
            ],
            [
                b(''), u('part1'),
                ['part1'], SEPARATOR,
            ],
            [
                b('part1'), u(''),
                ['part1'], SEPARATOR,
            ],
            [
                b('part1'), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                u('part1'), BasePath(u('part2')),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                BasePath(u('part1')), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                BasePath(u('part1')), BasePath(u('part2')),
                ['part1', 'part2'], SEPARATOR,
            ],
        )
    )
    def test_parts(self, part1, part2, parts, separator):
        p = BasePath(part1) / part2

        assert p.parts == parts
        assert p.separator == separator

    def test_combined(self):
        part11 = u('part11')
        part12 = u('part12')
        part21 = u('part21')
        part22 = u('part22')
        part1 = SEPARATOR.join([part11, part12])
        part2 = SEPARATOR.join([part21, part22])
        p = BasePath(part1) / part2

        assert p.parts == [part11, part12, part21, part22]
        assert p.separator == SEPARATOR

    def test_combined_different_separators(self):
        part11 = u('part11')
        part12 = u('part12')
        part21 = u('part21')
        part22 = u('part22')
        separator1 = '.'
        part1 = SEPARATOR.join([part11, part12])
        part2 = SEPARATOR.join([part21, part22])
        p1 = BasePath(part2)
        p = BasePath(part1, separator=separator1) / p1

        assert p.parts == [part11, part12, part21, part22]
        assert p.separator == separator1
Пример #15
0
    def test_parts_many(self):
        parts = ['part1', 'part2']
        p = BasePath._from_parsed_parts(parts)

        assert p.parts == parts
        assert p.separator == SEPARATOR
Пример #16
0
class TestBasePathRtruediv(object):

    def test_default_empty(self):
        p = u('') / BasePath()

        assert p.parts == []
        assert p.separator == SEPARATOR

    @pytest.mark.parametrize(
        'part1,part2,parts,separator',
        (
            [
                u(''), u(''),
                [], SEPARATOR,
            ],
            [
                u(''), u('part1'),
                ['part1'], SEPARATOR,
            ],
            [
                u('part1'), u(''),
                ['part1'], SEPARATOR,
            ],
            [
                u('part1'), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                b(''), u(''),
                [], SEPARATOR,
            ],
            [
                b(''), u('part1'),
                ['part1'], SEPARATOR,
            ],
            [
                b('part1'), u(''),
                ['part1'], SEPARATOR,
            ],
            [
                b('part1'), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                u('part1'), BasePath(u('part2')),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                BasePath(u('part1')), u('part2'),
                ['part1', 'part2'], SEPARATOR,
            ],
            [
                BasePath(u('part1')), BasePath(u('part2')),
                ['part1', 'part2'], SEPARATOR,
            ],
        )
    )
    def test_parts(self, part1, part2, parts, separator):
        p = part1 / BasePath(part2)

        assert p.parts == parts
        assert p.separator == separator

    def test_combined(self):
        part11 = u('part11')
        part12 = u('part12')
        part21 = u('part21')
        part22 = u('part22')
        part1 = SEPARATOR.join([part11, part12])
        part2 = SEPARATOR.join([part21, part22])
        p = part1 / BasePath(part2)

        assert p.parts == [part11, part12, part21, part22]
        assert p.separator == SEPARATOR
Пример #17
0
    def test_default_empty(self):
        p = u('') / BasePath()

        assert p.parts == []
        assert p.separator == SEPARATOR
Пример #18
0
    def test_default(self):
        parts = []
        p = BasePath._from_parts(parts)

        assert p.parts == parts
        assert p.separator == SEPARATOR
Пример #19
0
    def test_parts(self, part1, part2, parts, separator):
        p = part1 / BasePath(part2)

        assert p.parts == parts
        assert p.separator == separator
Пример #20
0
    def test_parts_many(self):
        parts = [u('part1'), u('part2')]
        p = BasePath._from_parts(parts)

        assert p.parts == parts
        assert p.separator == SEPARATOR
Пример #21
0
    def test_path(self):
        args = [BasePath(u('test'))]

        result = parse_args(args, self.separator)

        assert result == ['test']