datarepr 1.2.6__tar.gz → 1.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datarepr-1.2.8/MANIFEST.in +3 -0
- {datarepr-1.2.6/src/datarepr.egg-info → datarepr-1.2.8}/PKG-INFO +1 -1
- {datarepr-1.2.6 → datarepr-1.2.8}/pyproject.toml +1 -1
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr/__init__.py +1 -1
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr/core.py +1 -1
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr/tests/__init__.py +1 -1
- datarepr-1.2.8/src/datarepr/tests/test_0.py +114 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr/tests/test_oxford.py +2 -2
- datarepr-1.2.8/src/datarepr/tests/testdata.toml +58 -0
- {datarepr-1.2.6 → datarepr-1.2.8/src/datarepr.egg-info}/PKG-INFO +1 -1
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr.egg-info/SOURCES.txt +2 -1
- datarepr-1.2.6/MANIFEST.in +0 -2
- datarepr-1.2.6/src/datarepr/tests/test_0.py +0 -130
- {datarepr-1.2.6 → datarepr-1.2.8}/LICENSE.txt +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/README.rst +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/docs/v1.0.rst +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/docs/v1.1.rst +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/docs/v1.2.rst +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/setup.cfg +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr/py.typed +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr.egg-info/dependency_links.txt +0 -0
- {datarepr-1.2.6 → datarepr-1.2.8}/src/datarepr.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Test the datarepr function."""
|
|
2
|
+
|
|
3
|
+
__all__: list[str] = ["TestDatareprFunction"]
|
|
4
|
+
|
|
5
|
+
import enum
|
|
6
|
+
import io
|
|
7
|
+
import tomllib
|
|
8
|
+
import unittest
|
|
9
|
+
from collections.abc import Sequence
|
|
10
|
+
from functools import cached_property
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Self, cast
|
|
13
|
+
|
|
14
|
+
from datarepr.core import datarepr
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Lazy(enum.Enum):
|
|
18
|
+
lazy = None
|
|
19
|
+
|
|
20
|
+
@cached_property
|
|
21
|
+
def data(self: Self, /) -> dict[str, Any]:
|
|
22
|
+
file: Path
|
|
23
|
+
stream: io.BufferedReader
|
|
24
|
+
file = Path(__file__).parent / "testdata.toml"
|
|
25
|
+
with file.open("rb") as stream:
|
|
26
|
+
return tomllib.load(stream)
|
|
27
|
+
|
|
28
|
+
@cached_property
|
|
29
|
+
def test_0(self: Self, /) -> dict[str, Any]:
|
|
30
|
+
return cast(dict[str, Any], self.lazy.data["test_0"])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TestDatareprFunction(unittest.TestCase):
|
|
34
|
+
"""Test the datarepr function comprehensively."""
|
|
35
|
+
|
|
36
|
+
def go_valid(
|
|
37
|
+
self: Self,
|
|
38
|
+
name: str,
|
|
39
|
+
/,
|
|
40
|
+
*,
|
|
41
|
+
args: Sequence[Any],
|
|
42
|
+
kwargs: Any = (),
|
|
43
|
+
solution: str,
|
|
44
|
+
) -> None:
|
|
45
|
+
"""Test the datarepr function with valid parameters."""
|
|
46
|
+
result: str
|
|
47
|
+
with self.subTest(name):
|
|
48
|
+
result = datarepr(*args, **dict(kwargs))
|
|
49
|
+
self.assertEqual(result, solution)
|
|
50
|
+
|
|
51
|
+
def test_0(self: Self, /) -> None:
|
|
52
|
+
"""Test the testdata."""
|
|
53
|
+
x: Any
|
|
54
|
+
y: Any
|
|
55
|
+
for x, y in Lazy.lazy.test_0.items():
|
|
56
|
+
self.go_valid(x, **y)
|
|
57
|
+
|
|
58
|
+
def test_combination_of_all(self: Self, /) -> None:
|
|
59
|
+
"""Test a complex combination of types and structures."""
|
|
60
|
+
result: str
|
|
61
|
+
solution: str
|
|
62
|
+
result = datarepr(
|
|
63
|
+
"complex_function",
|
|
64
|
+
[1, 2],
|
|
65
|
+
{3: 4},
|
|
66
|
+
a=5,
|
|
67
|
+
b=[6, 7],
|
|
68
|
+
c={"key": "value"},
|
|
69
|
+
)
|
|
70
|
+
solution = (
|
|
71
|
+
"complex_function([1, 2], {3: 4}, a=5,"
|
|
72
|
+
" b=[6, 7], c={'key': 'value'})"
|
|
73
|
+
)
|
|
74
|
+
self.assertEqual(result, solution)
|
|
75
|
+
|
|
76
|
+
def test_name_as_non_string(self: Self, /) -> None:
|
|
77
|
+
"""Test with the 'name' parameter as a non-string type."""
|
|
78
|
+
result: str
|
|
79
|
+
result = datarepr(None, "arg1")
|
|
80
|
+
self.assertEqual(result, "None('arg1')")
|
|
81
|
+
|
|
82
|
+
def test_no_args_at_all(self: Self, /) -> None:
|
|
83
|
+
"""Test with no arguments, not even the name."""
|
|
84
|
+
args: Any
|
|
85
|
+
args = ()
|
|
86
|
+
with self.assertRaises(TypeError):
|
|
87
|
+
# Raise TypeError: missing required 'name' argument.
|
|
88
|
+
datarepr(*args)
|
|
89
|
+
|
|
90
|
+
def test_special_characters(self: Self, /) -> None:
|
|
91
|
+
"""Test with special characters in arguments."""
|
|
92
|
+
result: str
|
|
93
|
+
result = datarepr("test_function", "a\nb", "\t", key="val\nue")
|
|
94
|
+
self.assertEqual(
|
|
95
|
+
result, "test_function('a\\nb', '\\t', key='val\\nue')"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
def test_various_types(self: Self, /) -> None:
|
|
99
|
+
"""Test with various types of arguments."""
|
|
100
|
+
result: str
|
|
101
|
+
result = datarepr("test_function", 1, 2.0, True, None)
|
|
102
|
+
self.assertEqual(result, "test_function(1, 2.0, True, None)")
|
|
103
|
+
result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
|
|
104
|
+
self.assertEqual(
|
|
105
|
+
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
106
|
+
)
|
|
107
|
+
result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
|
|
108
|
+
self.assertEqual(
|
|
109
|
+
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
if __name__ == "__main__":
|
|
114
|
+
unittest.main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Test the oxford function."""
|
|
2
2
|
|
|
3
|
-
__all__ = ["TestOxfordFunction"]
|
|
3
|
+
__all__: list[str] = ["TestOxfordFunction"]
|
|
4
4
|
|
|
5
5
|
import unittest
|
|
6
6
|
from typing import Self
|
|
@@ -11,7 +11,7 @@ from datarepr.core import oxford
|
|
|
11
11
|
class TestOxfordFunction(unittest.TestCase):
|
|
12
12
|
"""Test the oxford function comprehensively."""
|
|
13
13
|
|
|
14
|
-
def test_no_args_at_all(self: Self) -> None:
|
|
14
|
+
def test_no_args_at_all(self: Self, /) -> None:
|
|
15
15
|
"""Test oxford with varying numbers of arguments."""
|
|
16
16
|
self.assertEqual("", oxford())
|
|
17
17
|
self.assertEqual(42, oxford(default=42))
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[test_0.test_empty_args_kwargs]
|
|
2
|
+
args=["test_function"]
|
|
3
|
+
solution = "test_function()"
|
|
4
|
+
|
|
5
|
+
[test_0.test_empty_name]
|
|
6
|
+
args = ["", 1, 2]
|
|
7
|
+
kwargs = { a=3}
|
|
8
|
+
solution = "(1, 2, a=3)"
|
|
9
|
+
|
|
10
|
+
[test_0.test_large_number_of_args]
|
|
11
|
+
args = ["test_function", 0, 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]
|
|
12
|
+
solution='test_function(0, 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)'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[test_0.test_positional_args_only]
|
|
16
|
+
args=["test_function", 1, 2, 3]
|
|
17
|
+
solution = "test_function(1, 2, 3)"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
[test_0.test_keyword_args_only_1]
|
|
22
|
+
args=["test_function"]
|
|
23
|
+
kwargs = { x="x", y="y"}
|
|
24
|
+
solution="test_function(x='x', y='y')"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
[test_0.test_positional_args_only_1]
|
|
29
|
+
args = ["test_function", "a", "b", "c"]
|
|
30
|
+
solution="test_function('a', 'b', 'c')"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
[test_0.test_mixed_args]
|
|
34
|
+
args = ["test_function", 1, 2]
|
|
35
|
+
kwargs = {a=3, b=4}
|
|
36
|
+
solution = "test_function(1, 2, a=3, b=4)"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
[test_0.test_mixed_args_1]
|
|
42
|
+
|
|
43
|
+
args = ["test_function", "x", "y"]
|
|
44
|
+
kwargs={ z=5}
|
|
45
|
+
solution="test_function('x', 'y', z=5)"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
[test_0.test_keyword_args_only]
|
|
51
|
+
args=["test_function"]
|
|
52
|
+
kwargs={ a=1, b=2, c=3}
|
|
53
|
+
solution="test_function(a=1, b=2, c=3)"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
[test_0.test_name_as_non_string]
|
|
57
|
+
args=[123, "arg1"]
|
|
58
|
+
solution="123('arg1')"
|
datarepr-1.2.6/MANIFEST.in
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"""Test the datarepr function."""
|
|
2
|
-
|
|
3
|
-
__all__ = ["TestDatareprFunction"]
|
|
4
|
-
|
|
5
|
-
import unittest
|
|
6
|
-
from typing import Any, Self
|
|
7
|
-
|
|
8
|
-
from datarepr.core import datarepr
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestDatareprFunction(unittest.TestCase):
|
|
12
|
-
"""Test the datarepr function comprehensively."""
|
|
13
|
-
|
|
14
|
-
def test_combination_of_all(self: Self) -> None:
|
|
15
|
-
"""Test a complex combination of types and structures."""
|
|
16
|
-
expected: str
|
|
17
|
-
result: str
|
|
18
|
-
result = datarepr(
|
|
19
|
-
"complex_function",
|
|
20
|
-
[1, 2],
|
|
21
|
-
{3: 4},
|
|
22
|
-
a=5,
|
|
23
|
-
b=[6, 7],
|
|
24
|
-
c={"key": "value"},
|
|
25
|
-
)
|
|
26
|
-
expected = (
|
|
27
|
-
"complex_function([1, 2], {3: 4}, a=5,"
|
|
28
|
-
" b=[6, 7], c={'key': 'value'})"
|
|
29
|
-
)
|
|
30
|
-
self.assertEqual(result, expected)
|
|
31
|
-
|
|
32
|
-
def test_empty_args_kwargs(self: Self) -> None:
|
|
33
|
-
"""Test when only the name is provided and no args or kwargs."""
|
|
34
|
-
result: str
|
|
35
|
-
result = datarepr("test_function")
|
|
36
|
-
self.assertEqual(result, "test_function()")
|
|
37
|
-
|
|
38
|
-
def test_empty_name(self: Self) -> None:
|
|
39
|
-
"""Test with an empty name."""
|
|
40
|
-
result: str
|
|
41
|
-
result = datarepr("", 1, 2, a=3)
|
|
42
|
-
self.assertEqual(result, "(1, 2, a=3)")
|
|
43
|
-
|
|
44
|
-
def test_keyword_args_only(self: Self) -> None:
|
|
45
|
-
"""Test with keyword arguments only."""
|
|
46
|
-
result: str
|
|
47
|
-
result = datarepr("test_function", a=1, b=2, c=3)
|
|
48
|
-
self.assertEqual(result, "test_function(a=1, b=2, c=3)")
|
|
49
|
-
|
|
50
|
-
def test_keyword_args_only_1(self: Self) -> None:
|
|
51
|
-
"""Test with string keyword arguments."""
|
|
52
|
-
result: str
|
|
53
|
-
result = datarepr("test_function", x="x", y="y")
|
|
54
|
-
self.assertEqual(result, "test_function(x='x', y='y')")
|
|
55
|
-
|
|
56
|
-
def test_large_number_of_args(self: Self) -> None:
|
|
57
|
-
"""Test with a large number of arguments."""
|
|
58
|
-
args: range
|
|
59
|
-
expected: str
|
|
60
|
-
result: str
|
|
61
|
-
args = range(100)
|
|
62
|
-
result = datarepr("test_function", *args)
|
|
63
|
-
expected = "test_function(" + ", ".join(map(str, args)) + ")"
|
|
64
|
-
self.assertEqual(result, expected)
|
|
65
|
-
|
|
66
|
-
def test_mixed_args(self: Self) -> None:
|
|
67
|
-
"""Test with both positional and keyword arguments."""
|
|
68
|
-
result: str
|
|
69
|
-
result = datarepr("test_function", 1, 2, a=3, b=4)
|
|
70
|
-
self.assertEqual(result, "test_function(1, 2, a=3, b=4)")
|
|
71
|
-
|
|
72
|
-
def test_mixed_args_1(self: Self) -> None:
|
|
73
|
-
"""Test with string positional and int keyword arguments."""
|
|
74
|
-
result: str
|
|
75
|
-
result = datarepr("test_function", "x", "y", z=5)
|
|
76
|
-
self.assertEqual(result, "test_function('x', 'y', z=5)")
|
|
77
|
-
|
|
78
|
-
def test_name_as_non_string(self: Self) -> None:
|
|
79
|
-
"""Test with the 'name' parameter as a non-string type."""
|
|
80
|
-
result: str
|
|
81
|
-
result = datarepr(123, "arg1")
|
|
82
|
-
self.assertEqual(result, "123('arg1')")
|
|
83
|
-
result = datarepr(None, "arg1")
|
|
84
|
-
self.assertEqual(result, "None('arg1')")
|
|
85
|
-
|
|
86
|
-
def test_no_args_at_all(self: Self) -> None:
|
|
87
|
-
"""Test with no arguments, not even the name."""
|
|
88
|
-
args: Any
|
|
89
|
-
args = ()
|
|
90
|
-
with self.assertRaises(TypeError):
|
|
91
|
-
# Raise TypeError: missing required 'name' argument.
|
|
92
|
-
datarepr(*args)
|
|
93
|
-
|
|
94
|
-
def test_positional_args_only(self: Self) -> None:
|
|
95
|
-
"""Test with positional arguments only."""
|
|
96
|
-
result: str
|
|
97
|
-
result = datarepr("test_function", 1, 2, 3)
|
|
98
|
-
self.assertEqual(result, "test_function(1, 2, 3)")
|
|
99
|
-
|
|
100
|
-
def test_positional_args_only_1(self: Self) -> None:
|
|
101
|
-
"""Test with string positional arguments."""
|
|
102
|
-
result: str
|
|
103
|
-
result = datarepr("test_function", "a", "b", "c")
|
|
104
|
-
self.assertEqual(result, "test_function('a', 'b', 'c')")
|
|
105
|
-
|
|
106
|
-
def test_special_characters(self: Self) -> None:
|
|
107
|
-
"""Test with special characters in arguments."""
|
|
108
|
-
result: str
|
|
109
|
-
result = datarepr("test_function", "a\nb", "\t", key="val\nue")
|
|
110
|
-
self.assertEqual(
|
|
111
|
-
result, "test_function('a\\nb', '\\t', key='val\\nue')"
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
def test_various_types(self: Self) -> None:
|
|
115
|
-
"""Test with various types of arguments."""
|
|
116
|
-
result: str
|
|
117
|
-
result = datarepr("test_function", 1, 2.0, True, None)
|
|
118
|
-
self.assertEqual(result, "test_function(1, 2.0, True, None)")
|
|
119
|
-
result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
|
|
120
|
-
self.assertEqual(
|
|
121
|
-
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
122
|
-
)
|
|
123
|
-
result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
|
|
124
|
-
self.assertEqual(
|
|
125
|
-
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if __name__ == "__main__":
|
|
130
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|