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

Commit a6a88b5

Browse files
committed
Initial commit
1 parent 29a7320 commit a6a88b5

File tree

17 files changed

+358
-6
lines changed

17 files changed

+358
-6
lines changed

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v2.1.0
5+
hooks:
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: mixed-line-ending
9+
- id: check-byte-order-marker
10+
- id: check-executables-have-shebangs
11+
- id: check-merge-conflict
12+
- id: debug-statements
13+
- repo: https://gitlab.com/pycqa/flake8
14+
rev: 3.7.7
15+
hooks:
16+
- id: flake8
17+
- repo: https://github.com/adrienverge/yamllint.git
18+
rev: v1.15.0
19+
hooks:
20+
- id: yamllint
21+
files: \.(yaml|yml)$
22+
types: [file, yaml]
23+
entry: yamllint --strict
24+
- repo: https://github.com/codespell-project/codespell.git
25+
rev: v1.15.0
26+
hooks:
27+
- id: codespell
28+
name: codespell
29+
description: Checks for common misspellings in text files.
30+
entry: codespell
31+
language: python
32+
types: [text]
33+
args: []
34+
require_serial: false
35+
additional_dependencies: []

.travis.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
dist: xenial
3+
# Config file for automatic testing at travis-ci.org
4+
5+
sudo: false
6+
services:
7+
- docker
8+
language: python
9+
10+
matrix:
11+
include:
12+
- python: 3.7
13+
env: TOX_ENV=lint
14+
- python: 2.7
15+
env: TOX_ENV=py27
16+
- python: 3.5
17+
env: TOX_ENV=py35
18+
- python: 3.6
19+
env: TOX_ENV=py36
20+
- python: 3.7
21+
env: TOX_ENV=py37
22+
23+
install:
24+
- pip install tox
25+
26+
script:
27+
- tox -e $TOX_ENV
28+
29+
before_cache:
30+
- rm -rf $HOME/.cache/pip/log
31+
32+
cache:
33+
directories:
34+
- $HOME/.cache/pip
35+
addons:
36+
apt:
37+
packages:
38+
- lxc
39+
- lxc-dev
40+
- lxd
41+
- lxd-client

LICENSE

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
MIT License
21

3-
Copyright (c) 2019 PyContribs
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2019 Sorin Sbarnea
45

56
Permission is hereby granted, free of charge, to any person obtaining a copy
67
of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +10,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
910
copies of the Software, and to permit persons to whom the Software is
1011
furnished to do so, subject to the following conditions:
1112

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
1415

1516
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1617
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1718
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1819
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1920
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include LICENSE
2+
include README.rst
3+
4+
recursive-exclude * __pycache__
5+
recursive-exclude * *.py[co]

README.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
===============
2+
pytest-molecule
3+
===============
4+
5+
.. image:: https://img.shields.io/pypi/v/pytest-molecule.svg
6+
:target: https://pypi.org/project/pytest-molecule
7+
:alt: PyPI version
8+
9+
.. image:: https://img.shields.io/pypi/pyversions/pytest-molecule.svg
10+
:target: https://pypi.org/project/pytest-molecule
11+
:alt: Python versions
12+
13+
.. image:: https://travis-ci.org/pycontribs/pytest-molecule.svg?branch=master
14+
:target: https://travis-ci.org/pycontribs/pytest-molecule
15+
:alt: See Build Status on Travis CI
16+
17+
PyTest Molecule Plugin :: auto detects and runs molecule tests
18+
19+
----
20+
21+
This plugin enables pytest discovery of all molecule.yml files inside the codebase
22+
and runs them as pytest tests.
23+
24+
Once you install pytest-molecule you should be able to just run `pytest` in order
25+
to run molecule on all roles and scenarios.
26+
27+
Installation
28+
------------
29+
30+
You can install "pytest-molecule" via `pip`_ from `PyPI`_::
31+
32+
$ pip install pytest-molecule
33+
34+
35+
Contributing
36+
------------
37+
Contributions are very welcome. Tests can be run with `tox`_, please ensure
38+
the coverage at least stays the same before you submit a pull request.
39+
40+
License
41+
-------
42+
43+
Distributed under the terms of the `MIT`_ license, "pytest-molecule" is free and open source software
44+
45+
46+
Issues
47+
------
48+
49+
If you encounter any problems, please `file an issue`_ along with a detailed description.
50+
51+
.. _`MIT`: http://opensource.org/licenses/MIT
52+
.. _`file an issue`: https://github.com/ssbarnea/pytest-molecule/issues
53+
.. _`pytest`: https://github.com/pytest-dev/pytest
54+
.. _`tox`: https://tox.readthedocs.io/en/latest/
55+
.. _`pip`: https://pypi.org/project/pip/
56+
.. _`PyPI`: https://pypi.org/project

