Skip to content
Snippets Groups Projects
Commit 4e959cbc authored by Nathan Hertz's avatar Nathan Hertz
Browse files

Finished testing for all recipes. Added buildout recipe to automatically run...

Finished testing for all recipes. Added buildout recipe to automatically run tests on other buildout recipes (and itself)
parent b33a4ecf
No related branches found
No related tags found
No related merge requests found
......@@ -3,8 +3,14 @@ import zc.buildout.testing
@pytest.fixture(scope='module')
def recipe():
from .. import setup_to_meta
"""
pytest fixture that initializes zc.buildout objects for use in testing.
Initializes Buildout, Options, and Recipe objects.
:return: Initialized recipe object for build_pkgs
"""
from .. import build_pkgs
buildout = zc.buildout.testing.Buildout()
options = buildout.Options(buildout, 'gen_metadata', {'recipe': 'setup_to_meta'})
recipe = setup_to_meta.Recipe(buildout=buildout, name=None, options=options)
options = buildout.Options(buildout, 'build_pkgs', {'recipe': 'build_pkgs', 'name': 'null'})
recipe = build_pkgs.Recipe(buildout=buildout, name=None, options=options)
return recipe
\ No newline at end of file
import pytest
from .. import setup_to_meta
class TestSetupToMeta:
def test_del_substrings(self):
replaced = setup_to_meta.del_substrings('heallob, woarlcd', ['a', 'b', 'c'])
assert replaced == 'hello, world'
import os
from .. import build_pkgs
class TestBuildPkgs:
def test_get_names(self):
"""
Test that build_pkgs correctly gets the package name from
:return:
"""
d = 'apps/cli/executables/null'
assert setup_to_meta.get_names([d]) == ['null']
assert build_pkgs.get_names([d]) == ['null']
def test_get_dirs(self):
assert './apps/cli/executables/null' in setup_to_meta.get_dirs()
def test_get_outputs(self):
assert setup_to_meta.get_outputs(['null']) == ['build/metadata/null/meta.yaml']
"""
Test that build_pkgs correctly finds and stores directory paths
of directories containing setup.py files.
"""
assert './apps/cli/executables/null' in build_pkgs.get_dirs()
def test_output(self, recipe):
"""
Test that metadata was successfully created and contains data.
Checking for 'package' is an arbitrary check for content that will always
occur in a correct recipe.
:param recipe: Fixture that initializes recipe class in setup_to_meta.py
Test that the package specified in the recipe has been built correctly.
"""
created = recipe.install()
for path in created:
with open(path, 'r') as f:
assert 'package' in f.read()
print(path)
if len(path) > 0:
assert path is not None, "conda build failed to build package"
assert os.path.exists(path)
......@@ -3,6 +3,12 @@ import zc.buildout.testing
@pytest.fixture(scope='module')
def recipe():
"""
pytest fixture that initializes zc.buildout objects for use in testing.
Initializes Buildout, Options, and Recipe objects.
:return: Initialized recipe object for setup_to_meta
"""
from .. import setup_to_meta
buildout = zc.buildout.testing.Buildout()
options = buildout.Options(buildout, 'gen_metadata', {'recipe': 'setup_to_meta'})
......
import pytest
from .. import setup_to_meta
class TestSetupToMeta:
def test_del_substrings(self):
"""
Test that del_substrings function properly deletes substrings from a given string
"""
replaced = setup_to_meta.del_substrings('heallob, woarlcd', ['a', 'b', 'c'])
assert replaced == 'hello, world'
def test_get_names(self):
"""
Test that setup_to_meta correctly gets the package name from the package path
"""
d = 'apps/cli/executables/null'
assert setup_to_meta.get_names([d]) == ['null']
def test_get_dirs(self):
"""
Test that setup_to_meta correctly finds and stores directory paths
of packages containing setup.py files
"""
assert './apps/cli/executables/null' in setup_to_meta.get_dirs()
def test_get_outputs(self):
"""
Test that tests that setup_to_meta correctly generates a list of output paths given
a list of package names.
"""
assert setup_to_meta.get_outputs(['null']) == ['build/metadata/null/meta.yaml']
def test_output(self, recipe):
......
......@@ -6,7 +6,7 @@ class TestRecipes:
Test that test_recipes is able to successfully retrieve names and paths
for all buildout recipes.
"""
recipe_names = ['setup_to_meta', 'build_packages', 'test_recipes']
recipe_names = ['setup_to_meta', 'build_pkgs', 'test_recipes']
recipes = test_recipes.get_recipes()
for recipe in recipe_names:
assert recipe in recipes
......@@ -32,6 +32,16 @@ class Recipe:
For more detailed information, see the link.
http://www.buildout.org/en/latest/topics/writing-recipes.html
"""
def run_test(self, recipe):
"""
Run test for given recipe.
:param recipe: Name of recipe to be run.
"""
logger.debug(f"Running tests for recipe {recipe}...")
subprocess.run(['pytest', '-vv', '--log-level=DEBUG', '--showlocals',
self.recipes[recipe]])
def __init__(self, buildout, name, options):
"""
Initializes fields needed for recipe.
......@@ -52,7 +62,10 @@ class Recipe:
In this case, nothing is "installed" per se.
:return: Paths to files, as strings, created by the recipe.
"""
if self.choice in self.recipes:
logger.debug(f"Running tests for recipe {self.choice}...")
subprocess.run(['pytest', '-vv', '--log-level=DEBUG', '--showlocals',
self.recipes[self.choice]])
if self.choice == 'all':
# Run tests for all recipes
for recipe in self.recipes:
self.run_test(recipe)
else:
if self.choice in self.recipes:
self.run_test(self.choice)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment