Fix imports

Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
Katarzyna Treder
2024-12-13 15:18:42 +01:00
parent fd869a0afc
commit 5bd6a656c5
37 changed files with 170 additions and 231 deletions

View File

@@ -0,0 +1,4 @@
#
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

View File

@@ -1,5 +1,6 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#

View File

@@ -1,10 +1,12 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
from core.test_run import TestRun
from test_tools import fs_tools
from test_tools.fs_tools import check_if_directory_exists
from test_tools.fs_tools import check_if_directory_exists, parse_ls_output, ls_item, ls
from test_utils.filesystem.fs_item import FsItem
@@ -13,14 +15,14 @@ class Directory(FsItem):
FsItem.__init__(self, full_path)
def ls(self):
output = fs_tools.ls(f"{self.full_path}")
return fs_tools.parse_ls_output(output, self.full_path)
output = ls(self.full_path)
return parse_ls_output(output, self.full_path)
@staticmethod
def create_directory(path: str, parents: bool = False):
fs_tools.create_directory(path, parents)
output = fs_tools.ls_item(path)
return fs_tools.parse_ls_output(output)[0]
output = ls_item(path)
return parse_ls_output(output)[0]
@staticmethod
def create_temp_directory(parent_dir_path: str = "/tmp"):

View File

@@ -3,10 +3,13 @@
# Copyright(c) 2023-2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
from datetime import timedelta
from test_tools import fs_tools
from test_tools.dd import Dd
from test_tools.fs_tools import read_file, write_file, ls_item, parse_ls_output, remove, \
check_if_directory_exists
from test_utils.filesystem.fs_item import FsItem
from type_def.size import Size
@@ -28,10 +31,10 @@ class File(FsItem):
return fs_tools.crc32sum(str(self), timeout)
def read(self):
return fs_tools.read_file(str(self))
return read_file(str(self))
def write(self, content, overwrite: bool = True):
fs_tools.write_file(str(self), content, overwrite)
write_file(str(self), content, overwrite)
self.refresh_item()
def get_properties(self):
@@ -40,8 +43,8 @@ class File(FsItem):
@staticmethod
def create_file(path: str):
fs_tools.create_file(path)
output = fs_tools.ls_item(path)
return fs_tools.parse_ls_output(output)[0]
output = ls_item(path)
return parse_ls_output(output)[0]
def padding(self, size: Size):
dd = Dd().input("/dev/zero").output(self).count(1).block_size(size)
@@ -49,7 +52,7 @@ class File(FsItem):
self.refresh_item()
def remove(self, force: bool = False, ignore_errors: bool = False):
fs_tools.remove(str(self), force=force, ignore_errors=ignore_errors)
remove(str(self), force=force, ignore_errors=ignore_errors)
def copy(self,
destination,
@@ -58,17 +61,17 @@ class File(FsItem):
dereference: bool = False,
timeout: timedelta = timedelta(minutes=30)):
fs_tools.copy(str(self), destination, force, recursive, dereference, timeout)
if fs_tools.check_if_directory_exists(destination):
if check_if_directory_exists(destination):
path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
else:
path = destination
output = fs_tools.ls_item(path)
return fs_tools.parse_ls_output(output)[0]
output = ls_item(path)
return parse_ls_output(output)[0]
class FileProperties:
def __init__(self, file):
file = fs_tools.parse_ls_output(fs_tools.ls_item(file.full_path))[0]
file = parse_ls_output(ls_item(file.full_path))[0]
self.full_path = file.full_path
self.parent_dir = FsItem.get_parent_dir(self.full_path)
self.name = FsItem.get_name(self.full_path)

View File

@@ -1,11 +1,14 @@
#
# Copyright(c) 2019-2021 Intel Corporation
# Copyright(c) 2024 Huawei Technologies Co., Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#
import posixpath
from test_tools import fs_tools
from test_tools.fs_tools import Permissions, PermissionsUsers, PermissionSign, \
check_if_directory_exists, ls_item, parse_ls_output
class FsItem:
@@ -42,9 +45,9 @@ class FsItem:
self.refresh_item()
def chmod(self,
permissions: fs_tools.Permissions,
users: fs_tools.PermissionsUsers,
sign: fs_tools.PermissionSign = fs_tools.PermissionSign.set,
permissions: Permissions,
users: PermissionsUsers,
sign: PermissionSign = PermissionSign.set,
recursive: bool = False):
fs_tools.chmod(self.full_path, permissions, users, sign=sign, recursive=recursive)
self.refresh_item()
@@ -58,19 +61,19 @@ class FsItem:
force: bool = False,
recursive: bool = False,
dereference: bool = False):
target_dir_exists = fs_tools.check_if_directory_exists(destination)
target_dir_exists = check_if_directory_exists(destination)
fs_tools.copy(str(self), destination, force, recursive, dereference)
if target_dir_exists:
path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
else:
path = destination
output = fs_tools.ls_item(f"{path}")
return fs_tools.parse_ls_output(output)[0]
output = ls_item(f"{path}")
return parse_ls_output(output)[0]
def move(self,
destination,
force: bool = False):
target_dir_exists = fs_tools.check_if_directory_exists(destination)
target_dir_exists = check_if_directory_exists(destination)
fs_tools.move(str(self), destination, force)
if target_dir_exists:
self.full_path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
@@ -80,7 +83,7 @@ class FsItem:
return self
def refresh_item(self):
updated_file = fs_tools.parse_ls_output(fs_tools.ls_item(self.full_path))[0]
updated_file = parse_ls_output(ls_item(self.full_path))[0]
# keep order the same as in __init__()
self.parent_dir = updated_file.parent_dir
self.name = updated_file.name