Skip to content

Commit dbf6626

Browse files
Merge pull request #209 from dmitry-lipetsk/D20250311_002--tests_on_alpine
[remote] Tests are updated to support Alpine Linux
2 parents ef5493f + cf6f4cc commit dbf6626

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

tests/test_local.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,17 @@ def test_exec_command_failure(self):
5757
try:
5858
self.operations.exec_command(cmd, wait_exit=True, shell=True)
5959
except ExecUtilException as e:
60-
assert e.message == "Utility exited with non-zero code (127). Error: `/bin/sh: 1: nonexistent_command: not found`"
60+
assert type(e.exit_code) == int # noqa: E721
61+
assert e.exit_code == 127
62+
63+
assert type(e.message) == str # noqa: E721
6164
assert type(e.error) == bytes # noqa: E721
62-
assert e.error.strip() == b"/bin/sh: 1: nonexistent_command: not found"
65+
66+
assert e.message.startswith("Utility exited with non-zero code (127). Error:")
67+
assert "nonexistent_command" in e.message
68+
assert "not found" in e.message
69+
assert b"nonexistent_command" in e.error
70+
assert b"not found" in e.error
6371
break
6472
raise Exception("We wait an exception!")
6573

@@ -73,9 +81,11 @@ def test_exec_command_failure__expect_error(self):
7381

7482
exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)
7583

76-
assert error == b'/bin/sh: 1: nonexistent_command: not found\n'
7784
assert exit_status == 127
7885
assert result == b''
86+
assert type(error) == bytes # noqa: E721
87+
assert b"nonexistent_command" in error
88+
assert b"not found" in error
7989

8090
def test_read__text(self):
8191
"""

tests/test_remote.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ def test_exec_command_failure(self):
4141
try:
4242
self.operations.exec_command(cmd, verbose=True, wait_exit=True)
4343
except ExecUtilException as e:
44-
assert e.message == "Utility exited with non-zero code (127). Error: `bash: line 1: nonexistent_command: command not found`"
44+
assert type(e.exit_code) == int # noqa: E721
45+
assert e.exit_code == 127
46+
47+
assert type(e.message) == str # noqa: E721
4548
assert type(e.error) == bytes # noqa: E721
46-
assert e.error.strip() == b"bash: line 1: nonexistent_command: command not found"
49+
50+
assert e.message.startswith("Utility exited with non-zero code (127). Error:")
51+
assert "nonexistent_command" in e.message
52+
assert "not found" in e.message
53+
assert b"nonexistent_command" in e.error
54+
assert b"not found" in e.error
4755
break
4856
raise Exception("We wait an exception!")
4957

@@ -55,9 +63,11 @@ def test_exec_command_failure__expect_error(self):
5563

5664
exit_status, result, error = self.operations.exec_command(cmd, verbose=True, wait_exit=True, shell=True, expect_error=True)
5765

58-
assert error == b'bash: line 1: nonexistent_command: command not found\n'
5966
assert exit_status == 127
6067
assert result == b''
68+
assert type(error) == bytes # noqa: E721
69+
assert b"nonexistent_command" in error
70+
assert b"not found" in error
6171

6272
def test_is_executable_true(self):
6373
"""
@@ -344,11 +354,13 @@ def test_read__unknown_file(self):
344354
Test RemoteOperations::read with unknown file.
345355
"""
346356

347-
with pytest.raises(
348-
ExecUtilException,
349-
match=re.escape("cat: /dummy: No such file or directory")):
357+
with pytest.raises(ExecUtilException) as x:
350358
self.operations.read("/dummy")
351359

360+
assert "Utility exited with non-zero code (1)." in str(x.value)
361+
assert "No such file or directory" in str(x.value)
362+
assert "/dummy" in str(x.value)
363+
352364
def test_read_binary__spec(self):
353365
"""
354366
Test RemoteOperations::read_binary.
@@ -388,9 +400,13 @@ def test_read_binary__spec__unk_file(self):
388400
Test RemoteOperations::read_binary with unknown file.
389401
"""
390402

391-
with pytest.raises(ExecUtilException, match=re.escape("tail: cannot open '/dummy' for reading: No such file or directory")):
403+
with pytest.raises(ExecUtilException) as x:
392404
self.operations.read_binary("/dummy", 0)
393405

406+
assert "Utility exited with non-zero code (1)." in str(x.value)
407+
assert "No such file or directory" in str(x.value)
408+
assert "/dummy" in str(x.value)
409+
394410
def test_read_binary__spec__negative_offset(self):
395411
"""
396412
Test RemoteOperations::read_binary with negative offset.
@@ -419,9 +435,13 @@ def test_get_file_size__unk_file(self):
419435
Test RemoteOperations::get_file_size.
420436
"""
421437

422-
with pytest.raises(ExecUtilException, match=re.escape("du: cannot access '/dummy': No such file or directory")):
438+
with pytest.raises(ExecUtilException) as x:
423439
self.operations.get_file_size("/dummy")
424440

441+
assert "Utility exited with non-zero code (1)." in str(x.value)
442+
assert "No such file or directory" in str(x.value)
443+
assert "/dummy" in str(x.value)
444+
425445
def test_touch(self):
426446
"""
427447
Test touch for creating a new file or updating access and modification times of an existing file.

tests/test_simple_remote.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
163163
("\"", "\""),
164164
]
165165

166+
errorIsDetected = False
167+
166168
for unkData in unkDatas:
167169
logging.info("----------------------")
168170
logging.info("Unk LANG is [{0}]".format(unkData[0]))
@@ -193,7 +195,10 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
193195
assert isinstance(exc, ExecUtilException)
194196

195197
if exc is None:
196-
raise Exception("We expected an error!")
198+
logging.warning("We expected an error!")
199+
continue
200+
201+
errorIsDetected = True
197202

198203
assert isinstance(exc, ExecUtilException)
199204

@@ -204,6 +209,9 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
204209
assert "initdb: error: invalid locale settings; check LANG and LC_* environment variables" in errMsg
205210
continue
206211

212+
if not errorIsDetected:
213+
pytest.xfail("All the bad data are processed without errors!")
214+
207215
finally:
208216
__class__.helper__restore_envvar("LANG", prev_LANG)
209217
__class__.helper__restore_envvar("LANGUAGE", prev_LANGUAGE)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy