10000 A support of Python 3.8 [import] · postgrespro/testgres@96ddf19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 96ddf19

Browse files
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!
1 parent 1618d7c commit 96ddf19

File tree

9 files changed

+166
-67
lines changed

9 files changed

+166
-67
lines changed

testgres/plugins/pg_probackup2/pg_probackup2/tests/test_basic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import shutil
55
import pytest
66

7-
from ...... import testgres
7+
try:
8+
# Python 3.8
9+
import testgres
10+
except ImportError:
11+
from ...... import testgres
12+
813
from ...pg_probackup2.app import ProbackupApp
914
from ...pg_probackup2.init_helpers import Init, init_params
1015
from ..storage.fs_backup import FSTestBackupDir

tests/helpers/global_data.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
from ...testgres.operations.os_ops import OsOperations
2-
from ...testgres.operations.os_ops import ConnectionParams
3-
from ...testgres.operations.local_ops import LocalOperations
4-
from ...testgres.operations.remote_ops import RemoteOperations
5-
6-
from ...testgres.node import PortManager
7-
from ...testgres.node import PortManager__ThisHost
8-
from ...testgres.node import PortManager__Generic
1+
try:
2+
# Python 3.8
3+
from testgres.operations.os_ops import OsOperations
4+
from testgres.operations.os_ops import ConnectionParams
5+
from testgres.operations.local_ops import LocalOperations
6+
from testgres.operations.remote_ops import RemoteOperations
7+
8+
from testgres.port_manager import PortManager
9+
from testgres.port_manager import PortManager__ThisHost
10+
from testgres.port_manager import PortManager__Generic
11+
except ImportError:
12+
from ...testgres.operations.os_ops import OsOperations
13+
from ...testgres.operations.os_ops import ConnectionParams
14+
from ...testgres.operations.local_ops import LocalOperations
15+
from ...testgres.operations.remote_ops import RemoteOperations
16+
17+
from ...testgres.port_manager import PortManager
18+
from ...testgres.port_manager import PortManager__ThisHost
19+
from ...testgres.port_manager import PortManager__Generic
920

1021
import os
1122

tests/test_config.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from ..testgres import TestgresConfig
2-
from ..testgres import configure_testgres
3-
from ..testgres import scoped_config
4-
from ..testgres import pop_config
5-
6-
from .. import testgres
1+
try:
2+
# Python 3.8
3+
import testgres
4+
5+
from testgres.config import TestgresConfig
6+
from testgres import configure_testgres
7+
from testgres import scoped_config
8+
from testgres import pop_config
9+
except ImportError:
10+
from .. import testgres
11+
12+
from ..testgres.config import TestgresConfig
13+
from ..testgres import configure_testgres
14+
from ..testgres import scoped_config
15+
from ..testgres import pop_config
716

817
import pytest
918

tests/test_os_ops_common.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
from .helpers.global_data import OsOperations
55
from .helpers.run_conditions import RunConditions
66

7+
try:
8+
# Python 3.8
9+
from testgres import InvalidOperationException
10+
from testgres import ExecUtilException
11+
except ImportError:
12+
from ..testgres import InvalidOperationException
13+
from ..testgres import ExecUtilException
14+
715
import os
816

917
import pytest
@@ -14,9 +22,6 @@
1422
import threading
1523
import typing
1624

17-
from ..testgres import InvalidOperationException
18-
from ..testgres import ExecUtilException
19-
2025

