10000 Test refactoring by dmitry-lipetsk · Pull Request #236 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Test refactoring #236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test_get_pg_config2 moved to TestUtils
  • Loading branch information
dmitry-lipetsk committed Apr 6, 2025
commit d7f704d8d46c902745e955f00dffb6835015a6c7
28 changes: 0 additions & 28 deletions tests/test_testgres_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from ..testgres.node import PgVer
from ..testgres.node import PostgresNode
from ..testgres.utils import get_pg_version2
from ..testgres.utils import get_pg_config2
from ..testgres.utils import file_tail
from ..testgres.utils import get_bin_path2
from ..testgres import ProcessType
Expand Down Expand Up @@ -1080,33 +1079,6 @@ def test_dump(self, node_svc: PostgresNodeService):
res = node3.execute(query_select)
assert (res == [(1, ), (2, )])

def test_get_pg_config2(self, node_svc: PostgresNodeService):
assert isinstance(node_svc, PostgresNodeService)

# check same instances
a = get_pg_config2(node_svc.os_ops, None)
b = get_pg_config2(node_svc.os_ops, None)
assert (id(a) == id(b))

# save right before config change
c1 = get_pg_config2(node_svc.os_ops, None)

# modify setting for this scope
with scoped_config(cache_pg_config=False) as config:
# sanity check for value
assert not (config.cache_pg_config)

# save right after config change
c2 = get_pg_config2(node_svc.os_ops, None)

# check different instances after config change
assert (id(c1) != id(c2))

# check different instances
a = get_pg_config2(node_svc.os_ops, None)
b = get_pg_config2(node_svc.os_ops, None)
assert (id(a) != id(b))

def test_pgbench(self, node_svc: PostgresNodeService):
assert isinstance(node_svc, PostgresNodeService)

Expand Down
49 changes: 49 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
from .helpers.global_data import OsOpsDescr
from .helpers.global_data import OsOpsDescrs
from .helpers.global_data import OsOperations

from ..testgres.utils import parse_pg_version
from ..testgres.utils import get_pg_config2
from ..testgres import scoped_config

import pytest


class TestUtils:
sm_os_ops_descrs: list[OsOpsDescr] = [
OsOpsDescrs.sm_local_os_ops_descr,
OsOpsDescrs.sm_remote_os_ops_descr
]

@pytest.fixture(
params=[descr.os_ops for descr in sm_os_ops_descrs],
ids=[descr.sign for descr in sm_os_ops_descrs]
)
def os_ops(self, request: pytest.FixtureRequest) -> OsOperations:
assert isinstance(request, pytest.FixtureRequest)
assert isinstance(request.param, OsOperations)
return request.param

def test_parse_pg_version(self):
# Linux Mint
assert parse_pg_version("postgres (PostgreSQL) 15.5 (Ubuntu 15.5-1.pgdg22.04+1)") == "15.5"
Expand All @@ -11,3 +33,30 @@ def test_parse_pg_version(self):
assert parse_pg_version("postgres (PostgreSQL) 11.4") == "11.4"
# Macos
assert parse_pg_version("postgres (PostgreSQL) 14.9 (Homebrew)") == "14.9"

def test_get_pg_config2(self, os_ops: OsOperations):
assert isinstance(os_ops, OsOperations)

# check same instances
a = get_pg_config2(os_ops, None)
b = get_pg_config2(os_ops, None)
assert (id(a) == id(b))

# save right before config change
c1 = get_pg_config2(os_ops, None)

# modify setting for this scope
with scoped_config(cache_pg_config=False) as config:
# sanity check for value
assert not (config.cache_pg_config)

# save right after config change
c2 = get_pg_config2(os_ops, None)

# check different instances after config change
assert (id(c1) != id(c2))

# check different instances
a = get_pg_config2(os_ops, None)
b = get_pg_config2(os_ops, None)
assert (id(a) != id(b))
0