added test for get_recipe_from_notebook

This commit is contained in:
PatchOfScotland
2023-03-14 13:39:01 +01:00
parent 40ed98000b
commit af489d2bb9
9 changed files with 27 additions and 16 deletions

View File

@ -1,6 +1,6 @@
from meow_base.patterns import FileEventPattern
from meow_base.recipes import getRecipeFromNotebook
from meow_base.recipes import get_recipe_from_notebook
from shared import run_test, MRME
@ -15,7 +15,7 @@ def multiple_rules_multiple_events(job_count:int, REPEATS, job_counter, requeste
)
patterns[pattern.name] = pattern
recipe = getRecipeFromNotebook("recipe_one", "test.ipynb")
recipe = get_recipe_from_notebook("recipe_one", "test.ipynb")
recipes = {
recipe.name: recipe

View File

@ -1,6 +1,6 @@
from meow_base.patterns import FileEventPattern
from meow_base.recipes import getRecipeFromNotebook
from meow_base.recipes import get_recipe_from_notebook
from shared import run_test, MRSE
@ -15,7 +15,7 @@ def multiple_rules_single_event(job_count:int, REPEATS, job_counter, requested_j
)
patterns[pattern.name] = pattern
recipe = getRecipeFromNotebook("recipe_one", "test.ipynb")
recipe = get_recipe_from_notebook("recipe_one", "test.ipynb")
recipes = {
recipe.name: recipe

View File

@ -1,6 +1,6 @@
from meow_base.patterns import FileEventPattern
from meow_base.recipes import getRecipeFromNotebook
from meow_base.recipes import get_recipe_from_notebook
from shared import run_test, SRME
@ -14,7 +14,7 @@ def single_rule_multiple_events(job_count:int, REPEATS, job_counter, requested_j
)
patterns[pattern.name] = pattern
recipe = getRecipeFromNotebook("recipe_one", "test.ipynb")
recipe = get_recipe_from_notebook("recipe_one", "test.ipynb")
recipes = {
recipe.name: recipe

View File

@ -1,6 +1,6 @@
from meow_base.patterns import FileEventPattern
from meow_base.recipes import getRecipeFromNotebook
from meow_base.recipes import get_recipe_from_notebook
from meow_base.functionality.meow import create_parameter_sweep
from shared import run_test, SRSEP
@ -16,7 +16,7 @@ def single_rule_single_event_parallel(job_count:int, REPEATS, job_counter, reque
)
patterns[pattern.name] = pattern
recipe = getRecipeFromNotebook("recipe_one", "test.ipynb")
recipe = get_recipe_from_notebook("recipe_one", "test.ipynb")
recipes = {
recipe.name: recipe

View File

@ -1,6 +1,6 @@
from meow_base.patterns import FileEventPattern
from meow_base.recipes import getRecipeFromNotebook
from meow_base.recipes import get_recipe_from_notebook
from shared import run_test, SRSES
@ -17,7 +17,7 @@ def single_rule_single_event_sequential(job_count:int, REPEATS, job_counter, req
)
patterns[pattern.name] = pattern
recipe = getRecipeFromNotebook("recipe_two", "sequential.ipynb")
recipe = get_recipe_from_notebook("recipe_two", "sequential.ipynb")
recipes = {
recipe.name: recipe

View File

@ -1,4 +1,4 @@
from .jupyter_notebook_recipe import JupyterNotebookRecipe, PapermillHandler, \
getRecipeFromNotebook
get_recipe_from_notebook
from .python_recipe import PythonRecipe, PythonHandler

View File

@ -182,12 +182,11 @@ class PapermillHandler(BaseHandler):
# Send job directory, as actual definitons will be read from within it
self.to_runner.send(job_dir)
#TODO test me
def getRecipeFromNotebook(name:str, notebook_filename:str,
def get_recipe_from_notebook(name:str, notebook_filename:str,
parameters:Dict[str,Any]={}, requirements:Dict[str,Any]={}
)->JupyterNotebookRecipe:
valid_existing_file_path(notebook_filename, extension=".ipynb")
check_type(name, str, hint="getRecipeFromNotebook.name")
check_type(name, str, hint="get_recipe_from_notebook.name")
notebook_code = read_notebook(notebook_filename)

View File

@ -15,7 +15,6 @@ from meow_base.recipes.jupyter_notebook_recipe import JupyterNotebookRecipe
from shared import setup, teardown, BAREBONES_NOTEBOOK, TEST_MONITOR_BASE
def patterns_equal(tester, pattern_one, pattern_two):
tester.assertEqual(pattern_one.name, pattern_two.name)
tester.assertEqual(pattern_one.recipe, pattern_two.recipe)

View File

@ -20,7 +20,7 @@ from meow_base.functionality.meow import create_job, create_rules, create_rule,
create_watchdog_event
from meow_base.patterns.file_event_pattern import FileEventPattern
from meow_base.recipes.jupyter_notebook_recipe import JupyterNotebookRecipe, \
PapermillHandler, papermill_job_func
PapermillHandler, papermill_job_func, get_recipe_from_notebook
from meow_base.recipes.python_recipe import PythonRecipe, PythonHandler, python_job_func
from meow_base.rules import FileEventPythonRule, FileEventJupyterNotebookRule
from shared import setup, teardown, BAREBONES_PYTHON_SCRIPT, \
@ -440,6 +440,19 @@ class JupyterNotebookTests(unittest.TestCase):
})
self.assertTrue(status)
# Test function correctly creates Recipe directly from notebook
def testGetRecipeFromNotebook(self)->None:
notebook_path = os.path.join(TEST_MONITOR_BASE, "notebook.ipynb")
write_notebook(COMPLETE_NOTEBOOK, notebook_path)
self.assertTrue(os.path.exists(notebook_path))
recipe = get_recipe_from_notebook("name", notebook_path)
self.assertIsInstance(recipe, JupyterNotebookRecipe)
self.assertEqual(recipe.name, "name")
self.assertEqual(recipe.recipe, COMPLETE_NOTEBOOK)
class PythonTests(unittest.TestCase):
def setUp(self)->None: