diff --git a/src/local_ops.py b/src/local_ops.py index a1f5874..cb51682 100644 --- a/src/local_ops.py +++ b/src/local_ops.py @@ -626,3 +626,7 @@ def get_tempdir(self) -> str: assert type(r) is str assert os.path.exists(r) return r + + def get_dirname(self, path: str) -> str: + assert type(path) is str + return os.path.dirname(path) diff --git a/src/os_ops.py b/src/os_ops.py index 2f23648..8ba6983 100644 --- a/src/os_ops.py +++ b/src/os_ops.py @@ -177,3 +177,7 @@ def is_port_free(self, number: int): def get_tempdir(self) -> str: raise NotImplementedError() + + def get_dirname(self, path: str) -> str: + assert type(path) is str + raise NotImplementedError() diff --git a/src/remote_ops.py b/src/remote_ops.py index 92f77a4..b2b2efb 100644 --- a/src/remote_ops.py +++ b/src/remote_ops.py @@ -783,6 +783,10 @@ def get_tempdir(self) -> str: assert type(temp_dir) is str return temp_dir + def get_dirname(self, path: str) -> str: + assert type(path) is str + return posixpath.dirname(path) + @staticmethod def _build_cmdline(cmd, exec_env: typing.Dict = None) -> str: cmd_items = __class__._create_exec_env_list(exec_env) diff --git a/tests/test_os_ops_common.py b/tests/test_os_ops_common.py index e4b8278..0d74eba 100644 --- a/tests/test_os_ops_common.py +++ b/tests/test_os_ops_common.py @@ -1396,3 +1396,22 @@ def test_kill__unk_pid( RuntimeError("Unknown os_ops type: {}".format(type(os_ops).__name__)) return + + def test_get_dirname(self, os_ops: OsOperations): + assert isinstance(os_ops, OsOperations) + + p = __file__ + assert type(p) is str + assert p != "" + assert os.path.exists(p) + + expected_dirname = os.path.dirname(p) + assert type(expected_dirname) is str + assert expected_dirname != "" + + actual_dirname = os_ops.get_dirname(p) + assert type(actual_dirname) is str + assert actual_dirname != "" + + assert actual_dirname == expected_dirname + return