8000 A support of Python v3.8 by dmitry-lipetsk · Pull Request #238 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

A support of Python v3.8 #238

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
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
A support of Python 3.8 [import]
This commit fixes a problem with imports.

As I understand 3.8 has a problem with import across root-directory and I do not know/find how to fix it correctly.

If someone know how to resolve these problems more easily (through sys.path/__init__.py?) - you are welcome!
  • Loading branch information
dmitry-lipetsk committed Apr 8, 2025
commit 96ddf19fa5218f79b2a7f9d58753ac6200eae795
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import shutil
import pytest

from ...... import testgres
try:
# Python 3.8
import testgres
except ImportError:
from ...... import testgres

from ...pg_probackup2.app import ProbackupApp
from ...pg_probackup2.init_helpers import Init, init_params
from ..storage.fs_backup import FSTestBackupDir
Expand Down
27 changes: 19 additions & 8 deletions tests/helpers/global_data.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
from ...testgres.operations.os_ops import OsOperations
from ...testgres.operations.os_ops import ConnectionParams
from ...testgres.operations.local_ops import LocalOperations
from ...testgres.operations.remote_ops import RemoteOperations

from ...testgres.node import PortManager
from ...testgres.node import PortManager__ThisHost
from ...testgres.node import PortManager__Generic
try:
# Python 3.8
from testgres.operations.os_ops import OsOperations
from testgres.operations.os_ops import ConnectionParams
from testgres.operations.local_ops import LocalOperations
from testgres.operations.remote_ops import RemoteOperations

from testgres.port_manager import PortManager
from testgres.port_manager import PortManager__ThisHost
from testgres.port_manager import PortManager__Generic
except ImportError:
from ...testgres.operations.os_ops import OsOperations
from ...testgres.operations.os_ops import ConnectionParams
from ...testgres.operations.local_ops import LocalOperations
from ...testgres.operations.remote_ops import RemoteOperations

from ...testgres.port_manager import PortManager
from ...testgres.port_manager import PortManager__ThisHost
from ...testgres.port_manager import PortManager__Generic

import os

Expand Down
21 changes: 15 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
from ..testgres import TestgresConfig
from ..testgres import configure_testgres
from ..testgres import scoped_config
from ..testgres import pop_config

from .. import testgres
try:
# Python 3.8
import testgres

from testgres.config import TestgresConfig
from testgres import configure_testgres
from testgres import scoped_config
from testgres import pop_config
except ImportError:
from .. import testgres

from ..testgres.config import TestgresConfig
from ..testgres import configure_testgres
from ..testgres import scoped_config
from ..testgres import pop_config

import pytest

Expand Down
11 changes: 8 additions & 3 deletions tests/test_os_ops_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
from .helpers.global_data import OsOperations
from .helpers.run_conditions import RunConditions

try:
# Python 3.8
from testgres import InvalidOperationException
from testgres import ExecUtilException
except ImportError:
from ..testgres import InvalidOperationException
from ..testgres import ExecUtilException

import os

import pytest
Expand All @@ -14,9 +22,6 @@
import threading
import typing

from ..testgres import InvalidOperationException
from ..testgres import ExecUtilException


