File: test_remarshal.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (95 lines) | stat: -rw-r--r-- 2,406 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
import collections.abc
import uuid

import pytest

from globus_sdk import MISSING
from globus_sdk._internal.remarshal import (
    commajoin,
    list_map,
    listify,
    strseq_iter,
    strseq_listify,
)


@pytest.mark.parametrize(
    "value, expected_result",
    (
        ("foo", ["foo"]),
        ((1, 2, 3), ["1", "2", "3"]),
        (uuid.UUID(int=10), [f"{uuid.UUID(int=10)}"]),
        (["foo", uuid.UUID(int=5)], ["foo", f"{uuid.UUID(int=5)}"]),
    ),
)
def test_strseq_iter(value, expected_result):
    iter_ = strseq_iter(value)
    assert not isinstance(iter_, list)
    assert isinstance(iter_, collections.abc.Iterator)
    assert list(iter_) == expected_result
    assert list(iter_) == []


@pytest.mark.parametrize(
    "value, expected_result",
    (
        ("foo", ["foo"]),
        ((1, 2, 3), ["1", "2", "3"]),
        (uuid.UUID(int=10), [f"{uuid.UUID(int=10)}"]),
        (["foo", uuid.UUID(int=5)], ["foo", f"{uuid.UUID(int=5)}"]),
        (MISSING, MISSING),
        (None, None),
    ),
)
def test_strseq_listify(value, expected_result):
    list_ = strseq_listify(value)
    assert isinstance(list_, list) or list_ in (MISSING, None)
    assert list_ == expected_result


@pytest.mark.parametrize(
    "value, expected_result",
    (
        ("foo", "foo"),
        (uuid.UUID(int=10), f"{uuid.UUID(int=10)}"),
        ((1, 2, 3), "1,2,3"),
        (range(5), "0,1,2,3,4"),
        (["foo", uuid.UUID(int=5)], f"foo,{uuid.UUID(int=5)}"),
        (MISSING, MISSING),
        (None, None),
    ),
)
def test_commajoin(value, expected_result):
    joined = commajoin(value)
    assert joined == expected_result


@pytest.mark.parametrize(
    "value, expected_result",
    (
        ("foo", ["f", "o", "o"]),
        ((1, 2, 3), [1, 2, 3]),
        (range(5), [0, 1, 2, 3, 4]),
        (["foo", uuid.UUID(int=5)], ["foo", uuid.UUID(int=5)]),
        (MISSING, MISSING),
        (None, None),
    ),
)
def test_listify(value, expected_result):
    converted = listify(value)
    assert converted == expected_result


@pytest.mark.parametrize(
    "value, expected_result",
    (
        ("foo", ["ff", "oo", "oo"]),
        ((1, 2, 3), [2, 4, 6]),
        (range(5), [0, 2, 4, 6, 8]),
        (MISSING, MISSING),
        (None, None),
    ),
)
def test_list_map(value, expected_result):
    converted = list_map(value, lambda x: x * 2)
    assert converted == expected_result