From ccaca5e60ed19ab3251b770ec17853642c3a6f4c Mon Sep 17 00:00:00 2001 From: PatchOfScotland Date: Fri, 2 Dec 2022 14:05:49 +0100 Subject: [PATCH] added mig_meow rule creation --- ...eEventPattern.py => file_event_pattern.py} | 0 ...okRecipe.py => jupyter_notebook_recipe.py} | 0 rules/file_event_jupyter_notebook_rule.py | 20 +++++ tests/{testAll.sh => test_all.sh} | 0 tests/{testMeow.py => test_meow.py} | 0 tests/{testPatterns.py => test_patterns.py} | 2 +- tests/{testRecipes.py => test_recipes.py} | 2 +- tests/test_rules.py | 78 +++++++++++++++++++ .../{testValidation.py => test_validation.py} | 0 9 files changed, 100 insertions(+), 2 deletions(-) rename patterns/{FileEventPattern.py => file_event_pattern.py} (100%) rename recipes/{JupyterNotebookRecipe.py => jupyter_notebook_recipe.py} (100%) create mode 100644 rules/file_event_jupyter_notebook_rule.py rename tests/{testAll.sh => test_all.sh} (100%) rename tests/{testMeow.py => test_meow.py} (100%) rename tests/{testPatterns.py => test_patterns.py} (97%) rename tests/{testRecipes.py => test_recipes.py} (97%) create mode 100644 tests/test_rules.py rename tests/{testValidation.py => test_validation.py} (100%) diff --git a/patterns/FileEventPattern.py b/patterns/file_event_pattern.py similarity index 100% rename from patterns/FileEventPattern.py rename to patterns/file_event_pattern.py diff --git a/recipes/JupyterNotebookRecipe.py b/recipes/jupyter_notebook_recipe.py similarity index 100% rename from recipes/JupyterNotebookRecipe.py rename to recipes/jupyter_notebook_recipe.py diff --git a/rules/file_event_jupyter_notebook_rule.py b/rules/file_event_jupyter_notebook_rule.py new file mode 100644 index 0000000..827a5ef --- /dev/null +++ b/rules/file_event_jupyter_notebook_rule.py @@ -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) diff --git a/tests/testAll.sh b/tests/test_all.sh similarity index 100% rename from tests/testAll.sh rename to tests/test_all.sh diff --git a/tests/testMeow.py b/tests/test_meow.py similarity index 100% rename from tests/testMeow.py rename to tests/test_meow.py diff --git a/tests/testPatterns.py b/tests/test_patterns.py similarity index 97% rename from tests/testPatterns.py rename to tests/test_patterns.py index 7a003e0..4ee6394 100644 --- a/tests/testPatterns.py +++ b/tests/test_patterns.py @@ -1,7 +1,7 @@ import unittest -from patterns.FileEventPattern import FileEventPattern +from patterns.file_event_pattern import FileEventPattern class CorrectnessTests(unittest.TestCase): diff --git a/tests/testRecipes.py b/tests/test_recipes.py similarity index 97% rename from tests/testRecipes.py rename to tests/test_recipes.py index 3722e77..7c95a51 100644 --- a/tests/testRecipes.py +++ b/tests/test_recipes.py @@ -2,7 +2,7 @@ import jsonschema import unittest -from recipes.JupyterNotebookRecipe import JupyterNotebookRecipe +from recipes.jupyter_notebook_recipe import JupyterNotebookRecipe BAREBONES_NOTEBOOK = { "cells": [], diff --git a/tests/test_rules.py b/tests/test_rules.py new file mode 100644 index 0000000..c374857 --- /dev/null +++ b/tests/test_rules.py @@ -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) diff --git a/tests/testValidation.py b/tests/test_validation.py similarity index 100% rename from tests/testValidation.py rename to tests/test_validation.py