From e47cded2a784bfbc64c9a70aceedfe26f9a3b802 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Tue, 11 Mar 2025 10:27:59 +0300 Subject: [PATCH] [remote_ops] A problem with mktemp on Alpine Linux is fixed Five 'X' in template is not enough - Alpine returns "mktemp: : Invalid argument" error. Six 'X' is OK. --- testgres/operations/remote_ops.py | 4 ++-- tests/test_local.py | 17 +++++++++++++++++ tests/test_remote.py | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/testgres/operations/remote_ops.py b/testgres/operations/remote_ops.py index 767df567..11d9cd37 100644 --- a/testgres/operations/remote_ops.py +++ b/testgres/operations/remote_ops.py @@ -316,7 +316,7 @@ def mkdtemp(self, prefix=None): - prefix (str): The prefix of the temporary directory name. """ if prefix: - command = ["mktemp", "-d", "-t", prefix + "XXXXX"] + command = ["mktemp", "-d", "-t", prefix + "XXXXXX"] else: command = ["mktemp", "-d"] @@ -344,7 +344,7 @@ def mkstemp(self, prefix=None): - prefix (str): The prefix of the temporary directory name. """ if prefix: - command = ["mktemp", "-t", prefix + "XXXXX"] + command = ["mktemp", "-t", prefix + "XXXXXX"] else: command = ["mktemp"] diff --git a/tests/test_local.py b/tests/test_local.py index ee5e19a0..826c3f51 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -4,6 +4,7 @@ import pytest import re import tempfile +import logging from ..testgres import ExecUtilException from ..testgres import InvalidOperationException @@ -18,6 +19,22 @@ class TestLocalOperations: def setup(self): self.operations = LocalOperations() + def test_mkdtemp__default(self): + path = self.operations.mkdtemp() + logging.info("Path is [{0}].".format(path)) + assert os.path.exists(path) + os.rmdir(path) + assert not os.path.exists(path) + + def test_mkdtemp__custom(self): + C_TEMPLATE = "abcdef" + path = self.operations.mkdtemp(C_TEMPLATE) + logging.info("Path is [{0}].".format(path)) + assert os.path.exists(path) + assert C_TEMPLATE in os.path.basename(path) + os.rmdir(path) + assert not os.path.exists(path) + def test_exec_command_success(self): """ Test exec_command for successful command execution. diff --git a/tests/test_remote.py b/tests/test_remote.py index b1c4e58c..17c76c2c 100755 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -4,6 +4,7 @@ import pytest import re import tempfile +import logging from ..testgres import ExecUtilException from ..testgres import InvalidOperationException @@ -110,6 +111,22 @@ def test_makedirs_failure(self): with pytest.raises(Exception): self.operations.makedirs(path) + def test_mkdtemp__default(self): + path = self.operations.mkdtemp() + logging.info("Path is [{0}].".format(path)) + assert os.path.exists(path) + os.rmdir(path) + assert not os.path.exists(path) + + def test_mkdtemp__custom(self): + C_TEMPLATE = "abcdef" + path = self.operations.mkdtemp(C_TEMPLATE) + logging.info("Path is [{0}].".format(path)) + assert os.path.exists(path) + assert C_TEMPLATE in os.path.basename(path) + os.rmdir(path) + assert not os.path.exists(path) + def test_rmdirs(self): path = self.operations.mkdtemp() assert os.path.exists(path)