Skip to content
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
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dist
AUTHORS
ChangeLog
coverage.xml
flake8.report
junit*.xml
doc/build
.cache
34 changes: 11 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,18 @@ repos:
- id: check-merge-conflict
- id: debug-statements
language_version: python3
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
- repo: local
hooks:
- id: isort
args:
# https://github.com/pre-commit/mirrors-isort/issues/9#issuecomment-624404082
- --filter-files
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8.git
rev: 6.0.0
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-logging-format
- flake8-pep3101
- flake8-print
- id: ruff-check
name: ruff-check
entry: ruff check
language: system
types: [python]
- id: ruff-format
name: ruff
entry: ruff format --check --diff
language: system
types: [python]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
Expand Down
9 changes: 3 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ To run only some selected tests::
Code style
==========

Your code must pass without errors under `flake8
<https://flake8.readthedocs.io>`_ with the extension `hacking
<https://docs.openstack.org/hacking/latest/>`_::
Your code must pass without errors under `ruff <https://docs.astral.sh/ruff/>`_


pip install hacking
flake8 testinfra
pip install ruff
ruff check
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ recursive-include doc *.py *.rst *.svg
include doc/source/_templates/piwik.html
include doc/Makefile
include tox.ini
include .flake8
include mypy.ini
include Makefile
include *.yaml
Expand All @@ -15,6 +14,7 @@ include ansible.cfg
include dev-requirements.txt
include test-requirements.txt
include LICENSE
include *.toml
exclude .editorconfig
exclude .gitignore
prune doc/build
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

# General information about the project.
project = "testinfra"
copyright = "{}, Philippe Pepiot".format(datetime.date.today().year)
copyright = f"{datetime.date.today().year}, Philippe Pepiot"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
71 changes: 71 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
target-version = "py39"

[lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-debugger
"T10",
# flake8-logging
"G",
# flake8-comprehension
"C4",
# flake8-simplify
"SIM",
# flake8-print
"T20",
# individual rules
"RUF100", # unused-noqa
# imports
"I",
]

# For error codes, see https://docs.astral.sh/ruff/rules/#error-e
ignore = [
# argument is shadowing a Python builtin
"A001",
"A002",
"A005",
# attribute overriding builtin name
"A003",
# [bugbear] Do not use mutable data structures for argument defaults (I choose by myself)
"B006",
# [bugbear] Do not perform function calls in argument defaults (conflict with fastapi dependency system)
"B008",
# [bugbear] Function definition does not bind loop variable
"B023",
# closing bracket does not match indentation of opening bracket's line (disagree with emacs python mode)
# "E123",
# continuation line over-indented for hanging indent line (disagree with emacs python mode)
# "E126",
# whitespace before ':'
"E203",
# missing whitespace around arithmetic operator (disagree when in parameter)
"E226",
# line too long
"E501",
# multiple statements on one line (def) (not compatible with black)
# "E704",
# do not assign lambda expression (this is inconvenient)
"E731",
# Logging statement uses exception in arguments (seems legit to display only str representation of exc)
# "G200",
# [string-format] format string does contain unindexed parameters (don't care of py2.6)
# "P101",
# [string-format] docstring does contain unindexed parameters
# "P102",
# [string-format] other string does contain unindexed parameters
# "P103",
# Line break occurred before a binary operator (to keep operators aligned)
# "W503",
]

[lint.isort]
known-first-party = ["testinfra"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
56 changes: 25 additions & 31 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,27 @@ def has_docker():
def setup_ansible_config(tmpdir, name, host, user, port, key):
items = [
name,
"ansible_ssh_private_key_file={}".format(key),
'ansible_ssh_common_args="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL"', # noqa
f"ansible_ssh_private_key_file={key}",
'ansible_ssh_common_args="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL"',
"myvar=foo",
"ansible_host={}".format(host),
"ansible_user={}".format(user),
"ansible_port={}".format(port),
f"ansible_host={host}",
f"ansible_user={user}",
f"ansible_port={port}",
]
tmpdir.join("inventory").write("[testgroup]\n" + " ".join(items) + "\n")
tmpdir.mkdir("host_vars").join(name).write(ANSIBLE_HOSTVARS)
tmpdir.mkdir("group_vars").join("testgroup").write(
("---\n" "myhostvar: should_be_overriden\n" "mygroupvar: qux\n")
"---\nmyhostvar: should_be_overriden\nmygroupvar: qux\n"
)
vault_password_file = tmpdir.join("vault-pass.txt")
vault_password_file.write("polichinelle\n")
ansible_cfg = tmpdir.join("ansible.cfg")
ansible_cfg.write(
(
"[defaults]\n"
"vault_password_file={}\n"
"host_key_checking=False\n\n"
"[ssh_connection]\n"
"pipelining=True\n"
).format(str(vault_password_file))
"[defaults]\n"
f"vault_password_file={str(vault_password_file)}\n"
"host_key_checking=False\n\n"
"[ssh_connection]\n"
"pipelining=True\n"
)


Expand Down Expand Up @@ -119,7 +117,7 @@ def teardown():

return docker_id, docker_host, port

fname = "_docker_container_{}_{}".format(image, scope)
fname = f"_docker_container_{image}_{scope}"
mod = sys.modules[__name__]
setattr(mod, fname, func)

Expand Down Expand Up @@ -147,7 +145,7 @@ def host(request, tmpdir_factory):
else:
scope = "session"

fname = "_docker_container_{}_{}".format(spec.name, scope)
fname = f"_docker_container_{spec.name}_{scope}"
docker_id, docker_host, port = request.getfixturevalue(fname)

if kw["connection"] == "docker":
Expand All @@ -156,7 +154,8 @@ def host(request, tmpdir_factory):
hostname = spec.name
tmpdir = tmpdir_factory.mktemp(str(id(request)))
key = tmpdir.join("ssh_key")
key.write(open(os.path.join(BASETESTDIR, "ssh_key")).read())
with open(os.path.join(BASETESTDIR, "ssh_key")) as f:
key.write(f.read())
key.chmod(384) # octal 600
if kw["connection"] == "ansible":
setup_ansible_config(
Expand All @@ -168,26 +167,21 @@ def host(request, tmpdir_factory):
else:
ssh_config = tmpdir.join("ssh_config")
ssh_config.write(
(
"Host {}\n"
" Hostname {}\n"
" Port {}\n"
" UserKnownHostsFile /dev/null\n"
" StrictHostKeyChecking no\n"
" IdentityFile {}\n"
" IdentitiesOnly yes\n"
" LogLevel FATAL\n"
).format(hostname, docker_host, port, str(key))
f"Host {hostname}\n"
f" Hostname {docker_host}\n"
f" Port {port}\n"
" UserKnownHostsFile /dev/null\n"
" StrictHostKeyChecking no\n"
f" IdentityFile {str(key)}\n"
" IdentitiesOnly yes\n"
" LogLevel FATAL\n"
)
kw["ssh_config"] = str(ssh_config)

# Wait ssh to be up
service = testinfra.get_host(docker_id, connection="docker").service

if image == "rockylinux9":
service_name = "sshd"
else:
service_name = "ssh"
service_name = "sshd" if image == "rockylinux9" else "ssh"

while not service(service_name).is_running:
time.sleep(0.5)
Expand Down Expand Up @@ -232,7 +226,7 @@ def build_image(build_failed, dockerfile, image, image_path):
"-f",
dockerfile,
"-t",
"testinfra:{0}".format(image),
f"testinfra:{image}",
image_path,
]
)
Expand Down
Loading