added mig_meow rule creation
This commit is contained in:
20
rules/file_event_jupyter_notebook_rule.py
Normal file
20
rules/file_event_jupyter_notebook_rule.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
from core.correctness.validation import check_input
|
||||
from core.meow import BaseRule
|
||||
from patterns.file_event_pattern import FileEventPattern
|
||||
from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe
|
||||
|
||||
class FileEventJupyterNotebookRule(BaseRule):
|
||||
def __init__(self, name: str, pattern:FileEventPattern,
|
||||
recipe:JupyterNotebookRecipe):
|
||||
super().__init__(name, pattern, recipe)
|
||||
if pattern.recipe != recipe.name:
|
||||
raise ValueError(f"Cannot create Rule {name}. Pattern "
|
||||
f"{pattern.name} does not identify Recipe {recipe.name}. It "
|
||||
f"uses {pattern.recipe}")
|
||||
|
||||
def _is_valid_pattern(self, pattern:FileEventPattern) -> None:
|
||||
check_input(pattern, FileEventPattern)
|
||||
|
||||
def _is_valid_recipe(self, recipe:JupyterNotebookRecipe) -> None:
|
||||
check_input(recipe, JupyterNotebookRecipe)
|
@ -1,7 +1,7 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from patterns.FileEventPattern import FileEventPattern
|
||||
from patterns.file_event_pattern import FileEventPattern
|
||||
|
||||
|
||||
class CorrectnessTests(unittest.TestCase):
|
@ -2,7 +2,7 @@
|
||||
import jsonschema
|
||||
import unittest
|
||||
|
||||
from recipes.JupyterNotebookRecipe import JupyterNotebookRecipe
|
||||
from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe
|
||||
|
||||
BAREBONES_NOTEBOOK = {
|
||||
"cells": [],
|
78
tests/test_rules.py
Normal file
78
tests/test_rules.py
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from patterns.file_event_pattern import FileEventPattern
|
||||
from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe
|
||||
from rules.file_event_jupyter_notebook_rule import FileEventJupyterNotebookRule
|
||||
from test_recipes import BAREBONES_NOTEBOOK
|
||||
|
||||
class CorrectnessTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
return super().tearDown()
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationMinimum(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
FileEventJupyterNotebookRule("name", fep, jnr)
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationNoName(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventJupyterNotebookRule("", fep, jnr)
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationInvalidName(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
FileEventJupyterNotebookRule(1, fep, jnr)
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationInvalidPattern(self)->None:
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
FileEventJupyterNotebookRule("name", "pattern", jnr)
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationInvalidRecipe(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
FileEventJupyterNotebookRule("name", fep, "recipe")
|
||||
|
||||
def testFileEventJupyterNotebookRuleCreationMissmatchedRecipe(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventJupyterNotebookRule("name", fep, jnr)
|
||||
|
||||
def testFileEventJupyterNotebookRuleSetupName(self)->None:
|
||||
name = "name"
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
fejnr = FileEventJupyterNotebookRule(name, fep, jnr)
|
||||
|
||||
self.assertEqual(fejnr.name, name)
|
||||
|
||||
def testFileEventJupyterNotebookRuleSetupPattern(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
fejnr = FileEventJupyterNotebookRule("name", fep, jnr)
|
||||
|
||||
self.assertEqual(fejnr.pattern, fep)
|
||||
|
||||
def testFileEventJupyterNotebookRuleSetupRecipe(self)->None:
|
||||
fep = FileEventPattern("name", "path", "recipe", "file")
|
||||
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
fejnr = FileEventJupyterNotebookRule("name", fep, jnr)
|
||||
|
||||
self.assertEqual(fejnr.recipe, jnr)
|
Reference in New Issue
Block a user