Skip to content

Commit 05ee575

Browse files
author
David Erb
committed
tweaks docs and cleans up
1 parent 153c732 commit 05ee575

File tree

9 files changed

+49
-110
lines changed

9 files changed

+49
-110
lines changed
-32 KB
Binary file not shown.

src/dls_servbase_api/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
class Keywords:
22
ENABLE_COOKIES = "dls_servbase_api::keywords::enable_cookies"
3+
4+
5+
# ----------------------------------------------------------------------------------------
6+
class ClassTypes:
7+
AIOHTTP = "dls_servbase_lib.datafaces.aiohttp"
8+
NORMSQL = "dls_servbase_lib.datafaces.normsql"

src/dls_servbase_lib/datafaces/aiohttp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# Basic things.
1111
from dls_utilpack.thing import Thing
1212

13+
# Class types.
14+
from dls_servbase_api.constants import ClassTypes
15+
1316
# Dataface protocolj things.
1417
from dls_servbase_api.datafaces.constants import Commands, Keywords
1518

@@ -22,7 +25,7 @@
2225

2326
logger = logging.getLogger(__name__)
2427

25-
thing_type = "dls_servbase_lib.datafaces.aiohttp"
28+
thing_type = ClassTypes.AIOHTTP
2629

2730

2831
# ------------------------------------------------------------------------------------------

src/dls_servbase_lib/datafaces/datafaces.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Use standard logging in this module.
22
import logging
3+
from typing import Any, Dict, Type
34

45
# Class managing list of things.
56
from dls_utilpack.things import Things
67

8+
# Class types.
9+
from dls_servbase_api.constants import ClassTypes
10+
711
# Exceptions.
812
from dls_servbase_api.exceptions import NotFound
913

@@ -15,16 +19,34 @@
1519

1620
class Datafaces(Things):
1721
"""
18-
List of available dls_servbase_datafaces.
22+
Factory for creating instances of dls_servbase_dataface.
23+
24+
Since it is based on Things, it also can maintain a list of named instances.
25+
26+
There are currently two class types which implement dls_servbase_dataface:
27+
AIOHTTP - This is a networked service with an HTTP protocol.
28+
NORMSQL - This is implement directly on a sqlite/mysql/postgres database.
1929
"""
2030

2131
# ----------------------------------------------------------------------------------------
2232
def __init__(self, name=None):
33+
"""
34+
Args:
35+
name (_type_, optional): Name of this list used in debug messages. Defaults to None.
36+
"""
2337
Things.__init__(self, name)
2438

2539
# ----------------------------------------------------------------------------------------
26-
def build_object(self, specification):
27-
""""""
40+
def build_object(self, specification: Dict) -> Any:
41+
"""
42+
Build an object whose type is contained in the specification as a string.
43+
44+
Args:
45+
specification (Dict): Specification, must contain at least the keyword "type".
46+
47+
Returns:
48+
The dls_servbase_dataface instance.
49+
"""
2850

2951
dls_servbase_dataface_class = self.lookup_class(specification["type"])
3052

@@ -39,15 +61,20 @@ def build_object(self, specification):
3961
return dls_servbase_dataface_object
4062

4163
# ----------------------------------------------------------------------------------------
42-
def lookup_class(self, class_type):
43-
""""""
64+
def lookup_class(self, class_type: str) -> Type:
65+
"""
66+
From the given class type string, return a class corresponding to the type.
67+
68+
Returns:
69+
A class which can be instantiated.
70+
"""
4471

45-
if class_type == "dls_servbase_lib.datafaces.aiohttp":
72+
if class_type == ClassTypes.AIOHTTP:
4673
from dls_servbase_lib.datafaces.aiohttp import Aiohttp
4774

4875
return Aiohttp
4976

50-
elif class_type == "dls_servbase_lib.datafaces.normsql":
77+
elif class_type == ClassTypes.NORMSQL:
5178
from dls_servbase_lib.datafaces.normsql import Normsql
5279

5380
return Normsql

src/dls_servbase_lib/datafaces/normsql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# Base class for generic things.
77
from dls_utilpack.thing import Thing
88

9+
# Class types.
10+
from dls_servbase_api.constants import ClassTypes
911
from dls_servbase_api.databases.constants import Tablenames
1012
from dls_servbase_api.databases.database_definition import DatabaseDefinition
1113

1214
logger = logging.getLogger(__name__)
1315

14-
thing_type = "dls_servbase_lib.datafaces.normsql"
16+
thing_type = ClassTypes.NORMSQL
1517

1618

1719
class Normsql(Thing):

tests/base.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/base_specification_tester.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/base_tester.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,6 @@
99

1010
# ----------------------------------------------------------------------------------------
1111
class BaseTester:
12-
"""
13-
This is a base class for simplest tests.
14-
"""
15-
16-
def main(self, constants, output_directory):
17-
"""
18-
This is the main program which calls the test using asyncio.
19-
"""
20-
21-
multiprocessing.current_process().name = "main"
22-
23-
failure_message = None
24-
try:
25-
# Run main test in asyncio event loop.
26-
asyncio.run(self._main_coroutine(constants, output_directory))
27-
28-
except Exception as exception:
29-
logger.exception(
30-
"unexpected exception in the test method", exc_info=exception
31-
)
32-
failure_message = str(exception)
33-
34-
if failure_message is not None:
35-
pytest.fail(failure_message)
36-
37-
38-
# ----------------------------------------------------------------------------------------
39-
class BaseTester2:
4012
"""
4113
Provide asyncio loop and error checking over *Tester classes.
4214
"""

tests/test_database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from dls_servbase_api.databases.constants import CookieFieldnames, Tablenames
77
from dls_servbase_api.databases.database_definition import DatabaseDefinition
8-
from tests.base_tester import BaseTester2
8+
from tests.base_tester import BaseTester
99

1010
logger = logging.getLogger(__name__)
1111

@@ -61,7 +61,7 @@ def test(self, constants, logging_setup, output_directory):
6161

6262

6363
# ----------------------------------------------------------------------------------------
64-
class DatabaseTester(BaseTester2):
64+
class DatabaseTester(BaseTester):
6565
"""
6666
Test direct SQL access to the database.
6767
"""

0 commit comments

Comments
 (0)