From ea58073021718aa27d14b49d1d4cffb2e0ea8883 Mon Sep 17 00:00:00 2001 From: Andre Miras Date: Mon, 4 Feb 2019 16:16:51 +0100 Subject: [PATCH] Recipe class unit tests Starts unit testing trivial cases for the `Recipe` class. We will continue increasing the coverage as we encounter bugs. --- tests/test_recipe.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_recipe.py diff --git a/tests/test_recipe.py b/tests/test_recipe.py new file mode 100644 index 0000000000..f0a00ed5e7 --- /dev/null +++ b/tests/test_recipe.py @@ -0,0 +1,43 @@ +import types +import unittest +from pythonforandroid.build import Context +from pythonforandroid.recipe import Recipe + + +class TestRecipe(unittest.TestCase): + + def test_recipe_dirs(self): + """ + Trivial `recipe_dirs()` test. + Makes sure the list is not empty and has the root directory. + """ + ctx = Context() + recipes_dir = Recipe.recipe_dirs(ctx) + # by default only the root dir `recipes` directory + self.assertEqual(len(recipes_dir), 1) + self.assertTrue(recipes_dir[0].startswith(ctx.root_dir)) + + def test_list_recipes(self): + """ + Trivial test verifying list_recipes returns a generator with some recipes. + """ + ctx = Context() + recipes = Recipe.list_recipes(ctx) + self.assertTrue(isinstance(recipes, types.GeneratorType)) + recipes = list(recipes) + self.assertIn('python3', recipes) + + def test_get_recipe(self): + """ + Makes sure `get_recipe()` returns a `Recipe` object when possible. + """ + ctx = Context() + recipe_name = 'python3' + recipe = Recipe.get_recipe(recipe_name, ctx) + self.assertTrue(isinstance(recipe, Recipe)) + self.assertEqual(recipe.name, recipe_name) + recipe_name = 'does_not_exist' + with self.assertRaises(IOError) as e: + Recipe.get_recipe(recipe_name, ctx) + self.assertEqual( + e.exception.args[0], 'Recipe does not exist: {}'.format(recipe_name))