makeprop 0.0.2.dev0__tar.gz → 0.0.4.dev0__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.1
2
2
  Name: makeprop
3
- Version: 0.0.2.dev0
3
+ Version: 0.0.4.dev0
4
4
  Summary: makeprop
5
5
  Author-email: Johannes <johannes-programming@mailfence.com>
6
6
  License: The MIT License (MIT)
@@ -26,7 +26,9 @@ License: The MIT License (MIT)
26
26
  SOFTWARE.
27
27
  Project-URL: Documentation, https://pypi.org/project/makeprop
28
28
  Project-URL: Download, https://pypi.org/project/makeprop/#files
29
+ Project-URL: Index, https://pypi.org/project/makeprop
29
30
  Project-URL: Source, https://github.com/johannes-programming/makeprop
31
+ Project-URL: Website, https://makeprop.johannes-programming.online
30
32
  Classifier: Development Status :: 2 - Pre-Alpha
31
33
  Classifier: License :: OSI Approved :: MIT License
32
34
  Classifier: Programming Language :: Python
@@ -21,7 +21,7 @@ keywords = []
21
21
  name = "makeprop"
22
22
  readme = "README.rst"
23
23
  requires-python = ">=3.12.5"
24
- version = "0.0.2.dev0"
24
+ version = "0.0.4.dev0"
25
25
 
26
26
  [project.license]
27
27
  file = "LICENSE.txt"
@@ -29,4 +29,6 @@ file = "LICENSE.txt"
29
29
  [project.urls]
30
30
  Documentation = "https://pypi.org/project/makeprop"
31
31
  Download = "https://pypi.org/project/makeprop/#files"
32
+ Index = "https://pypi.org/project/makeprop"
32
33
  Source = "https://github.com/johannes-programming/makeprop"