pytest_molecule.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import print_function
3+
import os
4+
import pytest
5+
import subprocess
6+
7+
8+
def pytest_collect_file(parent, path):
9+
if path.basename == "molecule.yml":
10+
return MoleculeFile(path, parent)
11+
12+
13+
class MoleculeFile(pytest.File):
14+
def collect(self):
15+
yield MoleculeItem("", self)
16+
17+
18+
class MoleculeItem(pytest.Item):
19+
def __init__(self, name, parent):
20+
super(MoleculeItem, self).__init__(name, parent)
21+
22+
def runtest(self):
23+
folders = self.fspath.dirname.split(os.sep)
24+
cwd = os.path.abspath(os.path.join(self.fspath.dirname, '../..'))
25+
scenario = folders[-1]
26+
role = folders[-3] # noqa
27+
28+
cmd = ['python', '-m', 'molecule', 'test', '-s', scenario]
29+
print("running: %s (from %s)" % (" " .join(cmd), cwd))
30+
# Workaround for STDOUT/STDERR line ordering issue:
31+
# https://github.com/pytest-dev/pytest/issues/5449
32+
p = subprocess.Popen(
33+
cmd,
34+
cwd=cwd,
35+
stdout=subprocess.PIPE,
36+
stderr=subprocess.STDOUT,
37+
universal_newlines=True)
38+
for line in p.stdout:
39+
print(line, end="")
40+
p.wait()
41+
assert p.returncode == 0
42+
43+
44+
class MoleculeException(Exception):
45+
""" custom exception for error reporting. """

setup.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os
5+
import codecs
6+
from setuptools import setup
7+
8+
9+
def read(fname):
10+
file_path = os.path.join(os.path.dirname(__file__), fname)
11+
return codecs.open(file_path, encoding='utf-8').read()
12+
13+
14+
setup(
15+
name='pytest-molecule',
16+
version='0.1.0',
17+
author='Sorin Sbarnea',
18+
author_email='sorin.sbarnea@gmail.com',
19+
maintainer='Sorin Sbarnea',
20+
maintainer_email='sorin.sbarnea@gmail.com',
21+
license='MIT',
22+
url='https://github.com/pycontribs/pytest-molecule',
23+
description='PyTest Molecule Plugin :: discover and run molecule tests',
24+
long_description=read('README.rst'),
25+
py_modules=['pytest_molecule'],
26+
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
27+
install_requires=['pytest>=3.5.0', 'molecule>=2.22rc1'],
28+
classifiers=[
29+
'Development Status :: 4 - Beta',
30+
'Framework :: Pytest',
31+
'Intended Audience :: Developers',
32+
'Topic :: Software Development :: Testing',
33+
'Programming Language :: Python',
34+
'Programming Language :: Python :: 2',
35+
'Programming Language :: Python :: 2.7',
36+
'Programming Language :: Python :: 3',
37+
'Programming Language :: Python :: 3.5',
38+
'Programming Language :: Python :: 3.6',
39+
'Programming Language :: Python :: 3.7',
40+
'Programming Language :: Python :: Implementation :: CPython',
41+
'Programming Language :: Python :: Implementation :: PyPy',
42+
'Operating System :: OS Independent',
43+
'License :: OSI Approved :: MIT License',
44+
],
45+
entry_points={
46+
'pytest11': [
47+
'molecule = pytest_molecule',
48+
],
49+
},
50+
)

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pytest_plugins = 'pytester'

tests/roles/myrole/meta/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
galaxy_info:
3+
author: Sorin Sbarnea
4+
description: Role that does nothing
5+
license: MIT
6+
7+
min_ansible_version: 2.6
8+
9+
galaxy_tags: []
10+
11+
dependencies: []
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Molecule managed
2+
3+
{% if item.registry is defined %}
4+
FROM {{ item.registry.url }}/{{ item.image }}
5+
{% else %}
6+
FROM {{ item.image }}
7+
{% endif %}
8+
9+
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
10+
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
11+
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
12+
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
13+
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
14+
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
15+
16+
{% for pkg in item.easy_install | default([]) %}
17+
# install pip for centos where there is no python-pip rpm in default repos
18+
RUN easy_install {{ pkg }}
19+
{% endfor %}
20+
21+
CMD ["sh", "-c", "while true; do sleep 10000; done"]

0 commit comments

Comments
 (0)