Skip to content

Commit

Permalink
behave: make linters happy
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup authored and xsuchy committed Oct 9, 2024
1 parent 8e51ccc commit 15c2b9b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions behave/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def _random_string(length):


def _download(context, url):
print('Downloading {}'.format(url))
req = requests.get(url)
print(f'Downloading {url}')
req = requests.get(url, timeout=60)
filename = os.path.join(context.workdir, os.path.basename(url))
with open(filename, 'wb') as dfd:
dfd.write(req.content)
Expand Down
4 changes: 3 additions & 1 deletion behave/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
# cyclic-import
# Seems like cyclic-import is just a style check which is not going to be
# fixed: https://github.com/PyCQA/pylint/issues/6983
disable=import-error,cyclic-import
# function-redefined
# This is a Behave's policy to create all step methods as `step_impl()`.
disable=import-error,cyclic-import,function-redefined
23 changes: 12 additions & 11 deletions behave/steps/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def _first_int(string, max_lines=20):
first_word = line.split()[0]
if first_word.isdigit():
return first_word
raise Exception("unexpected dnf history output")
raise RuntimeError("unexpected dnf history output")


def add_cleanup_last_transaction(context):
# TODO: DNF5 support https://github.com/rpm-software-management/dnf5/issues/140
# DNF5 support https://github.com/rpm-software-management/dnf5/issues/140
dnf = ["sudo", "/usr/bin/dnf-3", "-y", "history"]
_, out, _ = run(dnf + ["list"])
transaction_id = _first_int(out)
Expand All @@ -52,13 +52,14 @@ def _revert_transaction(_context):

context.add_cleanup(_revert_transaction, context)

@given(u'an unique mock namespace')

@given('an unique mock namespace')
def step_impl(context):
print("using uniqueext {}".format(context.uniqueext))
print(f"using uniqueext {context.uniqueext}")
context.uniqueext_used = True


@given(u'the {package} package {state} installed on host')
@given('the {package} package {state} installed on host')
def step_impl(context, package, state):
"""
Install the package, and uninstall in post- action. If state is "not", then
Expand Down Expand Up @@ -93,12 +94,12 @@ def _uninstall_pkg(_context):
context.add_cleanup(_uninstall_pkg, context)


@given(u'pre-intitialized chroot')
@given('pre-intitialized chroot')
def step_impl(context):
context.mock.init()


@given(u'a custom third-party repository is used for builds')
@given('a custom third-party repository is used for builds')
def step_impl(context):
context.add_repos.append(
"https://raw.githubusercontent.com/rpm-software-management/"
Expand All @@ -112,7 +113,7 @@ def step_impl(context):
run(["createrepo_c", context.local_repo])


@given(u'the local repo contains a "{rpm}" RPM')
@given('the local repo contains a "{rpm}" RPM')
def step_impl(context, rpm):
rpm = context.download_rpm(rpm)
shutil.move(rpm, context.local_repo)
Expand All @@ -124,14 +125,14 @@ def step_impl(context):
context.add_repos.append(context.local_repo)


@when(u'a build is depending on third-party repo requested')
@when(u'a build which requires the "always-installable" RPM is requested')
@when('a build is depending on third-party repo requested')
@when('a build which requires the "always-installable" RPM is requested')
def step_impl(context):
local_file = context.download_rpm("buildrequires-always-installable")
context.mock.rebuild([local_file])


@then(u'the build succeeds')
@then('the build succeeds')
def step_impl(context):
assert os.path.exists(context.mock.resultdir)
rpms = glob.glob(os.path.join(context.mock.resultdir, "*.rpm"))
Expand Down
25 changes: 13 additions & 12 deletions behave/testlib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ def run(cmd):
directly.
"""
try:
process = subprocess.Popen(
with subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)
stdout, stderr = process.communicate()
print(f"Command exit status {process.returncode} in: {quoted_cmd(cmd)}")
if stdout:
print("stdout:")
print(stdout)
if stderr:
print("stderr:")
print(stderr)
return process.returncode, stdout, stderr
) as process:
stdout, stderr = process.communicate()
print(f"Exit code: {process.returncode} in: {quoted_cmd(cmd)}")
if stdout:
print("stdout:")
print(stdout)
if stderr:
print("stderr:")
print(stderr)
return process.returncode, stdout, stderr
except (FileNotFoundError, PermissionError) as e:
print(f"Error running command {quoted_cmd(cmd)}: {e}")
return -1, "", str(e)
Expand All @@ -57,5 +57,6 @@ def run_check(cmd):
""" run, but check nonzero exit status """
retcode, stdout, stderr = run(cmd)
if retcode != 0:
raise Exception(f"Command failed with return code {retcode}: {quoted_cmd(cmd)}\n{stderr}")
raise RuntimeError(f"Command failed with return code {retcode}: "
f"{quoted_cmd(cmd)}\n{stderr}")
return stdout, stderr

0 comments on commit 15c2b9b

Please sign in to comment.