datarepr 1.2.4__tar.gz → 1.2.5__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.4/src/datarepr.egg-info → datarepr-1.2.5}/PKG-INFO +1 -1
- {datarepr-1.2.4 → datarepr-1.2.5}/pyproject.toml +1 -1
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/__init__.py +3 -1
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/core.py +5 -2
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/tests/__init__.py +4 -1
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/tests/test_0.py +68 -61
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/tests/test_oxford.py +7 -2
- {datarepr-1.2.4 → datarepr-1.2.5/src/datarepr.egg-info}/PKG-INFO +1 -1
- {datarepr-1.2.4 → datarepr-1.2.5}/LICENSE.txt +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/MANIFEST.in +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/README.rst +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/docs/v1.0.rst +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/docs/v1.1.rst +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/docs/v1.2.rst +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/setup.cfg +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr/py.typed +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr.egg-info/SOURCES.txt +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr.egg-info/dependency_links.txt +0 -0
- {datarepr-1.2.4 → datarepr-1.2.5}/src/datarepr.egg-info/top_level.txt +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
"""Provide core data representation utilities."""
|
|
2
2
|
|
|
3
3
|
__all__ = ["datarepr", "oxford"]
|
|
4
4
|
|
|
5
|
+
from typing import TypeVar
|
|
6
|
+
|
|
5
7
|
Default = TypeVar("Default")
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
def datarepr(name: object, /, *args: object, **kwargs: object) -> str:
|
|
9
|
-
"
|
|
11
|
+
"""Return a common-sense string representation."""
|
|
10
12
|
content: str
|
|
11
13
|
item: tuple[str, object]
|
|
12
14
|
parts: list[str]
|
|
@@ -22,6 +24,7 @@ def oxford(
|
|
|
22
24
|
conj: object = "and",
|
|
23
25
|
default: Default | str = "",
|
|
24
26
|
) -> Default | str:
|
|
27
|
+
"""Return repr values joined with an Oxford comma."""
|
|
25
28
|
if len(args) == 0:
|
|
26
29
|
return default
|
|
27
30
|
if len(args) == 1:
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"""Provide test utilities for the datarepr package."""
|
|
2
2
|
|
|
3
3
|
__all__ = ["test"]
|
|
4
4
|
|
|
5
|
+
import unittest
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
def test() -> unittest.TextTestResult:
|
|
9
|
+
"""Run all tests and return the result."""
|
|
7
10
|
suite: unittest.TestSuite
|
|
8
11
|
suite = unittest.TestLoader().discover(start_dir="datarepr.tests")
|
|
9
12
|
return unittest.TextTestRunner().run(suite)
|
|
@@ -1,119 +1,126 @@
|
|
|
1
|
+
"""Test the datarepr function."""
|
|
2
|
+
|
|
3
|
+
__all__ = ["TestDatareprFunction"]
|
|
4
|
+
|
|
1
5
|
import unittest
|
|
2
6
|
from typing import Any, Self
|
|
3
7
|
|
|
4
8
|
from datarepr.core import datarepr
|
|
5
9
|
|
|
6
|
-
__all__ = ["TestDatareprFunction"]
|
|
7
|
-
|
|
8
10
|
|
|
9
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)
|
|
10
31
|
|
|
11
32
|
def test_empty_args_kwargs(self: Self) -> None:
|
|
12
|
-
"
|
|
33
|
+
"""Test when only the name is provided and no args or kwargs."""
|
|
13
34
|
result: str
|
|
14
35
|
result = datarepr("test_function")
|
|
15
36
|
self.assertEqual(result, "test_function()")
|
|
16
37
|
|
|
17
|
-
def
|
|
18
|
-
"
|
|
19
|
-
result: str
|
|
20
|
-
result = datarepr("test_function", 1, 2, 3)
|
|
21
|
-
self.assertEqual(result, "test_function(1, 2, 3)")
|
|
22
|
-
|
|
23
|
-
def test_positional_args_only_1(self: Self) -> None:
|
|
38
|
+
def test_empty_name(self: Self) -> None:
|
|
39
|
+
"""Test with an empty name."""
|
|
24
40
|
result: str
|
|
25
|
-
result = datarepr("
|
|
26
|
-
self.assertEqual(result, "
|
|
41
|
+
result = datarepr("", 1, 2, a=3)
|
|
42
|
+
self.assertEqual(result, "(1, 2, a=3)")
|
|
27
43
|
|
|
28
44
|
def test_keyword_args_only(self: Self) -> None:
|
|
29
|
-
"
|
|
45
|
+
"""Test with keyword arguments only."""
|
|
30
46
|
result: str
|
|
31
47
|
result = datarepr("test_function", a=1, b=2, c=3)
|
|
32
48
|
self.assertEqual(result, "test_function(a=1, b=2, c=3)")
|
|
33
49
|
|
|
34
50
|
def test_keyword_args_only_1(self: Self) -> None:
|
|
51
|
+
"""Test with string keyword arguments."""
|
|
35
52
|
result: str
|
|
36
53
|
result = datarepr("test_function", x="x", y="y")
|
|
37
54
|
self.assertEqual(result, "test_function(x='x', y='y')")
|
|
38
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
|
+
|
|
39
66
|
def test_mixed_args(self: Self) -> None:
|
|
40
|
-
"
|
|
67
|
+
"""Test with both positional and keyword arguments."""
|
|
41
68
|
result: str
|
|
42
69
|
result = datarepr("test_function", 1, 2, a=3, b=4)
|
|
43
70
|
self.assertEqual(result, "test_function(1, 2, a=3, b=4)")
|
|
44
71
|
|
|
45
72
|
def test_mixed_args_1(self: Self) -> None:
|
|
73
|
+
"""Test with string positional and int keyword arguments."""
|
|
46
74
|
result: str
|
|
47
75
|
result = datarepr("test_function", "x", "y", z=5)
|
|
48
76
|
self.assertEqual(result, "test_function('x', 'y', z=5)")
|
|
49
77
|
|
|
50
|
-
def test_various_types(self: Self) -> None:
|
|
51
|
-
"This test tests with various types of arguments."
|
|
52
|
-
result: str
|
|
53
|
-
result = datarepr("test_function", 1, 2.0, True, None)
|
|
54
|
-
self.assertEqual(result, "test_function(1, 2.0, True, None)")
|
|
55
|
-
result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
|
|
56
|
-
self.assertEqual(
|
|
57
|
-
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
58
|
-
)
|
|
59
|
-
|
|
60
78
|
def test_name_as_non_string(self: Self) -> None:
|
|
61
|
-
"
|
|
79
|
+
"""Test with the 'name' parameter as a non-string type."""
|
|
62
80
|
result: str
|
|
63
81
|
result = datarepr(123, "arg1")
|
|
64
82
|
self.assertEqual(result, "123('arg1')")
|
|
65
83
|
result = datarepr(None, "arg1")
|
|
66
84
|
self.assertEqual(result, "None('arg1')")
|
|
67
85
|
|
|
68
|
-
def
|
|
69
|
-
"
|
|
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."""
|
|
70
96
|
result: str
|
|
71
|
-
result = datarepr("", 1, 2,
|
|
72
|
-
self.assertEqual(result, "(1, 2,
|
|
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')")
|
|
73
105
|
|
|
74
106
|
def test_special_characters(self: Self) -> None:
|
|
75
|
-
"
|
|
107
|
+
"""Test with special characters in arguments."""
|
|
76
108
|
result: str
|
|
77
109
|
result = datarepr("test_function", "a\nb", "\t", key="val\nue")
|
|
78
110
|
self.assertEqual(
|
|
79
111
|
result, "test_function('a\\nb', '\\t', key='val\\nue')"
|
|
80
112
|
)
|
|
81
113
|
|
|
82
|
-
def
|
|
83
|
-
"
|
|
84
|
-
args: range
|
|
85
|
-
expected: str
|
|
86
|
-
result: str
|
|
87
|
-
args = range(100)
|
|
88
|
-
result = datarepr("test_function", *args)
|
|
89
|
-
expected = "test_function(" + ", ".join(map(str, args)) + ")"
|
|
90
|
-
self.assertEqual(result, expected)
|
|
91
|
-
|
|
92
|
-
def test_combination_of_all(self: Self) -> None:
|
|
93
|
-
"This test tests with a complex combination of different types and structures."
|
|
114
|
+
def test_various_types(self: Self) -> None:
|
|
115
|
+
"""Test with various types of arguments."""
|
|
94
116
|
result: str
|
|
95
|
-
result = datarepr(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
{3: 4},
|
|
99
|
-
a=5,
|
|
100
|
-
b=[6, 7],
|
|
101
|
-
c={"key": "value"},
|
|
102
|
-
)
|
|
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"})
|
|
103
120
|
self.assertEqual(
|
|
104
|
-
result,
|
|
105
|
-
"complex_function([1, 2], {3: 4}, a=5, b=[6, 7], c={'key': 'value'})",
|
|
121
|
+
result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
|
|
106
122
|
)
|
|
107
123
|
|
|
108
|
-
def test_no_args_at_all(self: Self) -> None:
|
|
109
|
-
"This test tests with no arguments, not even the name."
|
|
110
|
-
args: Any
|
|
111
|
-
args = ()
|
|
112
|
-
with self.assertRaises(TypeError):
|
|
113
|
-
datarepr(
|
|
114
|
-
*args
|
|
115
|
-
) # Should raise a TypeError due to missing required 'name' argument.
|
|
116
|
-
|
|
117
124
|
|
|
118
125
|
if __name__ == "__main__":
|
|
119
126
|
unittest.main()
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
"""Test the oxford function."""
|
|
2
|
+
|
|
3
|
+
__all__ = ["TestOxfordFunction"]
|
|
4
|
+
|
|
1
5
|
import unittest
|
|
2
6
|
from typing import Self
|
|
3
7
|
|
|
4
8
|
from datarepr.core import oxford
|
|
5
9
|
|
|
6
|
-
__all__ = ["TestOxfordFunction"]
|
|
7
|
-
|
|
8
10
|
|
|
9
11
|
class TestOxfordFunction(unittest.TestCase):
|
|
12
|
+
"""Test the oxford function comprehensively."""
|
|
13
|
+
|
|
10
14
|
def test_no_args_at_all(self: Self) -> None:
|
|
15
|
+
"""Test oxford with varying numbers of arguments."""
|
|
11
16
|
self.assertEqual("", oxford())
|
|
12
17
|
self.assertEqual(42, oxford(default=42))
|
|
13
18
|
self.assertEqual("1, 'two', and 3", oxford(1, "two", 3))
|
|
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
|
|
File without changes
|
|
File without changes
|