34
+ Website = "https://makeprop.johannes-programming.online"
@@ -0,0 +1,174 @@
1
+ import unittest
2
+
3
+ from makeprop.core import (
4
+ makeprop,
5
+ ) # Replace with the actual module name where makeprop is defined
6
+
7
+
8
+ class TestMakeprop(unittest.TestCase):
9
+
10
+ def test_default_var_name(self):
11
+ # Test using default variable name with property
12
+ class TestClass:
13
+ @makeprop()
14
+ def value(self, x):
15
+ return x * 2
16
+
17
+ obj = TestClass()
18
+ obj.value = 5
19
+ # Expected to be 5 * 2 = 10
20
+ self.assertEqual(obj._value, 10)
21
+ self.assertEqual(obj.value, 10)
22
+
23
+ def test_custom_var_name(self):
24
+ # Test using a custom variable name with property
25
+ class TestClass:
26
+ @makeprop("_custom_value")
27
+ def value(self, x):
28
+ return x + 1
29
+
30
+ obj = TestClass()
31
+ obj.value = 7
32
+ # Expected to be 7 + 1 = 8
33
+ self.assertEqual(obj._custom_value, 8)
34
+ self.assertEqual(obj.value, 8)
35
+
36
+ def test_callable_function_transformation(self):
37
+ # Test transformation of values using callable function in property
38
+ class TestClass:
39
+ @makeprop()
40
+ def value(self, x):
41
+ return x**2
42
+
43
+ obj = TestClass()
44
+ obj.value = 4
45
+ # Expected to be 4 ** 2 = 16
46
+ self.assertEqual(obj._value, 16)
47
+ self.assertEqual(obj.value, 16)
48
+
49
+ def test_docstring_inheritance(self):
50
+ # Test that the function docstring is inherited in the property
51
+ class TestClass:
52
+ @makeprop()
53
+ def value(self, x):
54
+ """Property to test docstring inheritance."""
55
+ return x
56
+
57
+ obj = TestClass()
58
+ # Check if docstring is properly inherited
59
+ self.assertEqual(
60
+ obj.__class__.value.__doc__, "Property to test docstring inheritance."
61
+ )
62
+
63
+ def test_multiple_instances_independence(self):
64
+ # Test independence of multiple instances of the same class
65
+ class TestClass:
66
+ @makeprop()
67
+ def value(self, x):
68
+ return x + 5
69
+
70
+ obj1 = TestClass()
71
+ obj2 = TestClass()
72
+
73
+ obj1.value = 3 # Expected to be 3 + 5 = 8
74
+ obj2.value = 7 # Expected to be 7 + 5 = 12
75
+
76
+ self.assertEqual(obj1.value, 8)
77
+ self.assertEqual(obj2.value, 12)
78
+
79
+ def test_no_side_effect_on_non_makeprop_attributes(self):
80
+ # Test that makeprop does not interfere with other attributes
81
+ class TestClass:
82
+ def __init__(self):
83
+ self.regular_attr = 42
84
+
85
+ @makeprop()
86
+ def value(self, x):
87
+ return x * 3
88
+
89
+ obj = TestClass()
90
+ obj.value = 2 # Expected to be 2 * 3 = 6
91
+
92
+ # Ensure makeprop works and does not affect regular_attr
93
+ self.assertEqual(obj.value, 6)
94
+ self.assertEqual(obj.regular_attr, 42)
95
+
96
+ def test_overwrite_existing_property(self):
97
+ # Test overwriting an existing property using makeprop
98
+ class TestClass:
99
+ @property
100
+ def value(self):
101
+ return "This should be overwritten"
102
+
103
+ @value.setter
104
+ def value(self, val):
105
+ pass # Placeholder to avoid AttributeError
106
+
107
+ @makeprop()
108
+ def value(self, x):
109
+ return x * 10
110
+
111
+ obj = TestClass()
112
+ obj.value = 5
113
+ # Expected to be 5 * 10 = 50
114
+ self.assertEqual(obj.value, 50)
115
+
116
+ def test_attribute_error_on_unset_value(self):
117
+ # Test AttributeError when accessing property without setting it
118
+ class TestClass:
119
+ @makeprop()
120
+ def value(self, x):
121
+ return x * 2
122
+
123
+ obj = TestClass()
124
+ with self.assertRaises(AttributeError):
125
+ _ = obj.value
126
+
127
+ def test_error_handling_with_invalid_type(self):
128
+ # Test handling of invalid type input in the property setter
129
+ class TestClass:
130
+ @makeprop()
131
+ def value(self, x):
132
+ if not isinstance(x, int):
133
+ raise ValueError("Expected an integer")
134
+ return x
135
+
136
+ obj = TestClass()
137
+ with self.assertRaises(ValueError):
138
+ obj.value = "invalid_type"
139
+
140
+ def test_reset_property(self):
141
+ # Test resetting property to None and subsequent assignment
142
+ class TestClass:
143
+ @makeprop()
144
+ def value(self, x):
145
+ return x * 2
146
+
147
+ obj = TestClass()
148
+ obj.value = 3 # Expected to be 3 * 2 = 6
149
+ self.assertEqual(obj.value, 6)
150
+
151
+ # Resetting property
152
+ del obj._value
153
+ with self.assertRaises(AttributeError):
154
+ _ = obj.value
155
+
156
+ def test_property_removal(self):
157
+ # Test if removing the private attribute raises AttributeError
158
+ class TestClass:
159
+ @makeprop()
160
+ def value(self, x):
161
+ return x + 10
162
+
163
+ obj = TestClass()
164
+ obj.value = 5
165
+ self.assertEqual(obj.value, 15)
166
+
167
+ # Deleting the private variable
168
+ del obj._value
169
+ with self.assertRaises(AttributeError):
170
+ _ = obj.value
171
+
172
+
173
+ if __name__ == "__main__":
174
+ unittest.main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: makeprop
3
- Version: 0.0.2.dev0
3
+ Version: 0.0.4.dev0
4
4
  Summary: makeprop
5
5
  Author-email: Johannes <johannes-programming@mailfence.com>
6
6
  License: The MIT License (MIT)
@@ -26,7 +26,9 @@ License: The MIT License (MIT)
26
26
  SOFTWARE.
27
27
  Project-URL: Documentation, https://pypi.org/project/makeprop
28
28
  Project-URL: Download, https://pypi.org/project/makeprop/#files
29
+ Project-URL: Index, https://pypi.org/project/makeprop
29
30
  Project-URL: Source, https://github.com/johannes-programming/makeprop
31
+ Project-URL: Website, https://makeprop.johannes-programming.online
30
32
  Classifier: Development Status :: 2 - Pre-Alpha
31
33
  Classifier: License :: OSI Approved :: MIT License
32
34
  Classifier: Programming Language :: Python
@@ -1,10 +0,0 @@
1
- import unittest
2
-
3
-
4
- class Test1984(unittest.TestCase):
5
- def test_1984(self):
6
- self.assertEqual(2 + 2, 4, "Ignorance is Strength")
7
-
8
-
9
- if __name__ == "__main__":
10
- unittest.main()
File without changes
File without changes
File without changes
File without changes