Skip to content

Commit e9ed3dc

Browse files
authored
Merge pull request #1 from mortymacs/development
Rename ABCMeta to ABC, add more tests, support 3.10
2 parents dca112a + 76d8b3b commit e9ed3dc

9 files changed

+190
-12
lines changed

.github/workflows/python-test.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.6, 3.7, 3.8, 3.9]
16+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
1717

1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
2020
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v3
2222
with:
2323
python-version: ${{ matrix.python-version }}
2424
- name: Install dependencies
@@ -36,7 +36,12 @@ jobs:
3636
black -C abcmeta/
3737
- name: Lint with pylint
3838
run: |
39-
pylint abcmeta/
39+
pylint --disable=consider-using-f-string abcmeta/
4040
- name: Test
4141
run: |
42-
python test.py
42+
PYTHONPATH=. python tests/correct_class_test.py
43+
PYTHONPATH=. python tests/incorrect_class_1_test.py |& grep -F "AttributeError: Derived class 'ABCDerived' has not implemented 'method_1' method of the parent class 'ABCParent'"
44+
PYTHONPATH=. python tests/incorrect_class_2_test.py |& grep -F "Derived method expected to get 3 parameters but gets 2"
45+
PYTHONPATH=. python tests/incorrect_class_3_test.py |& grep -F "Derived method expected to get 'name:<class 'str'>' paramter's type, but gets 'name:<class 'int'>'"
46+
PYTHONPATH=. python tests/incorrect_class_4_test.py |& grep -F "Derived method expected to get 'name' paramter, but gets 'family'"
47+
PYTHONPATH=. python tests/incorrect_class_5_test.py |& grep -F "Derived method expected to return in 'typing.Dict[str, str]' type, but returns 'typing.Dict[str, int]'"

abcmeta/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from difflib import ndiff
1414
from typing import Any, Callable, List, Optional, Text, Tuple, Type
1515

16-
__all__ = ["ABCMeta", "abstractmethod"]
16+
__all__ = ["ABC", "abstractmethod"]
1717

1818

1919
def _get_signature(method: Callable) -> Tuple[Type, List[Tuple[Text, Type]], Text]:
@@ -133,8 +133,8 @@ def abstractmethod(funcobj: Callable) -> Callable:
133133

134134

135135
# pylint: disable=too-few-public-methods
136-
class ABCMeta(metaclass=BuiltinABCMeta):
137-
"""Abstract base meta class."""
136+
class ABC(metaclass=BuiltinABCMeta):
137+
"""Abstract base class"""
138138

