Skip to content

Commit 5be9c9a

Browse files
committed
Move "Dumb" test objects to base file
Tests should not directly use abstract classes, but now use basic implementation instead
1 parent 24aa6f7 commit 5be9c9a

4 files changed

Lines changed: 49 additions & 50 deletions

File tree

tests/base.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,55 @@
22
import os.path
33
import shutil
44
import tempfile
5+
import typing
56
import unittest
67

78
import pytest
89
import responses
910

10-
from bugwarrior import config
11+
from bugwarrior import config, services
1112
from bugwarrior.config import schema
1213

1314

15+
class DumbConfig(config.ServiceConfig):
16+
service: typing.Literal["test"] = "test"
17+
18+
import_labels_as_tags: bool = False
19+
label_template: str = "{{label}}"
20+
21+
@property
22+
def service_class(cls) -> type["DumbService"]:
23+
return DumbService
24+
25+
26+
class DumbIssue(services.Issue):
27+
UDAS: dict = {}
28+
UNIQUE_KEY: tuple[str, ...] = ("id",)
29+
PRIORITY_MAP: dict = {}
30+
31+
def get_default_description(self):
32+
raise NotImplementedError
33+
34+
def to_taskwarrior(self):
35+
raise NotImplementedError
36+
37+
38+
class DumbService(services.Service):
39+
API_VERSION = 1.0
40+
ISSUE_CLASS = DumbIssue
41+
CONFIG_SCHEMA = DumbConfig
42+
43+
@staticmethod
44+
def get_keyring_service(_):
45+
raise NotImplementedError
46+
47+
def get_owner(self, _):
48+
raise NotImplementedError
49+
50+
def issues(self):
51+
raise NotImplementedError
52+
53+
1454
class AbstractServiceTest(abc.ABC):
1555
"""Ensures that certain test methods are implemented for each service."""
1656

tests/config/test_schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from bugwarrior.config import schema
1212

13-
from ..base import ConfigTest
13+
from ..base import ConfigTest, DumbConfig
1414

1515

1616
class TestExpandedPath(unittest.TestCase):
@@ -249,7 +249,7 @@ def test_flavors(self):
249249
class TestComputeTemplates(unittest.TestCase):
250250
def test_template(self):
251251
raw_values = {'templates': {}, 'project_template': 'foo'}
252-
computed_values = schema.ServiceConfig().compute_templates(raw_values)
252+
computed_values = DumbConfig.compute_templates(raw_values)
253253
self.assertEqual(computed_values['templates'], {'project': 'foo'})
254254

255255
def test_empty_template(self):
@@ -262,7 +262,7 @@ def test_empty_template(self):
262262
https://github.com/ralphbean/bugwarrior/issues/970
263263
"""
264264
raw_values = {'templates': {}, 'project_template': ''}
265-
computed_values = schema.ServiceConfig().compute_templates(raw_values)
265+
computed_values = DumbConfig.compute_templates(raw_values)
266266
self.assertEqual(computed_values['templates'], {'project': ''})
267267

268268

tests/test_service.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,18 @@
11
import pathlib
22
import re
3-
import typing
43
import unittest.mock
54

6-
from bugwarrior import config, services
5+
from bugwarrior import services
76
from bugwarrior.config import schema
87

9-
from .base import ConfigTest
8+
from .base import ConfigTest, DumbService
109

1110
LONG_MESSAGE = """\
1211
Some message that is over 100 characters. This message is so long it's
1312
going to fill up your floppy disk taskwarrior backup. Actually it's not
1413
that long.""".replace('\n', ' ')
1514

1615

17-
class DumbConfig(config.ServiceConfig):
18-
service: typing.Literal['test']
19-
20-
import_labels_as_tags: bool = False
21-
label_template: str = '{{label}}'
22-
23-
24-
class DumbIssue(services.Issue):
25-
"""
26-
Implement the required methods but they shouldn't be called.
27-
"""
28-
29-
def get_default_description(self):
30-
raise NotImplementedError
31-
32-
def to_taskwarrior(self):
33-
raise NotImplementedError
34-
35-
36-
class DumbService(services.Service):
37-
"""
38-
Implement the required methods but they shouldn't be called.
39-
"""
40-
41-
API_VERSION = 1.0
42-
ISSUE_CLASS = DumbIssue
43-
CONFIG_SCHEMA = DumbConfig
44-
45-
@staticmethod
46-
def get_keyring_service(_):
47-
raise NotImplementedError
48-
49-
def get_owner(self, _):
50-
raise NotImplementedError
51-
52-
def issues(self):
53-
raise NotImplementedError
54-
55-
5616
class ServiceBase(ConfigTest):
5717
def setUp(self):
5818
super().setUp()

tests/test_templates.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from bugwarrior.collect import TaskConstructor
2-
from bugwarrior.config.schema import MainSectionConfig, ServiceConfig
2+
from bugwarrior.config.schema import MainSectionConfig
33

4-
from .base import ServiceTest
5-
from .test_service import DumbIssue
4+
from .base import DumbConfig, DumbIssue, ServiceTest
65

76

87
class TestTemplates(ServiceTest):
@@ -14,7 +13,7 @@ def setUp(self):
1413
def get_issue(self, templates=None, issue=None, description=None, add_tags=None):
1514
templates = {} if templates is None else templates
1615
template_kwargs = {f'{key}_template': value for key, value in templates.items()}
17-
config = ServiceConfig(
16+
config = DumbConfig(
1817
target='dummy', add_tags=add_tags if add_tags else [], **template_kwargs
1918
)
2019
main_config = MainSectionConfig(interactive=False, targets=[])

0 commit comments

Comments
 (0)