|
| 1 | +from typing import Callable, Dict, List |
| 2 | + |
| 3 | +import pytest |
| 4 | +import ulist as ul |
| 5 | +from ulist.utils import check_test_result |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.parametrize( |
| 9 | + "test_method, args, kwargs, expected_value", |
| 10 | + [ |
| 11 | + (ul.read_csv, (), { |
| 12 | + "path": "./test_csv/00_test_int.csv", |
| 13 | + "schema": {"int32": "int32", "int64": "int64"} |
| 14 | + }, { |
| 15 | + "int32": [-2147483648, 2147483647, +2147483647], |
| 16 | + "int64": [-9223372036854774808, |
| 17 | + 9223372036854774807, |
| 18 | + +9223372036854774807], |
| 19 | + }), |
| 20 | + (ul.read_csv, (), { |
| 21 | + "path": "./test_csv/01_test_float.csv", |
| 22 | + "schema": {"float32": "float32", "float64": "float64"} |
| 23 | + }, { |
| 24 | + # Precision problem in float32 |
| 25 | + "float32": [3.14159, 0.314, 0.314], |
| 26 | + "float64": [3.14159, 31.4, 31.4] |
| 27 | + }), |
| 28 | + (ul.read_csv, (), { |
| 29 | + "path": "./test_csv/02_test_bool.csv", |
| 30 | + "schema": {"bool": "bool"} |
| 31 | + }, { |
| 32 | + "bool": [True, False, True, False] |
| 33 | + }), |
| 34 | + (ul.read_csv, (), { |
| 35 | + "path": "./test_csv/03_test_string.csv", |
| 36 | + "schema": {"string": "string"} |
| 37 | + }, { |
| 38 | + "string": ["String", 'Hello, "World"', None, "Long\nString"] |
| 39 | + }), |
| 40 | + (ul.read_csv, (), { |
| 41 | + "path": "./test_csv/04_test_nan.csv", |
| 42 | + "schema": {"int": "int", |
| 43 | + "float": "float", |
| 44 | + "string": "string", |
| 45 | + "bool": "bool"} |
| 46 | + }, { |
| 47 | + "int": [None, 2, 3, 4], |
| 48 | + "float": [1.0, None, 3.0, 4.0], |
| 49 | + "string": ["1", "2", None, "4"], |
| 50 | + "bool": [True, False, True, None] |
| 51 | + }), |
| 52 | + (ul.read_csv, (), { # schema.len() < field.len() |
| 53 | + "path": "./test_csv/04_test_nan.csv", |
| 54 | + "schema": {"int": "int", |
| 55 | + "bool": "bool"} |
| 56 | + }, { |
| 57 | + "int": [None, 2, 3, 4], |
| 58 | + "bool": [True, False, True, None] |
| 59 | + }), |
| 60 | + (ul.read_csv, (), { # schema.len() > field.len() |
| 61 | + "path": "./test_csv/02_test_bool.csv", |
| 62 | + "schema": {"foo": "int", |
| 63 | + "bar": "bool", |
| 64 | + "bool": "bool"} |
| 65 | + }, { |
| 66 | + "foo": [], |
| 67 | + "bar": [], |
| 68 | + "bool": [True, False, True, False] |
| 69 | + }) |
| 70 | + ], |
| 71 | +) |
| 72 | +def test_constructors( |
| 73 | + test_method: Callable, |
| 74 | + args: tuple, |
| 75 | + kwargs: dict, |
| 76 | + expected_value: Dict[str, List] |
| 77 | +) -> None: |
| 78 | + result = test_method(*args, **kwargs) |
| 79 | + check_test_result(kwargs["path"], test_method, result, expected_value) |
0 commit comments