datarepr 1.2.4__tar.gz → 1.2.6__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.4
3
+ Version: 1.2.6
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.4"
31
+ version = "1.2.6"
32
32
 
33
33
  [project.urls]
34
34
  Download = "https://pypi.org/project/datarepr/#files"
@@ -1,3 +1,5 @@
1
- from datarepr.core import datarepr, oxford
1
+ """Provide data representation utilities."""
2
2
 
3
3
  __all__ = ["datarepr", "oxford"]
4
+
5
+ from datarepr.core import datarepr, oxford
@@ -1,12 +1,14 @@
1
- from typing import TypeVar
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
- "This function allows for common sense representation."
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
- import unittest
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,130 @@
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
- "This test tests when only the name is provided and no args or kwargs."
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 test_positional_args_only(self: Self) -> None:
18
- "This test tests with positional arguments only."
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("test_function", "a", "b", "c")
26
- self.assertEqual(result, "test_function('a', 'b', 'c')")
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
- "This test tests with keyword arguments only."
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
- "This test tests with both positional and keyword arguments."
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
- "This test tests with the 'name' parameter as a non-string type."
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 test_empty_name(self: Self) -> None:
69
- "This test tests with an empty name."
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, a=3)
72
- self.assertEqual(result, "(1, 2, a=3)")
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
- "This test tests with special characters in arguments."
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 test_large_number_of_args(self: Self) -> None:
83
- "This test tests with a large number of arguments."
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
- "complex_function",
97
- [1, 2],
98
- {3: 4},
99
- a=5,
100
- b=[6, 7],
101
- c={"key": "value"},
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'})"
102
122
  )
123
+ result = datarepr("test_function", [1, 2], {3, 4}, {"key": "value"})
103
124
  self.assertEqual(
104
- result,
105
- "complex_function([1, 2], {3: 4}, a=5, b=[6, 7], c={'key': 'value'})",
125
+ result, "test_function([1, 2], {3, 4}, {'key': 'value'})"
106
126
  )
107
127
 
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
128
 
118
129
  if __name__ == "__main__":
119
130
  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))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datarepr
3
- Version: 1.2.4
3
+ Version: 1.2.6
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes