Skip to content

Commit e33e884

Browse files
TestTestgresRemote::test_init__unk_LANG_and_LC_CTYPE is updated (#400)
- It fails on PG10 - On a real remote machine we get message from dbinit only (warning from setlocale is optional)
1 parent a1427d0 commit e33e884

1 file changed

Lines changed: 31 additions & 9 deletions

File tree

tests/test_testgres_remote.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
# NOTE: those are ugly imports
2323

24+
from packaging.version import Version
25+
2426

2527
def util_exists(util):
2628
def good_properties(f):
@@ -72,6 +74,16 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
7274
prev_LC_CTYPE = os.environ.get("LC_CTYPE")
7375
prev_LC_COLLATE = os.environ.get("LC_COLLATE")
7476

77+
node = __class__.helper__get_node()
78+
79+
node_version = node.version
80+
assert node_version is not None
81+
assert type(node_version) is testgres.utils.PgVer
82+
assert isinstance(node_version, Version)
83+
84+
if node.version < Version("11"):
85+
pytest.skip("This test does not work on old PG10-.")
86+
7587
try:
7688
# TODO: Pass unkData through test parameter.
7789
unkDatas = [
@@ -106,14 +118,15 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
106118
assert os.getenv('LC_CTYPE') == unkData[1]
107119
assert os.getenv('LC_COLLATE') is None
108120

121+
node.cleanup()
122+
109123
exc: typing.Optional[BaseException] = None
110-
with __class__.helper__get_node() as node:
111-
try:
112-
node.init() # IT RAISES!
113-
except InitNodeException as e:
114-
exc = e.__cause__
115-
assert exc is not None
116-
assert isinstance(exc, ExecUtilException)
124+
try:
125+
node.init() # IT RAISES!
126+
except InitNodeException as e:
127+
exc = e.__cause__
128+
assert exc is not None
129+
assert isinstance(exc, ExecUtilException)
117130

118131
if exc is None:
119132
logging.warning("We expected an error!")
@@ -126,8 +139,17 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
126139
errMsg = str(exc)
127140
logging.info("Error message is {0}: {1}".format(type(exc).__name__, errMsg))
128141

129-
assert "warning: setlocale: LC_CTYPE: cannot change locale (" + unkData[1] + ")" in errMsg
130-
assert "initdb: error: invalid locale settings; check LANG and LC_* environment variables" in errMsg
142+
assert type(exc.error) is str
143+
144+
# Check an optional message from OS.
145+
expectedMsg1 = "warning: setlocale: LC_CTYPE: cannot change locale (" + unkData[1] + ")"
146+
147+
if expectedMsg1 not in exc.error:
148+
logging.warning("Msg does not contain {!r}.".format(expectedMsg1))
149+
150+
# Check a mandatory message from initdb.
151+
expectedMsg2 = "initdb: error: invalid locale settings; check LANG and LC_* environment variables"
152+
assert expectedMsg2 in exc.error
131153
continue
132154

133155
if not errorIsDetected:

0 commit comments

Comments
 (0)