-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# Constants | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
SUFFIX = ".fmf" | ||
MAIN = "main" + SUFFIX | ||
IGNORED_DIRECTORIES = ['/dev', '/proc', '/sys'] | ||
# comma separated list for plugin env var | ||
PLUGIN_ENV = "PLUGINS" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from functools import lru_cache | ||
import inspect | ||
from fmf.constants import PLUGIN_ENV, SUFFIX | ||
from fmf.utils import log | ||
import importlib | ||
import os | ||
|
||
|
||
|
||
class Plugin: | ||
""" | ||
Main abstact class for FMF plugins | ||
""" | ||
# you have to define extension list as class attribute e.g. [".py"] | ||
extensions = list() | ||
|
||
def get_data(self, filename): | ||
raise NotImplemented("Define own impementation") | ||
|
||
|
||
@lru_cache(maxsize=1) | ||
def enabled_plugins(): | ||
plugins = os.getenv(PLUGIN_ENV).split(",") if os.getenv(PLUGIN_ENV) else [] | ||
plugin_list = list() | ||
for item in plugins: | ||
loader = importlib.machinery.SourceFileLoader(os.path.basename(item), item) | ||
module = importlib.util.module_from_spec( | ||
importlib.util.spec_from_loader(loader.name, loader) | ||
) | ||
loader.exec_module(module) | ||
for name, item in inspect.getmembers(module): | ||
if inspect.isclass(item) and issubclass(item, Plugin): | ||
plugin_list.append(item) | ||
log.info("Loaded plugin {}".format(item)) | ||
return plugin_list | ||
|
||
|
||
def get_suffixes(): | ||
output = [SUFFIX] | ||
for item in enabled_plugins(): | ||
output += item.extensions | ||
return output | ||
|
||
|
||
def get_plugin_for_file(filename): | ||
extension = "." + filename.rsplit(".", 1)[1] | ||
for item in enabled_plugins(): | ||
if extension in item.extensions: | ||
log.debug("File {} parsed by by plugin {}".format(filename, item)) | ||
return item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from fmf.plugin_loader import Plugin | ||
from fmf.utils import log | ||
from fmf_metadata.pytest_collector import collect | ||
from fmf_metadata.constants import PYTEST_DEFAULT_CONF | ||
from fmf_metadata.base import _Test, _TestCls, define_undefined | ||
from fmf_metadata.base import FMF | ||
import re | ||
import os | ||
|
||
_ = FMF | ||
|
||
def update_data(store_dict, func, config): | ||
keys = [] | ||
filename = os.path.basename(func.fspath) | ||
if func.cls: | ||
cls = _TestCls(func.cls, filename) | ||
keys.append(cls.name) | ||
else: | ||
cls = _TestCls(None, filename) | ||
test = _Test(func) | ||
# normalise test name to pytest identifier | ||
test.name = re.search( | ||
f".*({os.path.basename(func.function.__name__)}.*)", func.name | ||
).group(1) | ||
# TODO: removed str_normalise(...) will see what happen | ||
keys.append(test.name) | ||
define_undefined(store_dict, keys, config, filename, cls, test) | ||
return store_dict | ||
|
||
|
||
class Pytest(Plugin): | ||
extensions = [".py"] | ||
|
||
def get_data(self, file_name): | ||
out = dict() | ||
for item in collect([file_name]): | ||
update_data(store_dict=out, func=item, config=PYTEST_DEFAULT_CONF) | ||
log.info("Processing Item: {}".format(item)) | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
author: Jan Scotka <[email protected]> | ||
|
||
/pure_fmf: | ||
test: ./runtest.sh | ||
summary: Pure FMF test case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import unittest | ||
from fmf_metadata import FMF | ||
|
||
|
||
@FMF.tag("Tier1") | ||
@FMF.summary("This is basic testcase") | ||
def test_pass(): | ||
assert True | ||
|
||
|
||
def test_fail(): | ||
assert False | ||
|
||
|
||
@pytest.mark.skip | ||
def test_skip(): | ||
assert True | ||
|
||
|
||
@pytest.mark.parametrize("test_input", ["a", "b", "c"]) | ||
def test_parametrize(test_input): | ||
assert bool(test_input) | ||
|
||
|
||
class TestCls(unittest.TestCase): | ||
def test(self): | ||
self.assertTrue(True) |