raisefunction 0.0.2.dev0__tar.gz → 1.0.1__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.
- {raisefunction-0.0.2.dev0/src/raisefunction.egg-info → raisefunction-1.0.1}/PKG-INFO +3 -2
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/pyproject.toml +5 -3
- raisefunction-1.0.1/src/raisefunction/core/__init__.py +31 -0
- raisefunction-1.0.1/src/raisefunction/tests/test_0.py +41 -0
- raisefunction-1.0.1/src/raisefunction/tests/test_1.py +17 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1/src/raisefunction.egg-info}/PKG-INFO +3 -2
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction.egg-info/SOURCES.txt +3 -1
- raisefunction-1.0.1/src/raisefunction.egg-info/requires.txt +1 -0
- raisefunction-0.0.2.dev0/src/raisefunction/core/__init__.py +0 -6
- raisefunction-0.0.2.dev0/src/raisefunction/tests/test_1984.py +0 -32
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/LICENSE.txt +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/MANIFEST.in +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/README.rst +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/setup.cfg +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction/__init__.py +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction/tests/__init__.py +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction.egg-info/dependency_links.txt +0 -0
- {raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: raisefunction
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: This project provides a function that raises errors passed to it.
|
|
5
5
|
Author-email: Johannes <johannes-programming@mailfence.com>
|
|
6
6
|
License: The MIT License (MIT)
|
|
@@ -28,7 +28,7 @@ Project-URL: Download, https://pypi.org/project/raisefunction/#files
|
|
|
28
28
|
Project-URL: Index, https://pypi.org/project/raisefunction/
|
|
29
29
|
Project-URL: Source, https://github.com/johannes-programming/raisefunction/
|
|
30
30
|
Project-URL: Website, https://raisefunction.johannes-programming.online/
|
|
31
|
-
Classifier: Development Status ::
|
|
31
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
32
32
|
Classifier: Intended Audience :: Developers
|
|
33
33
|
Classifier: License :: OSI Approved :: MIT License
|
|
34
34
|
Classifier: Natural Language :: English
|
|
@@ -40,6 +40,7 @@ Classifier: Typing :: Typed
|
|
|
40
40
|
Requires-Python: >=3.8
|
|
41
41
|
Description-Content-Type: text/x-rst
|
|
42
42
|
License-File: LICENSE.txt
|
|
43
|
+
Requires-Dist: overloadable>=1.0.9
|
|
43
44
|
|
|
44
45
|
=============
|
|
45
46
|
raisefunction
|
|
@@ -9,7 +9,7 @@ authors = [
|
|
|
9
9
|
{ email = "johannes-programming@mailfence.com", name = "Johannes" },
|
|
10
10
|
]
|
|
11
11
|
classifiers = [
|
|
12
|
-
"Development Status ::
|
|
12
|
+
"Development Status :: 5 - Production/Stable",
|
|
13
13
|
"Intended Audience :: Developers",
|
|
14
14
|
"License :: OSI Approved :: MIT License",
|
|
15
15
|
"Natural Language :: English",
|
|
@@ -19,13 +19,15 @@ classifiers = [
|
|
|
19
19
|
"Programming Language :: Python :: 3 :: Only",
|
|
20
20
|
"Typing :: Typed",
|
|
21
21
|
]
|
|
22
|
-
dependencies = [
|
|
22
|
+
dependencies = [
|
|
23
|
+
"overloadable>=1.0.9",
|
|
24
|
+
]
|
|
23
25
|
description = "This project provides a function that raises errors passed to it."
|
|
24
26
|
keywords = []
|
|
25
27
|
name = "raisefunction"
|
|
26
28
|
readme = "README.rst"
|
|
27
29
|
requires-python = ">=3.8"
|
|
28
|
-
version = "
|
|
30
|
+
version = "1.0.1"
|
|
29
31
|
|
|
30
32
|
[project.license]
|
|
31
33
|
file = "LICENSE.txt"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import *
|
|
2
|
+
|
|
3
|
+
from overloadable import overloadable
|
|
4
|
+
|
|
5
|
+
__all__ = ["raisefunction"]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@overloadable
|
|
9
|
+
def raisefunction(*args: Any) -> int:
|
|
10
|
+
"This function works as dispatcher."
|
|
11
|
+
if len(args) < 1:
|
|
12
|
+
raise TypeError(
|
|
13
|
+
"A raise statement requires at least 1 positional argument (0 given)."
|
|
14
|
+
)
|
|
15
|
+
if len(args) > 2:
|
|
16
|
+
raise TypeError(
|
|
17
|
+
"An assertion takes at most 2 positional arguments (%s given)." % len(args)
|
|
18
|
+
)
|
|
19
|
+
return len(args)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@raisefunction.overload(1)
|
|
23
|
+
def raisefunction(exc: BaseException, /) -> None:
|
|
24
|
+
"This function raises the given exception."
|
|
25
|
+
raise exc
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@raisefunction.overload(2)
|
|
29
|
+
def raisefunction(exc: BaseException, cause: Optional[BaseException], /) -> None:
|
|
30
|
+
"This function raises the given exception with the given cause."
|
|
31
|
+
raise exc from cause
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from raisefunction.core import raisefunction
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestRaiseFunction(unittest.TestCase):
|
|
7
|
+
def test_dispatcher_no_arguments(self):
|
|
8
|
+
"""Test the dispatcher raises a TypeError with no arguments."""
|
|
9
|
+
with self.assertRaises(TypeError) as context:
|
|
10
|
+
raisefunction()
|
|
11
|
+
self.assertIn("requires at least 1 positional argument", str(context.exception))
|
|
12
|
+
|
|
13
|
+
def test_dispatcher_too_many_arguments(self):
|
|
14
|
+
"""Test the dispatcher raises a TypeError with more than 2 arguments."""
|
|
15
|
+
with self.assertRaises(TypeError) as context:
|
|
16
|
+
raisefunction(1, 2, 3)
|
|
17
|
+
self.assertIn("takes at most 2 positional arguments", str(context.exception))
|
|
18
|
+
|
|
19
|
+
def test_raise_single_exception(self):
|
|
20
|
+
"""Test the single exception raising overload."""
|
|
21
|
+
with self.assertRaises(ValueError):
|
|
22
|
+
raisefunction(ValueError("Test single exception"))
|
|
23
|
+
|
|
24
|
+
def test_raise_exception_with_cause(self):
|
|
25
|
+
"""Test the exception raising overload with a cause."""
|
|
26
|
+
with self.assertRaises(ValueError) as context:
|
|
27
|
+
raisefunction(ValueError("Test exception"), TypeError("Cause exception"))
|
|
28
|
+
self.assertEqual(str(context.exception), "Test exception")
|
|
29
|
+
self.assertIsInstance(context.exception.__cause__, TypeError)
|
|
30
|
+
self.assertEqual(str(context.exception.__cause__), "Cause exception")
|
|
31
|
+
|
|
32
|
+
def test_invalid_arguments_in_overloads(self):
|
|
33
|
+
"""Test invalid argument types raise appropriate errors."""
|
|
34
|
+
with self.assertRaises(TypeError):
|
|
35
|
+
raisefunction("not an exception")
|
|
36
|
+
with self.assertRaises(TypeError):
|
|
37
|
+
raisefunction("not an exception", "not a cause")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
unittest.main()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from raisefunction.core import raisefunction
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestRaiseFunction(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def test_raise_exception_with_cause(self):
|
|
9
|
+
"""Test the exception raising overload with a cause."""
|
|
10
|
+
with self.assertRaises(ValueError) as context:
|
|
11
|
+
raisefunction(ValueError("Test exception"), KeyError("Cause exception"))
|
|
12
|
+
self.assertEqual(str(context.exception), "Test exception")
|
|
13
|
+
self.assertIsInstance(context.exception.__cause__, KeyError)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
unittest.main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: raisefunction
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: This project provides a function that raises errors passed to it.
|
|
5
5
|
Author-email: Johannes <johannes-programming@mailfence.com>
|
|
6
6
|
License: The MIT License (MIT)
|
|
@@ -28,7 +28,7 @@ Project-URL: Download, https://pypi.org/project/raisefunction/#files
|
|
|
28
28
|
Project-URL: Index, https://pypi.org/project/raisefunction/
|
|
29
29
|
Project-URL: Source, https://github.com/johannes-programming/raisefunction/
|
|
30
30
|
Project-URL: Website, https://raisefunction.johannes-programming.online/
|
|
31
|
-
Classifier: Development Status ::
|
|
31
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
32
32
|
Classifier: Intended Audience :: Developers
|
|
33
33
|
Classifier: License :: OSI Approved :: MIT License
|
|
34
34
|
Classifier: Natural Language :: English
|
|
@@ -40,6 +40,7 @@ Classifier: Typing :: Typed
|
|
|
40
40
|
Requires-Python: >=3.8
|
|
41
41
|
Description-Content-Type: text/x-rst
|
|
42
42
|
License-File: LICENSE.txt
|
|
43
|
+
Requires-Dist: overloadable>=1.0.9
|
|
43
44
|
|
|
44
45
|
=============
|
|
45
46
|
raisefunction
|
|
@@ -7,7 +7,9 @@ src/raisefunction/__init__.py
|
|
|
7
7
|
src/raisefunction.egg-info/PKG-INFO
|
|
8
8
|
src/raisefunction.egg-info/SOURCES.txt
|
|
9
9
|
src/raisefunction.egg-info/dependency_links.txt
|
|
10
|
+
src/raisefunction.egg-info/requires.txt
|
|
10
11
|
src/raisefunction.egg-info/top_level.txt
|
|
11
12
|
src/raisefunction/core/__init__.py
|
|
12
13
|
src/raisefunction/tests/__init__.py
|
|
13
|
-
src/raisefunction/tests/
|
|
14
|
+
src/raisefunction/tests/test_0.py
|
|
15
|
+
src/raisefunction/tests/test_1.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
overloadable>=1.0.9
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
|
|
3
|
-
from raisefunction.core import raisefunction
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class TestRaiseFunction(unittest.TestCase):
|
|
7
|
-
|
|
8
|
-
def test_raise_value_error(self):
|
|
9
|
-
"""Test if raisefunction raises a ValueError as expected."""
|
|
10
|
-
with self.assertRaises(ValueError) as context:
|
|
11
|
-
raisefunction(ValueError("This is a ValueError"))
|
|
12
|
-
self.assertEqual(str(context.exception), "This is a ValueError")
|
|
13
|
-
|
|
14
|
-
def test_raise_type_error(self):
|
|
15
|
-
"""Test if raisefunction raises a TypeError as expected."""
|
|
16
|
-
with self.assertRaises(TypeError) as context:
|
|
17
|
-
raisefunction(TypeError("This is a TypeError"))
|
|
18
|
-
self.assertEqual(str(context.exception), "This is a TypeError")
|
|
19
|
-
|
|
20
|
-
def test_raise_custom_exception(self):
|
|
21
|
-
"""Test if raisefunction raises a custom exception as expected."""
|
|
22
|
-
|
|
23
|
-
class CustomError(Exception):
|
|
24
|
-
pass
|
|
25
|
-
|
|
26
|
-
with self.assertRaises(CustomError) as context:
|
|
27
|
-
raisefunction(CustomError("This is a CustomError"))
|
|
28
|
-
self.assertEqual(str(context.exception), "This is a CustomError")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if __name__ == "__main__":
|
|
32
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{raisefunction-0.0.2.dev0 → raisefunction-1.0.1}/src/raisefunction.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|