Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gui-tests][full-ci] lint helper files #11884

Merged
merged 3 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test/gui/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ disable=
; TODO: enable later
invalid-name,
fail-under=10
ignore-paths=^tst_.*/test.py$|shared/scripts/names.py
ignored-modules=squish,object,objectmaphelper,test
ignore-paths=^tst_.*/test.py$,
shared/scripts/names.py,
shared/scripts/custom_lib
ignored-modules=
squish,
object,
objectmaphelper,
test,
requests,
psutil,
urllib3,
custom_lib.syncstate,
load-plugins=
pylint.extensions.check_elif,
pylint.extensions.bad_builtin,
Expand All @@ -37,6 +47,9 @@ method-naming-style=snake_case
module-naming-style=any
variable-naming-style=snake_case

[DESIGN]
max-args=8

[VARIABLES]
additional-builtins=
squish,
Expand Down
2 changes: 1 addition & 1 deletion test/gui/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PYTHON_LINT_PATHS:=./shared/scripts/pageObjects/* ./shared/steps/* ./shared/scripts/bdd_hooks.py
PYTHON_LINT_PATHS:="./**/*.py"

.PHONY: install
install: pnpm-install pnpm-install-chromium pip-install
Expand Down
3 changes: 1 addition & 2 deletions test/gui/shared/scripts/bdd_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from helpers.StacktraceHelper import getCoredumps, generateStacktrace
from helpers.SyncHelper import closeSocketConnection, clearWaitedAfterSync
from helpers.SpaceHelper import delete_project_spaces
from helpers.api.Provisioning import delete_created_groups, delete_created_users
from helpers.api.provisioning import delete_created_groups, delete_created_users
from helpers.SetupClientHelper import wait_until_app_killed
from helpers.ConfigHelper import (
init_config,
Expand Down Expand Up @@ -99,7 +99,6 @@ def hook(context):
+ context.title
+ "\n"
)
f.close()

# this path will be changed according to the user added to the client
# e.g.: /tmp/client-bdd/Alice
Expand Down
72 changes: 33 additions & 39 deletions test/gui/shared/scripts/helpers/ConfigHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def read_env_file():
envs = {}
script_path = os.path.dirname(os.path.realpath(__file__))
env_path = os.path.abspath(os.path.join(script_path, '..', '..', '..', 'envs.txt'))
with open(env_path, "rt", encoding="UTF-8") as f:
with open(env_path, 'rt', encoding='UTF-8') as f:
for line in f:
if not line.strip():
continue
Expand All @@ -24,19 +24,19 @@ def get_config_from_env_file(env):
envs = read_env_file()
if env in envs:
return envs[env]
raise Exception('Environment "%s" not found in envs.txt' % env)
raise KeyError(f'Environment "{env}" not found in envs.txt')


def isWindows():
return platform.system() == "Windows"
return platform.system() == 'Windows'


def isLinux():
return platform.system() == "Linux"
return platform.system() == 'Linux'


def getWinUserHome():
return os.environ.get("UserProfile")
return os.environ.get('UserProfile')


def getClientRootPath():
Expand All @@ -49,15 +49,14 @@ def getConfigHome():
if isWindows():
# There is no way to set custom config path in windows
# TODO: set to different path if option is available
return os.path.join(getWinUserHome(), "AppData", "Roaming", "ownCloud")
return os.path.join(get_config_from_env_file("XDG_CONFIG_HOME"), "ownCloud")
return os.path.join(getWinUserHome(), 'AppData', 'Roaming', 'ownCloud')
return os.path.join(get_config_from_env_file('XDG_CONFIG_HOME'), 'ownCloud')


def get_default_home_dir():
if isWindows():
return getWinUserHome()
elif isLinux():
return os.environ.get("HOME")
return os.environ.get('HOME')


# map environment variables to config keys
Expand Down Expand Up @@ -103,51 +102,49 @@ def get_default_home_dir():
READONLY_CONFIG = list(CONFIG_ENV_MAP.keys()) + list(DEFAULT_PATH_CONFIG.keys())


def read_cfg_file(cfg_path):
cfg = ConfigParser()
if cfg.read(cfg_path):
for key, _ in CONFIG.items():
if key in CONFIG_ENV_MAP:
if value := cfg.get('DEFAULT', CONFIG_ENV_MAP[key]):
if key in ('ocis', 'screenRecordOnFailure'):
CONFIG[key] = value == 'true'
else:
CONFIG[key] = value