class TestOsOpsCommon:
sm_os_ops_descrs: typing.List[OsOpsDescr] = [
Expand Down
6 changes: 5 additions & 1 deletion tests/test_os_ops_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from .helpers.global_data import OsOpsDescrs
from .helpers.global_data import OsOperations

from ..testgres import ExecUtilException
try:
# Python 3.8
from testgres import ExecUtilException
except ImportError:
from ..testgres import ExecUtilException

import os
import pytest
Expand Down
73 changes: 50 additions & 23 deletions tests/test_testgres_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,56 @@
from .helpers.global_data import OsOperations
from .helpers.global_data import PortManager

from ..testgres.node import PgVer
from ..testgres.node import PostgresNode
from ..testgres.utils import get_pg_version2
from ..testgres.utils import file_tail
from ..testgres.utils import get_bin_path2
from ..testgres import ProcessType
from ..testgres import NodeStatus
from ..testgres import IsolationLevel

# New name prevents to collect test-functions in TestgresException and fixes
# the problem with pytest warning.
from ..testgres import TestgresException as testgres_TestgresException

from ..testgres import InitNodeException
from ..testgres import StartNodeException
from ..testgres import QueryException
from ..testgres import ExecUtilException
from ..testgres import TimeoutException
from ..testgres import InvalidOperationException
from ..testgres import BackupException
from ..testgres import ProgrammingError
from ..testgres import scoped_config
from ..testgres import First, Any
try:
# Python 3.8
from testgres.node import PgVer
from testgres.node import PostgresNode
from testgres.utils import get_pg_version2
from testgres.utils import file_tail
from testgres.utils import get_bin_path2
from testgres import ProcessType
from testgres import NodeStatus
from testgres import IsolationLevel

# New name prevents to collect test-functions in TestgresException and fixes
# the problem with pytest warning.
from testgres import TestgresException as testgres_TestgresException

from testgres import InitNodeException
from testgres import StartNodeException
from testgres import QueryException
from testgres import ExecUtilException
from testgres import TimeoutException
from testgres import InvalidOperationException
from testgres import BackupException
from testgres import ProgrammingError
from testgres import scoped_config
from testgres import First, Any

except ImportError:
from ..testgres.node import PgVer
from ..testgres.node import PostgresNode
from ..testgres.utils import get_pg_version2
from ..testgres.utils import file_tail
from ..testgres.utils import get_bin_path2
from ..testgres import ProcessType
from ..testgres import NodeStatus
from ..testgres import IsolationLevel

# New name prevents to collect test-functions in TestgresException and fixes
# the problem with pytest warning.
from ..testgres import TestgresException as testgres_TestgresException

from ..testgres import InitNodeException
from ..testgres import StartNodeException
from ..testgres import QueryException
from ..testgres import ExecUtilException
from ..testgres import TimeoutException
from ..testgres import InvalidOperationException
from ..testgres import BackupException
from ..testgres import ProgrammingError
from ..testgres import scoped_config
from ..testgres import First, Any

from contextlib import contextmanager

Expand Down
49 changes: 34 additions & 15 deletions tests/test_testgres_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,40 @@
import platform
import logging

from .. import testgres

from ..testgres import StartNodeException
from ..testgres import ExecUtilException
from ..testgres import NodeApp
from ..testgres import scoped_config
from ..testgres import get_new_node
from ..testgres import get_bin_path
from ..testgres import get_pg_config
from ..testgres import get_pg_version

# NOTE: those are ugly imports
from ..testgres.utils import bound_ports
from ..testgres.utils import PgVer
from ..testgres.node import ProcessProxy

try:
# Python 3.8
import testgres

from testgres import StartNodeException
from testgres import ExecUtilException
from testgres import NodeApp
from testgres import scoped_config
from testgres import get_new_node
from testgres import get_bin_path
from testgres import get_pg_config
from testgres import get_pg_version

# NOTE: those are ugly imports
from testgres.utils import bound_ports
from testgres.utils import PgVer
from testgres.node import ProcessProxy
except ImportError:
from .. import testgres

from ..testgres import StartNodeException
from ..testgres import ExecUtilException
from ..testgres import NodeApp
from ..testgres import scoped_config
from ..testgres import get_new_node
from ..testgres import get_bin_path
from ..testgres import get_pg_config
from ..testgres import get_pg_version

# NOTE: those are ugly imports
from ..testgres.utils import bound_ports
from ..testgres.utils import PgVer
from ..testgres.node import ProcessProxy


def pg_version_ge(version):
Expand Down
27 changes: 20 additions & 7 deletions tests/test_testgres_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
from .helpers.global_data import PostgresNodeService
from .helpers.global_data import PostgresNodeServices

from .. import testgres
try:
# Python 3.8
import testgres

from ..testgres.exceptions import InitNodeException
from ..testgres.exceptions import ExecUtilException
from testgres.exceptions import InitNodeException
from testgres.exceptions import ExecUtilException

from ..testgres.config import scoped_config
from ..testgres.config import testgres_config
from testgres.config import scoped_config
from testgres.config import testgres_config

from ..testgres import get_bin_path
from ..testgres import get_pg_config
from testgres import get_bin_path
from testgres import get_pg_config
except ImportError:
from .. import testgres

from ..testgres.exceptions import InitNodeException
from ..testgres.exceptions import ExecUtilException

from ..testgres.config import scoped_config
from ..testgres.config import testgres_config

from ..testgres import get_bin_path
from ..testgres import get_pg_config

# NOTE: those are ugly imports

Expand Down
12 changes: 9 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
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
try:
# Python 3.8
from testgres.utils import parse_pg_version
from testgres.utils import get_pg_config2
from testgres import scoped_config
except ImportError:
from ..testgres.utils import parse_pg_version
from ..testgres.utils import get_pg_config2
from ..testgres import scoped_config

import pytest
import typing
Expand Down
0