2126
class TestOsOpsCommon:
2227
sm_os_ops_descrs: typing.List[OsOpsDescr] = [

tests/test_os_ops_remote.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from .helpers.global_data import OsOpsDescrs
44
from .helpers.global_data import OsOperations
55

6-
from ..testgres import ExecUtilException
6+
try:
7+
# Python 3.8
8+
from testgres import ExecUtilException
9+
except ImportError:
10+
from ..testgres import ExecUtilException
711

812
import os
913
import pytest

tests/test_testgres_common.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,56 @@
33
from .helpers.global_data import OsOperations
44
from .helpers.global_data import PortManager
55

6-
from ..testgres.node import PgVer
7-
from ..testgres.node import PostgresNode
8-
from ..testgres.utils import get_pg_version2
9-
from ..testgres.utils import file_tail
10-
from ..testgres.utils import get_bin_path2
11-
from ..testgres import ProcessType
12-
from ..testgres import NodeStatus
13-
from ..testgres import IsolationLevel
14-
15-
# New name prevents to collect test-functions in TestgresException and fixes
16-
# the problem with pytest warning.
17-
from ..testgres import TestgresException as testgres_TestgresException
18-
19-
from ..testgres import InitNodeException
20-
from ..testgres import StartNodeException
21-
from ..testgres import QueryException
22-
from ..testgres import ExecUtilException
23-
from ..testgres import TimeoutException
24-
from ..testgres import InvalidOperationException
25-
from ..testgres import BackupException
26-
from ..testgres import ProgrammingError
27-
from ..testgres import scoped_config
28-
from ..testgres import First, Any
6+
try:
7+
# Python 3.8
8+
from testgres.node import PgVer
9+
from testgres.node import PostgresNode
10+
from testgres.utils import get_pg_version2
11+
from testgres.utils import file_tail
12+
from testgres.utils import get_bin_path2
13+
from testgres import ProcessType
14+
from testgres import NodeStatus
15+
from testgres import IsolationLevel
16+
17+
# New name prevents to collect test-functions in TestgresException and fixes
18+
# the problem with pytest warning.
19+
from testgres import TestgresException as testgres_TestgresException
20+
21+
from testgres import InitNodeException
22+
from testgres import StartNodeException
23+
from testgres import QueryException
24+
from testgres import ExecUtilException
25+
from testgres import TimeoutException
26+
from testgres import InvalidOperationException
27+
from testgres import BackupException
28+
from testgres import ProgrammingError
29+
from testgres import scoped_config
30+
from testgres import First, Any
31+
32+
except ImportError:
33+
from ..testgres.node import PgVer
34+
from ..testgres.node import PostgresNode
35+
from ..testgres.utils import get_pg_version2
36+
from ..testgres.utils import file_tail
37+
from ..testgres.utils import get_bin_path2
38+
from ..testgres import ProcessType
39+
from ..testgres import NodeStatus
40+
from ..testgres import IsolationLevel
41+
42+
# New name prevents to collect test-functions in TestgresException and fixes
43+
# the problem with pytest warning.
44+
from ..testgres import TestgresException as testgres_TestgresException
45+
46+
from ..testgres import InitNodeException
47+
from ..testgres import StartNodeException
48+
from ..testgres import QueryException
49+
from ..testgres import ExecUtilException
50+
from ..testgres import TimeoutException
51+
from ..testgres import InvalidOperationException
52+
from ..testgres import BackupException
53+
from ..testgres import ProgrammingError
54+
from ..testgres import scoped_config
55+
from ..testgres import First, Any
2956

3057
from contextlib import contextmanager
3158

tests/test_testgres_local.py

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,40 @@
77
import platform
88
import logging
99

10-
from .. import testgres
11-
12-
from ..testgres import StartNodeException
13-
from ..testgres import ExecUtilException
14-
from ..testgres import NodeApp
15-
from ..testgres import scoped_config
16-
from ..testgres import get_new_node
17-
from ..testgres import get_bin_path
18-
from ..testgres import get_pg_config
19-
from ..testgres import get_pg_version
20-
21-
# NOTE: those are ugly imports
22-
from ..testgres.utils import bound_ports
23-
from ..testgres.utils import PgVer
24-
from ..testgres.node import ProcessProxy
10+
11+
try:
12+
# Python 3.8
13+
import testgres
14+
15+
from testgres import StartNodeException
16+
from testgres import ExecUtilException
17+
from testgres import NodeApp
18+
from testgres import scoped_config
19+
from testgres import get_new_node
20+
from testgres import get_bin_path
21+
from testgres import get_pg_config
22+
from testgres import get_pg_version
23+
24+
# NOTE: those are ugly imports
25+
from testgres.utils import bound_ports
26+
from testgres.utils import PgVer
27+
from testgres.node import ProcessProxy
28+
except ImportError:
29+
from .. import testgres
30+
31+
from ..testgres import StartNodeException
32+
from ..testgres import ExecUtilException
33+
from ..testgres import NodeApp
34+
from ..testgres import scoped_config
35+
from ..testgres import get_new_node
36+
from ..testgres import get_bin_path
37+
from ..testgres import get_pg_config
38+
from ..testgres import get_pg_version
39+
40+
# NOTE: those are ugly imports
41+
from ..testgres.utils import bound_ports
42+
from ..testgres.utils import PgVer
43+
from ..testgres.node import ProcessProxy
2544

2645

2746
def pg_version_ge(version):

tests/test_testgres_remote.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@
77
from .helpers.global_data import PostgresNodeService
88
from .helpers.global_data import PostgresNodeServices
99

10-
from .. import testgres
10+
try:
11+
# Python 3.8
12+
import testgres
1113

12-
from ..testgres.exceptions import InitNodeException
13-
from ..testgres.exceptions import ExecUtilException
14+
from testgres.exceptions import InitNodeException
15+
from testgres.exceptions import ExecUtilException
1416

15-
from ..testgres.config import scoped_config
16-
from ..testgres.config import testgres_config
17+
from testgres.config import scoped_config
18+
from testgres.config import testgres_config
1719

18-
from ..testgres import get_bin_path
19-
from ..testgres import get_pg_config
20+
from testgres import get_bin_path
21+
from testgres import get_pg_config
22+
except ImportError:
23+
from .. import testgres
24+
25+
from ..testgres.exceptions import InitNodeException
26+
from ..testgres.exceptions import ExecUtilException
27+
28+
from ..testgres.config import scoped_config
29+
from ..testgres.config import testgres_config
30+
31+
from ..testgres import get_bin_path
32+
from ..testgres import get_pg_config
2033

2134
# NOTE: those are ugly imports
2235

tests/test_utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
from .helpers.global_data import OsOpsDescrs
33
from .helpers.global_data import OsOperations
44

5-
from ..testgres.utils import parse_pg_version
6-
from ..testgres.utils import get_pg_config2
7-
from ..testgres import scoped_config
5+
try:
6+
# Python 3.8
7+
from testgres.utils import parse_pg_version
8+
from testgres.utils import get_pg_config2
9+
from testgres import scoped_config
10+
except ImportError:
11+
from ..testgres.utils import parse_pg_version
12+
from ..testgres.utils import get_pg_config2
13+
from ..testgres import scoped_config
814

915
import pytest
1016
import typing

0 commit comments

Comments
 (0)
0