Skip to content

Commit 0c4cd1d

Browse files
authored
Merge pull request kivy#1676 from AndreMiras/feature/recipe_unit_tests
Recipe class unit tests
2 parents 9efee20 + ea58073 commit 0c4cd1d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/test_recipe.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import types
2+
import unittest
3+
from pythonforandroid.build import Context
4+
from pythonforandroid.recipe import Recipe
5+
6+
7+
class TestRecipe(unittest.TestCase):
8+
9+
def test_recipe_dirs(self):
10+
"""
11+
Trivial `recipe_dirs()` test.
12+
Makes sure the list is not empty and has the root directory.
13+
"""
14+
ctx = Context()
15+
recipes_dir = Recipe.recipe_dirs(ctx)
16+
# by default only the root dir `recipes` directory
17+
self.assertEqual(len(recipes_dir), 1)
18+
self.assertTrue(recipes_dir[0].startswith(ctx.root_dir))
19+
20+
def test_list_recipes(self):
21+
"""
22+
Trivial test verifying list_recipes returns a generator with some recipes.
23+
"""
24+
ctx = Context()
25+
recipes = Recipe.list_recipes(ctx)
26+
self.assertTrue(isinstance(recipes, types.GeneratorType))
27+
recipes = list(recipes)
28+
self.assertIn('python3', recipes)
29+
30+
def test_get_recipe(self):
31+
"""
32+
Makes sure `get_recipe()` returns a `Recipe` object when possible.
33+
"""
34+
ctx = Context()
35+
recipe_name = 'python3'
36+
recipe = Recipe.get_recipe(recipe_name, ctx)
37+
self.assertTrue(isinstance(recipe, Recipe))
38+
self.assertEqual(recipe.name, recipe_name)
39+
recipe_name = 'does_not_exist'
40+
with self.assertRaises(IOError) as e:
41+
Recipe.get_recipe(recipe_name, ctx)
42+
self.assertEqual(
43+
e.exception.args[0], 'Recipe does not exist: {}'.format(recipe_name))

0 commit comments

Comments
 (0)