8000 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
TestConfig is added
  • Loading branch information
dmitry-lipetsk committed Apr 6, 2025
commit 88ca53dd232e0dded2566d52acb79bf9fd0750de
41 changes: 41 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from ..testgres import TestgresConfig
from ..testgres import configure_testgres
from ..testgres import scoped_config
from ..testgres import pop_config

from .. import testgres

import pytest


class TestConfig:
def test_config_stack(self):
# no such option
with pytest.raises(expected_exception=TypeError):
configure_testgres(dummy=True)

# we have only 1 config in stack
with pytest.raises(expected_exception=IndexError):
pop_config()

d0 = TestgresConfig.cached_initdb_dir
d1 = 'dummy_abc'
d2 = 'dummy_def'

with scoped_config(cached_initdb_dir=d1) as c1:
assert (c1.cached_initdb_dir == d1)

with scoped_config(cached_initdb_dir=d2) as c2:
stack_size = len(testgres.config.config_stack)

# try to break a stack
with pytest.raises(expected_exception=TypeError):
with scoped_config(dummy=True):
pass

assert (c2.cached_initdb_dir == d2)
assert (len(testgres.config.config_stack) == stack_size)

assert (c1.cached_initdb_dir == d1)

assert (TestgresConfig.cached_initdb_dir == d0)
37 changes: 1 addition & 36 deletions tests/test_testgres_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
ExecUtilException, \
NodeApp

from ..testgres import \
TestgresConfig, \
configure_testgres, \
scoped_config, \
pop_config
from ..testgres import scoped_config

from ..testgres import \
get_new_node
Expand Down Expand Up @@ -100,37 +96,6 @@ def test_pg_config(self):
b = get_pg_config()
assert (id(a) != id(b))

def test_config_stack(self):
# no such option
with pytest.raises(expected_exception=TypeError):
configure_testgres(dummy=True)

# we have only 1 config in stack
with pytest.raises(expected_exception=IndexError):
pop_config()

d0 = TestgresConfig.cached_initdb_dir
d1 = 'dummy_abc'
d2 = 'dummy_def'

with scoped_config(cached_initdb_dir=d1) as c1:
assert (c1.cached_initdb_dir == d1)

with scoped_config(cached_initdb_dir=d2) as c2:
stack_size = len(testgres.config.config_stack)

# try to break a stack
with pytest.raises(expected_exception=TypeError):
with scoped_config(dummy=True):
pass

assert (c2.cached_initdb_dir == d2)
assert (len(testgres.config.config_stack) == stack_size)

assert (c1.cached_initdb_dir == d1)

assert (TestgresConfig.cached_initdb_dir == d0)

def test_ports_management(self):
assert bound_ports is not None
assert type(bound_ports) == set # noqa: E721
Expand Down
38 changes: 2 additions & 36 deletions tests/test_testgres_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
InitNodeException, \
ExecUtilException

from ..testgres.config import \
TestgresConfig, \
configure_testgres, \
scoped_config, \
pop_config, testgres_config
from ..testgres.config import scoped_config
from ..testgres.config import testgres_config

from ..testgres import \
get_bin_path, \
Expand Down Expand Up @@ -168,37 +165,6 @@ def test_pg_config(self):
b = get_pg_config()
assert (id(a) != id(b))

def test_config_stack(self):
# no such option
with pytest.raises(expected_exception=TypeError):
configure_testgres(dummy=True)

# we have only 1 config in stack
with pytest.raises(expected_exception=IndexError):
pop_config()

d0 = TestgresConfig.cached_initdb_dir
d1 = 'dummy_abc'
d2 = 'dummy_def'

with scoped_config(cached_initdb_dir=d1) as c1:
assert (c1.cached_initdb_dir == d1)

with scoped_config(cached_initdb_dir=d2) as c2:
stack_size = len(testgres.config.config_stack)

# try to break a stack
with pytest.raises(expected_exception=TypeError):
with scoped_config(dummy=True):
pass

assert (c2.cached_initdb_dir == d2)
assert (len(testgres.config.config_stack) == 52D7 stack_size)

assert (c1.cached_initdb_dir == d1)

assert (TestgresConfig.cached_initdb_dir == d0)

@staticmethod
def helper__get_node(name=None):
svc = PostgresNodeServices.sm_remote
Expand Down
0