|
33 | 33 | ] |
34 | 34 |
|
35 | 35 |
|
| 36 | +# ======================================================== |
| 37 | +# _get_best_matching_type() tests |
| 38 | +# ======================================================== |
| 39 | +@pytest.mark.parametrize( |
| 40 | + "python_object, expected_type_string", |
| 41 | + [ |
| 42 | + (False, "bool"), |
| 43 | + (b"mystr", "bytes"), |
| 44 | + (456.2, "float"), |
| 45 | + (123, "int"), |
| 46 | + ("mystr", "str"), |
| 47 | + ([False, False], "Collection.bool"), |
| 48 | + ([b"mystr", b"mystr"], "Collection.bytes"), |
| 49 | + ([456.2, 1.0], "Collection.float"), |
| 50 | + ([123, 456], "Collection.int"), |
| 51 | + (["mystr", "mystr"], "Collection.str"), |
| 52 | + ((False, False), "Collection.bool"), |
| 53 | + ((b"mystr", b"mystr"), "Collection.bytes"), |
| 54 | + ((456.2, 1.0), "Collection.float"), |
| 55 | + ((123, 456), "Collection.int"), |
| 56 | + (("mystr", "mystr"), "Collection.str"), |
| 57 | + ((False, False), "Collection.bool"), |
| 58 | + ((b"mystr", b"mystr"), "Collection.bytes"), |
| 59 | + ((456.2, 1.0), "Collection.float"), |
| 60 | + ((123, 456), "Collection.int"), |
| 61 | + (("mystr", "mystr"), "Collection.str"), |
| 62 | + (set([False, True]), "Collection.bool"), |
| 63 | + (set([b"mystr", b"mystr2"]), "Collection.bytes"), |
| 64 | + (set([456.2, 1.0]), "Collection.float"), |
| 65 | + (set([123, 456]), "Collection.int"), |
| 66 | + (set(["mystr", "mystr2"]), "Collection.str"), |
| 67 | + (frozenset([False, True]), "Collection.bool"), |
| 68 | + (frozenset([b"mystr", b"mystr2"]), "Collection.bytes"), |
| 69 | + (frozenset([456.2, 1.0]), "Collection.float"), |
| 70 | + (frozenset([123, 456]), "Collection.int"), |
| 71 | + (frozenset(["mystr", "mystr2"]), "Collection.str"), |
| 72 | + ], |
| 73 | +) |
| 74 | +def test___various_python_objects___get_best_matching_type___returns_correct_type_string( |
| 75 | + python_object: object, expected_type_string: str |
| 76 | +) -> None: |
| 77 | + type_string = nipanel._convert._get_best_matching_type(python_object) |
| 78 | + assert type_string == expected_type_string |
| 79 | + |
| 80 | + |
36 | 81 | # ======================================================== |
37 | 82 | # Built-in Types: Python to Protobuf |
38 | 83 | # ======================================================== |
|
0 commit comments