Skip to content

Commit 0fda11b

Browse files
committed
fix checkArchitecture test in ServiceBase
That test was simply testing each abstract method is defined only once. Reverted to check the number of calls for each abstract method while adding an allowlist, for abstract methods we can call from concrete ones
1 parent 7dafc55 commit 0fda11b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tests/test_service.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import abc
12
import pathlib
3+
from pathlib import Path
24
import re
35
import unittest.mock
46

@@ -31,7 +33,9 @@ def makeIssue(self):
3133
service = self.makeService()
3234
return service.get_issue_for_record({})
3335

34-
def checkArchitecture(self, klass):
36+
def checkArchitecture(
37+
self, klass: abc.ABCMeta, method_allowlist: set[str] | None = None
38+
):
3539
"""
3640
Bidirectional communication between the base classes and their children
3741
has been a source of complication as changes to any part of the
@@ -43,17 +47,16 @@ def checkArchitecture(self, klass):
4347
appear once. This should ensure that these methods are declared here
4448
but not called.
4549
"""
46-
with open(services.__file__, 'r') as f:
47-
base = f.read()
50+
base = Path(services.__file__).read_text()
4851

49-
for method in klass.__abstractmethods__:
50-
references = re.findall(rf'def {method}\(', base)
52+
for method in klass.__abstractmethods__ - (method_allowlist or set()):
53+
references = re.findall(rf'{method}\(', base)
5154
self.assertEqual(len(references), 1, references)
5255

5356

5457
class TestService(ServiceBase):
5558
def test_architecture(self):
56-
self.checkArchitecture(services.Service)
59+
self.checkArchitecture(services.Service, {"get_keyring_service"})
5760

5861
def test_build_annotations_default(self):
5962
service = self.makeService()

0 commit comments

Comments
 (0)