datarepr 1.2.6__tar.gz → 1.2.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarepr
3
- Version: 1.2.6
3
+ Version: 1.2.7
4
4
  Summary: This project allows for common sense data representation.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -28,7 +28,7 @@ license-files = [
28
28
  name = "datarepr"
29
29
  readme = "README.rst"
30
30
  requires-python = ">=3.11"
31
- version = "1.2.6"
31
+ version = "1.2.7"
32
32
 
33
33
  [project.urls]
34
34
  Download = "https://pypi.org/project/datarepr/#files"
@@ -0,0 +1,112 @@
1
+ """Test the datarepr function."""
2
+
3
+ __all__ = ["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
+ solution: str,
42
+ args: Sequence[Any],
43
+ kwargs: Any = (),
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
+ for x, y in Lazy.lazy.test_0.items():
54
+ self.go_valid(x, **y)
55
+
56
+ def test_combination_of_all(self: Self) -> None:
57
+ """Test a complex combination of types and structures."""
58
+ result: str
59
+ solution: str
60
+ result = datarepr(
61
+ "complex_function",
62
+ [1, 2],
63
+ {3: 4},
64
+ a=5,
65
+ b=[6, 7],
66
+ c={"key": "value"},
67
+ )
68
+ solution = (
69
+ "complex_function([1, 2], {3: 4}, a=5,"
70
+ " b=[6, 7], c={'key': 'value'})"
71
+ )
72
+ self.assertEqual(result, solution)
73
+
74
+ def test_name_as_non_string(self: Self) -> None:
75
+ """Test with the 'name' parameter as a non-string type."""
76
+ result: str
77
+ result = datarepr(None, "arg1")
78
+ self.assertEqual(result, "None('arg1')")
79
+
80
+ def test_no_args_at_all(self: Self) -> None:
81
+ """Test with no arguments, not even the name."""
82
+ args: Any
83
+ args = ()
84
+ with self.assertRaises(TypeError):
85
+ # Raise TypeError: missing required 'name' argument.
86
+ datarepr(*args)
87
+
88
+ def test_special_characters(self: Self) -> None:
89
+ """Test with special characters in arguments."""
90
+ result: str
91
+ result = datarepr("test_function", "a\nb", "\t", key="val\nue")
92
+ self.assertEqual(
93
+ result, "test_function('a\\nb', '\\t', key='val\\nue')"
94
+ )
95
+
96
+ def test_various_types(self: Self) -> None:
97
+ """Test with various types of arguments."""
98
+ result: str
99
+ result = datarepr("test_function", 1, 2.0, True, None)
100
+ self.assertEqual(result, "test_function(1, 2.0, True, None)")
101
+ result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
102
+ self.assertEqual(
103
+ result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
104
+ )
105
+ result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
106
+ self.assertEqual(
107
+ result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
108
+ )
109
+
110
+
111
+ if __name__ == "__main__":
112
+ unittest.main()
@@ -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')"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarepr
3
- Version: 1.2.6
3
+ Version: 1.2.7
4
4
  Summary: This project allows for common sense data representation.
5
5
  Author-email: Johannes <johannes.programming@gmail.com>
6
6
  License-Expression: MIT
@@ -15,4 +15,5 @@ src/datarepr.egg-info/dependency_links.txt
15
15
  src/datarepr.egg-info/top_level.txt
16
16
  src/datarepr/tests/__init__.py
17
17
  src/datarepr/tests/test_0.py
18
- src/datarepr/tests/test_oxford.py
18
+ src/datarepr/tests/test_oxford.py
19
+ src/datarepr/tests/testdata.toml
@@ -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