def init_config():
global CONFIG, CONFIG_ENV_MAP
# try reading configs from config.ini
cfg = ConfigParser()
try:
script_path = os.path.dirname(os.path.realpath(__file__))
config_path = os.path.abspath(
cfg_path = os.path.abspath(
os.path.join(script_path, '..', '..', '..', 'config.ini')
)
if cfg.read(config_path):
for key, _ in CONFIG.items():
if key in CONFIG_ENV_MAP:
value = cfg.get('DEFAULT', CONFIG_ENV_MAP[key])
if value:
if key == 'ocis' or key == 'screenRecordOnFailure':
CONFIG[key] = value == 'true'
else:
CONFIG[key] = value
except Exception:
read_cfg_file(cfg_path)
except:
pass

# read and override configs from environment variables
for key, value in CONFIG_ENV_MAP.items():
if os.environ.get(value):
if key == 'ocis' or key == 'screenRecordOnFailure':
if key in ('ocis', 'screenRecordOnFailure'):
CONFIG[key] = os.environ.get(value) == 'true'
else:
CONFIG[key] = os.environ.get(value)

# Set the default values if empty
for key, value in CONFIG.items():
if key == 'maxSyncTimeout' or key == 'minSyncTimeout':
if key in ('maxSyncTimeout', 'minSyncTimeout'):
CONFIG[key] = builtins.int(value)
elif (
key == 'localBackendUrl'
or key == 'middlewareUrl'
or key == 'secureLocalBackendUrl'
):
elif key in ('localBackendUrl', 'middlewareUrl', 'secureLocalBackendUrl'):
# make sure there is always one trailing slash
CONFIG[key] = value.rstrip('/') + '/'
elif (
key == 'clientRootSyncPath'
or key == 'tempFolderPath'
or key == 'clientConfigDir'
or key == 'guiTestReportDir'
elif key in (
'clientRootSyncPath',
'tempFolderPath',
'clientConfigDir',
'guiTestReportDir',
):
# make sure there is always one trailing slash
if isWindows():
Expand All @@ -158,22 +155,19 @@ def init_config():


def get_config(key=None):
global CONFIG
if key:
return CONFIG[key]
return CONFIG


def set_config(key, value):
global CONFIG, READONLY_CONFIG
if key in READONLY_CONFIG:
raise Exception('Cannot set read-only config: %s' % key)
raise KeyError(f'Cannot set read-only config: {key}')
CONFIG[key] = value
return CONFIG


def clear_scenario_config():
global CONFIG, READONLY_CONFIG
global CONFIG
initial_config = {}
for key in READONLY_CONFIG:
initial_config[key] = CONFIG[key]
Expand Down
51 changes: 24 additions & 27 deletions test/gui/shared/scripts/helpers/FilesHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
import re
import ctypes
import shutil

from helpers.ConfigHelper import isWindows


def buildConflictedRegex(filename):
if '.' in filename:
if "." in filename:
# TODO: improve this for complex filenames
namepart = filename.split('.')[0]
extpart = filename.split('.')[1]
return '%s \(conflicted copy \d{4}-\d{2}-\d{2} \d{6}\)\.%s' % (
namepart = filename.split(".")[0]
extpart = filename.split(".")[1]
# pylint: disable=anomalous-backslash-in-string
return "%s \(conflicted copy \d{4}-\d{2}-\d{2} \d{6}\)\.%s" % (
namepart,
extpart,
)
return '%s \(conflicted copy \d{4}-\d{2}-\d{2} \d{6}\)' % (filename)
# pylint: disable=anomalous-backslash-in-string
return "%s \(conflicted copy \d{4}-\d{2}-\d{2} \d{6}\)" % filename


def sanitizePath(path):
return path.replace('//', '/')
return path.replace("//", "/")


def prefix_path_namespace(path):
Expand All @@ -27,36 +30,33 @@ def prefix_path_namespace(path):
# disable string parsing
# - long path
# - trailing whitespaces
return '\\\\?\\' + path
return f"\\\\?\\{path}"
return path


def can_read(resource):
can_read = False
read = False
try:
f = open(resource)
f.close()
can_read = True
with open(resource, encoding="utf-8") as f:
read = True
except:
pass
return can_read and os.access(resource, os.R_OK)
return read and os.access(resource, os.R_OK)


def can_write(resource):
can_write = False
write = False
try:
f = open(resource, 'w')
f.close()
can_write = True
with open(resource, "w", encoding="utf-8") as f:
write = True
except:
pass
return can_write and os.access(resource, os.W_OK)
return write and os.access(resource, os.W_OK)


def read_file_content(file):
f = open(file, "r")
content = f.read()
f.close()
with open(file, "r", encoding="utf-8") as f:
content = f.read()
return content


Expand All @@ -75,9 +75,9 @@ def get_size_in_bytes(size):
multiplier = 1024
if match:
size_num = int(match.group(1))
size_unit = match.group(2).lower()
size_unit = match.group(2)

if not size_unit:
if not (size_unit := size_unit.lower()):
return size_num
if size_unit in units:
if size_unit == "b":
Expand All @@ -89,7 +89,7 @@ def get_size_in_bytes(size):
if size_unit == "gb":
return size_num * (multiplier**3)

raise Exception("Invalid size: " + size)
raise ValueError("Invalid size: " + size)


def get_file_size_on_disk(resource_path):
Expand All @@ -98,9 +98,7 @@ def get_file_size_on_disk(resource_path):
return ctypes.windll.kernel32.GetCompressedFileSizeW(
ctypes.c_wchar_p(resource_path), ctypes.pointer(file_size_high)
)
raise Exception(
"'get_file_size_on_disk' function is only supported for Windows OS."
)
raise OSError("'get_file_size_on_disk' function is only supported for Windows OS.")


def get_file_size(resource_path):
Expand All @@ -112,7 +110,6 @@ def get_file_size(resource_path):


def remember_path(path):
global CREATED_PATHS
CREATED_PATHS.append(path)


Expand Down
2 changes: 0 additions & 2 deletions test/gui/shared/scripts/helpers/ObjectHelper.py

This file was deleted.

Loading