Skip to content

Commit 4e6ae8a

Browse files
Tests are updated (typing) (#343)
1 parent 1e195b1 commit 4e6ae8a

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

tests/helpers/run_conditions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class RunConditions:
77
# It is not a test kit!
88
__test__ = False
99

10+
@staticmethod
1011
def skip_if_windows():
1112
if platform.system().lower() == "windows":
1213
pytest.skip("This test does not support Windows.")

tests/test_os_ops_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def LOCAL_WORKER(os_ops: OsOperations,
10011001

10021002
assert os.path.exists(lock_dir)
10031003

1004-
def LOG_INFO(template: str, *args: list) -> None:
1004+
def LOG_INFO(template: str, *args) -> None:
10051005
assert type(template) == str # noqa: E721
10061006
assert type(args) == tuple # noqa: E721
10071007

tests/test_os_ops_remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_rmdirs__try_to_delete_file(self, os_ops: OsOperations):
3333

3434
assert os.path.exists(path)
3535
assert type(x.value) == ExecUtilException # noqa: E721
36+
assert type(x.value.description) == str # noqa: E721
3637
assert x.value.description == "Utility exited with non-zero code (20). Error: `cannot remove '" + path + "': it is not a directory`"
3738
assert x.value.message.startswith(x.value.description)
3839
assert type(x.value.error) == str # noqa: E721

tests/test_testgres_common.py

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from src import NodeStatus
2020
from src import IsolationLevel
2121
from src import NodeApp
22+
from src import enums
2223

2324
# New name prevents to collect test-functions in TestgresException and fixes
2425
# the problem with pytest warning.
@@ -797,15 +798,16 @@ def LOCAL__test_auxiliary_pids(
797798

798799
def LOCAL__check_auxiliary_pids__multiple_attempts(
799800
node: PostgresNode,
800-
expectedTypes: typing.List[ProcessType]):
801+
expectedTypes: typing.List[ProcessType],
802+
):
801803
assert node is not None
802804
assert type(node) == PostgresNode # noqa: E721
803805
assert expectedTypes is not None
804806
assert type(expectedTypes) == list # noqa: E721
805807

806808
nAttempt = 0
807809

808-
while nAttempt < 5:
810+
while True:
809811
nAttempt += 1
810812

811813
logging.info("Test pids of [{0}] node. Attempt #{1}.".format(
@@ -821,15 +823,17 @@ def LOCAL__check_auxiliary_pids__multiple_attempts(
821823
assert type(absenceList) == list # noqa: E721
822824
if len(absenceList) == 0:
823825
logging.info("Bingo!")
824-
return
826+
break
827+
828+
if nAttempt == 5:
829+
raise Exception("Node {0} does not have the following processes: {1}.".format(
830+
node.name,
831+
absenceList,
832+
))
825833

826834
logging.info("These processes are not found: {0}.".format(absenceList))
827835
continue
828-
829-
raise Exception("Node {0} does not have the following processes: {1}.".format(
830-
node.name,
831-
absenceList
832-
))
836+
return
833837

834838
with __class__.helper__get_node(node_svc).init().start() as master:
835839

@@ -1388,7 +1392,7 @@ def impl__test_pg_ctl_wait_option(
13881392
self,
13891393
node_svc: PostgresNodeService,
13901394
node: PostgresNode
1391-
) -> None:
1395+
) -> bool:
13921396
assert isinstance(node_svc, PostgresNodeService)
13931397
assert isinstance(node, PostgresNode)
13941398
assert node.status() == NodeStatus.Uninitialized
@@ -1693,25 +1697,36 @@ def test_promotion(self, node_svc: PostgresNodeService):
16931697
res = replica.safe_psql('select * from abc')
16941698
assert (__class__.helper__rm_carriage_returns(res) == b'1\n')
16951699

1696-
def test_dump(self, node_svc: PostgresNodeService):
1700+
@pytest.fixture(
1701+
params=[
1702+
enums.DumpFormat.Plain,
1703+
enums.DumpFormat.Custom,
1704+
enums.DumpFormat.Directory,
1705+
enums.DumpFormat.Tar
1706+
]
1707+
)
1708+
def dump_fmt(self, request: pytest.FixtureRequest) -> enums.DumpFormat:
1709+
assert type(request.param) == enums.DumpFormat # noqa: E721
1710+
return request.param
1711+
1712+
def test_dump(self, node_svc: PostgresNodeService, dump_fmt: enums.DumpFormat):
16971713
assert isinstance(node_svc, PostgresNodeService)
1714+
assert type(dump_fmt) == enums.DumpFormat # noqa: E721
16981715
query_create = 'create table test as select generate_series(1, 2) as val'
16991716
query_select = 'select * from test order by val asc'
17001717

17011718
with __class__.helper__get_node(node_svc).init().start() as node1:
1702-
17031719
node1.execute(query_create)
1704-
for format in ['plain', 'custom', 'directory', 'tar']:
1705-
with removing(node_svc.os_ops, node1.dump(format=format)) as dump:
1706-
with __class__.helper__get_node(node_svc).init().start() as node3:
1707-
if format == 'directory':
1708-
assert (os.path.isdir(dump))
1709-
else:
1710-
assert (os.path.isfile(dump))
1711-
# restore dump
1712-
node3.restore(filename=dump)
1713-
res = node3.execute(query_select)
1714-
assert (res == [(1, ), (2, )])
1720+
with removing(node_svc.os_ops, node1.dump(format=dump_fmt)) as dump:
1721+
with __class__.helper__get_node(node_svc).init().start() as node3:
1722+
if dump_fmt == enums.DumpFormat.Directory:
1723+
assert (os.path.isdir(dump))
1724+
else:
1725+
assert (os.path.isfile(dump))
1726+
# restore dump
1727+
node3.restore(filename=dump)
1728+
res = node3.execute(query_select)
1729+
assert (res == [(1, ), (2, )])
17151730

17161731
def test_dump_with_options(self, node_svc: PostgresNodeService):
17171732
assert isinstance(node_svc, PostgresNodeService)
@@ -1865,8 +1880,8 @@ def reserve_port(self) -> int:
18651880
self.m_DummyPortCurrentUsage += 1
18661881
return self.m_DummyPortNumber
18671882

1868-
def release_port(self, dummyPortNumber: int):
1869-
assert type(dummyPortNumber) == int # noqa: E721
1883+
def release_port(self, number: int) -> None:
1884+
assert type(number) == int # noqa: E721
18701885

18711886
assert type(self.m_DummyPortMaxUsage) == int # noqa: E721
18721887
assert type(self.m_DummyPortTotalUsage) == int # noqa: E721
@@ -1880,12 +1895,12 @@ def release_port(self, dummyPortNumber: int):
18801895
assert self.m_PrevPortManager is not None
18811896
assert isinstance(self.m_PrevPortManager, PortManager)
18821897

1883-
if self.m_DummyPortCurrentUsage > 0 and dummyPortNumber == self.m_DummyPortNumber:
1898+
if self.m_DummyPortCurrentUsage > 0 and number == self.m_DummyPortNumber:
18841899
assert self.m_DummyPortTotalUsage > 0
18851900
self.m_DummyPortCurrentUsage -= 1
18861901
return
18871902

1888-
return self.m_PrevPortManager.release_port(dummyPortNumber)
1903+
return self.m_PrevPortManager.release_port(number)
18891904

18901905
def test_port_rereserve_during_node_start(self, node_svc: PostgresNodeService):
18911906
assert type(node_svc) == PostgresNodeService # noqa: E721
@@ -2500,7 +2515,7 @@ def test_node_app__make_empty(self, node_svc: PostgresNodeService):
25002515
assert type(node_app.nodes_to_cleanup) == list # noqa: E721
25012516
assert len(node_app.nodes_to_cleanup) == 0
25022517

2503-
node: PostgresNode = None
2518+
node: typing.Optional[PostgresNode] = None
25042519
try:
25052520
node = node_app.make_simple("node")
25062521
assert node is not None
@@ -2518,7 +2533,8 @@ def test_node_app__make_empty(self, node_svc: PostgresNodeService):
25182533
node.stop()
25192534
node.release_resources()
25202535

2521-
node.cleanup(release_resources=True)
2536+
if node is not None:
2537+
node.cleanup(release_resources=True)
25222538

25232539
# -----------
25242540
logging.info("temp directory [{}] is deleting".format(tmp_dir))

tests/test_testgres_remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
import logging
6+
import typing
67

78
from .helpers.global_data import PostgresNodeService
89
from .helpers.global_data import PostgresNodeServices
@@ -105,7 +106,7 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
105106
assert os.getenv('LC_CTYPE') == unkData[1]
106107
assert os.getenv('LC_COLLATE') is None
107108

108-
exc: ExecUtilException = None
109+
exc: typing.Optional[BaseException] = None
109110
with __class__.helper__get_node() as node:
110111
try:
111112
node.init() # IT RAISES!

0 commit comments

Comments
 (0)