139139
def __init_subclass__(cls):
140140
"""Python built-in method."""

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="abcmeta",
8-
version="1.0.2",
8+
version="2.0.0",
99
author="Morteza NourelahiAlamdari",
1010
author_email="[email protected]",
1111
description="Python meta class and abstract method library with restrictions.",
@@ -16,6 +16,7 @@
1616
project_urls={"Bug Tracker": "https://github.com/mortymacs/abcmeta/issues"},
1717
classifiers=[
1818
"Programming Language :: Python :: 3",
19+
"Programming Language :: Python :: 3.10",
1920
"Programming Language :: Python :: 3.9",
2021
"Programming Language :: Python :: 3.8",
2122
"Programming Language :: Python :: 3.7",

test.py tests/correct_class_test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Unit test for abcmeta library."""
22
from typing import Dict, Text, Tuple
33

4-
from abcmeta import ABCMeta, abstractmethod
4+
from abcmeta import ABC, abstractmethod
55

66

7-
class ABCMetaParent(ABCMeta):
7+
class ABCParent(ABC):
88
@abstractmethod
99
def method_1(self, name, age):
1010
pass
@@ -21,7 +21,7 @@ def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
2121
"""Abstract method."""
2222

2323

24-
class ABCMetaDerived(ABCMetaParent):
24+
class ABCMetaDerived(ABCParent):
2525
def method_1(self, name, age):
2626
pass
2727

tests/incorrect_class_1_test.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Test for abcmeta library.
2+
3+
incompleted derived class.
4+
"""
5+
from typing import Dict, Text, Tuple
6+
7+
from abcmeta import ABC, abstractmethod
8+
9+
10+
class ABCParent(ABC):
11+
@abstractmethod
12+
def method_1(self, name, age):
13+
pass
14+
15+
@abstractmethod
16+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
17+
"""Abstract method."""
18+
19+
def method_3(self):
20+
pass
21+
22+
@abstractmethod
23+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
24+
"""Abstract method."""
25+
26+
27+
class ABCDerived(ABCParent):
28+
def method(self, name):
29+
pass
30+
31+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
32+
return ("name", "test")

tests/incorrect_class_2_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test for abcmeta library.
2+
3+
incompleted parameters in the derived class.
4+
"""
5+
from typing import Dict, Text, Tuple
6+
7+
from abcmeta import ABC, abstractmethod
8+
9+
10+
class ABCParent(ABC):
11+
@abstractmethod
12+
def method_1(self, name, age):
13+
pass
14+
15+
@abstractmethod
16+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
17+
"""Abstract method."""
18+
19+
def method_3(self):
20+
pass
21+
22+
@abstractmethod
23+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
24+
"""Abstract method."""
25+
26+
27+
class ABCDerived(ABCParent):
28+
def method_1(self, name):
29+
pass
30+
31+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
32+
return {"name": "test"}
33+
34+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
35+
return ("name", "test")

tests/incorrect_class_3_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test for abcmeta library.
2+
3+
different parameter type in the derived class.
4+
"""
5+
from typing import Dict, Text, Tuple
6+
7+
from abcmeta import ABC, abstractmethod
8+
9+
10+
class ABCParent(ABC):
11+
@abstractmethod
12+
def method_1(self, name, age):
13+
pass
14+
15+
@abstractmethod
16+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
17+
"""Abstract method."""
18+
19+
def method_3(self):
20+
pass
21+
22+
@abstractmethod
23+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
24+
"""Abstract method."""
25+
26+
27+
class ABCDerived(ABCParent):
28+
def method_1(self, name, age):
29+
pass
30+
31+
def method_2(self, name: int, age: int) -> Dict[Text, Text]:
32+
return {"name": "test"}
33+
34+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
35+
return ("name", "test")

tests/incorrect_class_4_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test for abcmeta library.
2+
3+
different parameter name in the derived class.
4+
"""
5+
from typing import Dict, Text, Tuple
6+
7+
from abcmeta import ABC, abstractmethod
8+
9+
10+
class ABCParent(ABC):
11+
@abstractmethod
12+
def method_1(self, name, age):
13+
pass
14+
15+
@abstractmethod
16+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
17+
"""Abstract method."""
18+
19+
def method_3(self):
20+
pass
21+
22+
@abstractmethod
23+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
24+
"""Abstract method."""
25+
26+
27+
class ABCDerived(ABCParent):
28+
def method_1(self, name, age):
29+
pass
30+
31+
def method_2(self, name: str, age: int) -> Dict[Text, Text]:
32+
return {"name": "test"}
33+
34+
def method_4(self, family: Text, age: int) -> Tuple[Text, Text]:
35+
return ("name", "test")

tests/incorrect_class_5_test.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Test for abcmeta library.
2+
3+
different return type in the derived class.
4+
"""
5+
from typing import Dict, Text, Tuple
6+
7+
from abcmeta import ABC, abstractmethod
8+
9+
10+
class ABCParent(ABC):
11+
@abstractmethod
12+
def method_1(self, name, age):
13+
pass
14+
15+
@abstractmethod
16+
def method_2(self, name: Text, age: int) -> Dict[Text, Text]:
17+
"""Abstract method."""
18+
19+
def method_3(self):
20+
pass
21+
22+
@abstractmethod
23+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
24+
"""Abstract method."""
25+
26+
27+
class ABCDerived(ABCParent):
28+
def method_1(self, name, age):
29+
pass
30+
31+
def method_2(self, name: Text, age: int) -> Dict[Text, int]:
32+
return {"name": "test"}
33+
34+
def method_4(self, name: Text, age: int) -> Tuple[Text, Text]:
35+
return ("name", "test")

0 commit comments

Comments
 (0)