Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 438c58b

Browse files
committed
pytest-molecule is going black
We are going black and unlikely to look back. No more debates about code-style.
1 parent 09734a3 commit 438c58b

File tree

6 files changed

+123
-104
lines changed

6 files changed

+123
-104
lines changed

.flake8

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[flake8]
2+
# do not add excludes for files in repo
3+
exclude = .venv/,.tox/,dist/,build/,.eggs/
4+
format = pylint
5+
# E203: https://github.com/python/black/issues/315
6+
ignore = E741,W503,W504,H,E501,E203
7+
# 88 is official black default:
8+
max-line-length = 88

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
repos:
3+
- repo: https://github.com/python/black
4+
rev: 19.3b0
5+
hooks:
6+
- id: black
7+
language_version: python3
38
- repo: https://github.com/pre-commit/pre-commit-hooks
49
rev: v2.1.0
510
hooks:
@@ -14,6 +19,8 @@ repos:
1419
rev: 3.7.7
1520
hooks:
1621
- id: flake8
22+
additional_dependencies:
23+
- flake8-black
1724
- repo: https://github.com/adrienverge/yamllint.git
1825
rev: v1.15.0
1926
hooks:

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pytest-molecule
1414
:target: https://travis-ci.org/pycontribs/pytest-molecule
1515
:alt: See Build Status on Travis CI
1616

17+
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
18+
:target: https://github.com/python/black
19+
:alt: Python Black Code Style
20+
1721
PyTest Molecule Plugin :: auto detects and runs molecule tests
1822

1923
----

pytest_molecule/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def pytest_configure(config):
1919
raise Exception("Failed to ping docker server.")
2020

2121
# validate selinux availability
22-
if sys.platform == 'linux' and os.path.isfile("/etc/selinux/config"):
22+
if sys.platform == "linux" and os.path.isfile("/etc/selinux/config"):
2323
try:
2424
import selinux # noqa
2525
except Exception:
@@ -29,7 +29,8 @@ def pytest_configure(config):
2929
"libselinux python bindings installed. These can only be "
3030
"installed using your distro package manager and are specific "
3131
"to each python version. Common package names: "
32-
"libselinux-python python2-libselinux python3-libselinux")
32+
"libselinux-python python2-libselinux python3-libselinux"
33+
)
3334
# we do not re-raise this exception because missing or broken
3435
# selinux bindings are not guaranteed to fail molecule execution.
3536

@@ -41,7 +42,7 @@ def pytest_collect_file(parent, path):
4142

4243
class MoleculeFile(pytest.File):
4344
def collect(self):
44-
yield MoleculeItem('test', self)
45+
yield MoleculeItem("test", self)
4546

4647
def __str__(self):
4748
return str(self.fspath.relto(os.getcwd()))
@@ -53,11 +54,11 @@ def __init__(self, name, parent):
5354

5455
def runtest(self):
5556
folders = self.fspath.dirname.split(os.sep)
56-
cwd = os.path.abspath(os.path.join(self.fspath.dirname, '../..'))
57+
cwd = os.path.abspath(os.path.join(self.fspath.dirname, "../.."))
5758
scenario = folders[-1]
5859
role = folders[-3] # noqa
59-
cmd = [sys.executable, '-m', 'molecule', self.name, '-s', scenario]
60-
print("running: %s (from %s)" % (" " .join(cmd), cwd))
60+
cmd = [sys.executable, "-m", "molecule", self.name, "-s", scenario]
61+
print("running: %s (from %s)" % (" ".join(cmd), cwd))
6162

6263
try:
6364
# Workaround for STDOUT/STDERR line ordering issue:
@@ -67,19 +68,20 @@ def runtest(self):
6768
cwd=cwd,
6869
stdout=subprocess.PIPE,
6970
stderr=subprocess.STDOUT,
70-
universal_newlines=True)
71+
universal_newlines=True,
72+
)
7173
for line in p.stdout:
7274
print(line, end="")
7375
p.wait()
7476
if p.returncode != 0:
7577
pytest.fail(
76-
"Error code %s returned by: %s" % (
77-
p.returncode, " ".join(cmd)),
78-
pytrace=False)
78+
"Error code %s returned by: %s" % (p.returncode, " ".join(cmd)),
79+
pytrace=False,
80+
)
7981
except Exception as e:
8082
pytest.fail(
81-
"Exception %s returned by: %s" % (e, " ".join(cmd)),
82-
pytrace=False)
83+
"Exception %s returned by: %s" % (e, " ".join(cmd)), pytrace=False
84+
)
8385

8486
def reportinfo(self):
8587
return self.fspath, 0, "usecase: %s" % self.name

0 commit comments

Comments
 (0)