added bones of mig_meow pattern and recipe implementations
This commit is contained in:
@ -1,67 +0,0 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from core.correctness.validation import check_input, valid_string
|
||||
from core.correctness.vars import VALID_NAME_CHARS
|
||||
from core.meow import BasePattern, BaseRecipe, BaseRule
|
||||
|
||||
|
||||
class CorrectnessTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
return super().tearDown()
|
||||
|
||||
def testCheckInput(self):
|
||||
# Valid input
|
||||
check_input(1, int)
|
||||
check_input(0, int)
|
||||
check_input(False, bool)
|
||||
check_input(True, bool)
|
||||
|
||||
# Misstyped input
|
||||
with self.assertRaises(TypeError):
|
||||
check_input(1, str)
|
||||
|
||||
# Or none
|
||||
check_input(None, int, or_none=True)
|
||||
with self.assertRaises(TypeError):
|
||||
check_input(None, int, or_none=False)
|
||||
|
||||
def testValidString(self):
|
||||
# Valid input
|
||||
valid_string("", "")
|
||||
valid_string("David_Marchant", VALID_NAME_CHARS)
|
||||
|
||||
# Misstyped input
|
||||
with self.assertRaises(TypeError):
|
||||
valid_string(1, VALID_NAME_CHARS)
|
||||
with self.assertRaises(TypeError):
|
||||
valid_string("David_Marchant", 1)
|
||||
|
||||
# Missing chars
|
||||
with self.assertRaises(ValueError):
|
||||
valid_string("David Marchant", VALID_NAME_CHARS)
|
||||
|
||||
class MeowTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
return super().tearDown()
|
||||
|
||||
def testBaseRecipe(self):
|
||||
# Should not be implementable on its own
|
||||
with self.assertRaises(TypeError):
|
||||
BaseRecipe("", "")
|
||||
|
||||
def testBasePattern(self):
|
||||
# Should not be implementable on its own
|
||||
with self.assertRaises(TypeError):
|
||||
BasePattern("", "")
|
||||
|
||||
def testBaseRule(self):
|
||||
# Should not be implementable on its own
|
||||
with self.assertRaises(TypeError):
|
||||
BaseRule("", "")
|
24
tests/testMeow.py
Normal file
24
tests/testMeow.py
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from core.meow import BasePattern, BaseRecipe, BaseRule
|
||||
|
||||
|
||||
class MeowTests(unittest.TestCase):
|
||||
def setUp(self)->None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self)->None:
|
||||
return super().tearDown()
|
||||
|
||||
def testBaseRecipe(self)->None:
|
||||
with self.assertRaises(TypeError):
|
||||
BaseRecipe("", "")
|
||||
|
||||
def testBasePattern(self)->None:
|
||||
with self.assertRaises(TypeError):
|
||||
BasePattern("", "")
|
||||
|
||||
def testBaseRule(self)->None:
|
||||
with self.assertRaises(TypeError):
|
||||
BaseRule("", "")
|
@ -11,6 +11,71 @@ class CorrectnessTests(unittest.TestCase):
|
||||
def tearDown(self) -> None:
|
||||
return super().tearDown()
|
||||
|
||||
def testFileEventPattern(self):
|
||||
pass
|
||||
def testFileEventPatternCreationMinimum(self)->None:
|
||||
FileEventPattern("name", "path", "recipe", "file")
|
||||
|
||||
def testFileEventPatternCreationEmptyName(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("", "path", "recipe", "file")
|
||||
|
||||
def testFileEventPatternCreationEmptyPath(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("name", "", "recipe", "file")
|
||||
|
||||
def testFileEventPatternCreationEmptyRecipe(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("name", "path", "", "file")
|
||||
|
||||
def testFileEventPatternCreationEmptyFile(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("name", "path", "recipe", "")
|
||||
|
||||
def testFileEventPatternCreationInvalidName(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("@name", "path", "recipe", "file")
|
||||
|
||||
def testFileEventPatternCreationInvalidRecipe(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("name", "path", "@recipe", "file")
|
||||
|
||||
def testFileEventPatternCreationInvalidFile(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
FileEventPattern("name", "path", "recipe", "@file")
|
||||
|
||||
def testFileEventPatternSetupName(self)->None:
|
||||
name = "name"
|
||||
fep = FileEventPattern(name, "path", "recipe", "file")
|
||||
self.assertEqual(fep.name, name)
|
||||
|
||||
def testFileEventPatternSetupPath(self)->None:
|
||||
path = "path"
|
||||
fep = FileEventPattern("name", path, "recipe", "file")
|
||||
self.assertEqual(fep.triggering_path, path)
|
||||
|
||||
def testFileEventPatternSetupRecipe(self)->None:
|
||||
recipe = "recipe"
|
||||
fep = FileEventPattern("name", "path", recipe, "file")
|
||||
self.assertEqual(fep.recipe, recipe)
|
||||
|
||||
def testFileEventPatternSetupFile(self)->None:
|
||||
file = "file"
|
||||
fep = FileEventPattern("name", "path", "recipe", file)
|
||||
self.assertEqual(fep.triggering_file, file)
|
||||
|
||||
def testFileEventPatternSetupParementers(self)->None:
|
||||
parameters = {
|
||||
"a": 1,
|
||||
"b": True
|
||||
}
|
||||
fep = FileEventPattern(
|
||||
"name", "path", "recipe", "file", parameters=parameters)
|
||||
self.assertEqual(fep.parameters, parameters)
|
||||
|
||||
def testFileEventPatternSetupOutputs(self)->None:
|
||||
outputs = {
|
||||
"a": "a",
|
||||
"b": "b"
|
||||
}
|
||||
fep = FileEventPattern(
|
||||
"name", "path", "recipe", "file", outputs=outputs)
|
||||
self.assertEqual(fep.outputs, outputs)
|
||||
|
@ -1,16 +1,81 @@
|
||||
|
||||
|
||||
import jsonschema
|
||||
import unittest
|
||||
|
||||
from recipes.JupyterNotebookRecipe import JupyterNotebookRecipe
|
||||
|
||||
BAREBONES_NOTEBOOK = {
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
||||
|
||||
class CorrectnessTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
def setUp(self)->None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
def tearDown(self)->None:
|
||||
return super().tearDown()
|
||||
|
||||
def testJupyterNotebookRecipe(self):
|
||||
pass
|
||||
def testJupyterNotebookRecipeCreationMinimum(self)->None:
|
||||
JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
def testJupyterNotebookRecipeCreationSource(self)->None:
|
||||
JupyterNotebookRecipe(
|
||||
"test_recipe", BAREBONES_NOTEBOOK, source="notebook.ipynb")
|
||||
|
||||
def testJupyterNotebookRecipeCreationNoName(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
JupyterNotebookRecipe("", BAREBONES_NOTEBOOK)
|
||||
|
||||
def testJupyterNotebookRecipeCreationInvalidName(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
JupyterNotebookRecipe("@test_recipe", BAREBONES_NOTEBOOK)
|
||||
|
||||
def testJupyterNotebookRecipeCreationInvalidRecipe(self)->None:
|
||||
with self.assertRaises(jsonschema.exceptions.ValidationError):
|
||||
JupyterNotebookRecipe("test_recipe", {})
|
||||
|
||||
def testJupyterNotebookRecipeCreationInvalidSourceExtension(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
JupyterNotebookRecipe(
|
||||
"test_recipe", BAREBONES_NOTEBOOK, source="notebook")
|
||||
|
||||
def testJupyterNotebookRecipeCreationInvalidSoureChar(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
JupyterNotebookRecipe(
|
||||
"test_recipe", BAREBONES_NOTEBOOK, source="@notebook.ipynb")
|
||||
|
||||
def testJupyterNotebookRecipeSetupName(self)->None:
|
||||
name = "name"
|
||||
jnr = JupyterNotebookRecipe(name, BAREBONES_NOTEBOOK)
|
||||
self.assertEqual(jnr.name, name)
|
||||
|
||||
def testJupyterNotebookRecipeSetupRecipe(self)->None:
|
||||
jnr = JupyterNotebookRecipe("name", BAREBONES_NOTEBOOK)
|
||||
self.assertEqual(jnr.recipe, BAREBONES_NOTEBOOK)
|
||||
|
||||
def testJupyterNotebookRecipeSetupParameters(self)->None:
|
||||
parameters = {
|
||||
"a": 1,
|
||||
"b": True
|
||||
}
|
||||
jnr = JupyterNotebookRecipe(
|
||||
"name", BAREBONES_NOTEBOOK, parameters=parameters)
|
||||
self.assertEqual(jnr.parameters, parameters)
|
||||
|
||||
def testJupyterNotebookRecipeSetupRequirements(self)->None:
|
||||
requirements = {
|
||||
"a": 1,
|
||||
"b": True
|
||||
}
|
||||
jnr = JupyterNotebookRecipe(
|
||||
"name", BAREBONES_NOTEBOOK, requirements=requirements)
|
||||
self.assertEqual(jnr.requirements, requirements)
|
||||
|
||||
def testJupyterNotebookRecipeSetupSource(self)->None:
|
||||
source = "source.ipynb"
|
||||
jnr = JupyterNotebookRecipe(
|
||||
"name", BAREBONES_NOTEBOOK, source=source)
|
||||
self.assertEqual(jnr.source, source)
|
||||
|
87
tests/testValidation.py
Normal file
87
tests/testValidation.py
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from typing import Any
|
||||
|
||||
from core.correctness.validation import check_input, valid_string, valid_dict
|
||||
from core.correctness.vars import VALID_NAME_CHARS
|
||||
|
||||
|
||||
class CorrectnessTests(unittest.TestCase):
|
||||
def setUp(self)->None:
|
||||
return super().setUp()
|
||||
|
||||
def tearDown(self)->None:
|
||||
return super().tearDown()
|
||||
|
||||
def testCheckInputValid(self)->None:
|
||||
check_input(1, int)
|
||||
check_input(0, int)
|
||||
check_input(False, bool)
|
||||
check_input(True, bool)
|
||||
check_input(1, Any)
|
||||
|
||||
def testCheckInputMistyped(self)->None:
|
||||
with self.assertRaises(TypeError):
|
||||
check_input(1, str)
|
||||
|
||||
def testCheckInputOrNone(self)->None:
|
||||
check_input(None, int, or_none=True)
|
||||
with self.assertRaises(TypeError):
|
||||
check_input(None, int, or_none=False)
|
||||
|
||||
def testValidStringValid(self)->None:
|
||||
valid_string("David_Marchant", VALID_NAME_CHARS)
|
||||
|
||||
def testValidStringEmptyString(self)->None:
|
||||
valid_string("", VALID_NAME_CHARS, min_length=0)
|
||||
|
||||
def testValidStringNoValidChars(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
valid_string("David_Marchant", "")
|
||||
|
||||
def testValidStringMistypedInput(self)->None:
|
||||
with self.assertRaises(TypeError):
|
||||
valid_string(1, VALID_NAME_CHARS)
|
||||
with self.assertRaises(TypeError):
|
||||
valid_string("David_Marchant", 1)
|
||||
|
||||
def testValidStringMissingChars(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
valid_string("David Marchant", VALID_NAME_CHARS)
|
||||
|
||||
def testValidStringInsufficientLength(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
valid_string("", VALID_NAME_CHARS)
|
||||
valid_string("David Marchant", VALID_NAME_CHARS, min_length=50)
|
||||
|
||||
def testValidDictMinimum(self)->None:
|
||||
valid_dict({"a": 0, "b": 1}, str, int, strict=False)
|
||||
|
||||
def testValidDictAnyKeyType(self)->None:
|
||||
valid_dict({"a": 0, "b": 1}, Any, int, strict=False)
|
||||
|
||||
def testValidDictAnyValueType(self)->None:
|
||||
valid_dict({"a": 0, "b": 1}, str, Any, strict=False)
|
||||
|
||||
def testValidDictAllRequiredKeys(self)->None:
|
||||
valid_dict({"a": 0, "b": 1}, str, int, required_keys=["a", "b"])
|
||||
|
||||
def testValidDictAllRequiredOrOptionalKeys(self)->None:
|
||||
valid_dict(
|
||||
{"a": 0, "b": 1}, str, int, required_keys=["a"],
|
||||
optional_keys=["b"])
|
||||
|
||||
def testValidDictExtraKeys(self)->None:
|
||||
valid_dict(
|
||||
{"a": 0, "b": 1, "c": 2}, str, int, required_keys=["a"],
|
||||
optional_keys=["b"], strict=False)
|
||||
|
||||
def testValidDictMissingRequiredKeys(self)->None:
|
||||
with self.assertRaises(KeyError):
|
||||
valid_dict(
|
||||
{"a": 0, "b": 1}, str, int, required_keys=["a", "b", "c"])
|
||||
|
||||
def testValidDictOverlyStrict(self)->None:
|
||||
with self.assertRaises(ValueError):
|
||||
valid_dict({"a": 0, "b": 1}, str, int)
|
Reference in New Issue
Block a user