added cvery brief descriptions to tests

This commit is contained in:
PatchOfScotland
2023-01-31 15:49:29 +01:00
parent adfce30508
commit f4c31b13df
8 changed files with 126 additions and 9 deletions

View File

@ -28,6 +28,7 @@ class MeowTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test LocalPythonConductor creation and job types
def testLocalPythonConductorCreation(self)->None: def testLocalPythonConductorCreation(self)->None:
lpc = LocalPythonConductor() lpc = LocalPythonConductor()
@ -35,6 +36,7 @@ class MeowTests(unittest.TestCase):
self.assertEqual(valid_jobs, [PYTHON_TYPE]) self.assertEqual(valid_jobs, [PYTHON_TYPE])
# Test LocalPythonConductor executes valid jobs
def testLocalPythonConductorValidJob(self)->None: def testLocalPythonConductorValidJob(self)->None:
lpc = LocalPythonConductor() lpc = LocalPythonConductor()
@ -99,6 +101,7 @@ class MeowTests(unittest.TestCase):
self.assertTrue(os.path.exists(result_path)) self.assertTrue(os.path.exists(result_path))
# Test LocalPythonConductor does not execute jobs with bad arguments
def testLocalPythonConductorBadArgs(self)->None: def testLocalPythonConductorBadArgs(self)->None:
lpc = LocalPythonConductor() lpc = LocalPythonConductor()
@ -189,6 +192,7 @@ class MeowTests(unittest.TestCase):
self.assertTrue(os.path.exists(result_path)) self.assertTrue(os.path.exists(result_path))
# Test LocalPythonConductor does not execute jobs with bad functions
def testLocalPythonConductorBadFunc(self)->None: def testLocalPythonConductorBadFunc(self)->None:
lpc = LocalPythonConductor() lpc = LocalPythonConductor()

View File

@ -34,6 +34,7 @@ class CorrectnessTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test that generate_id creates unique ids
def testGenerateIDWorking(self)->None: def testGenerateIDWorking(self)->None:
id = generate_id() id = generate_id()
self.assertEqual(len(id), 16) self.assertEqual(len(id), 16)
@ -61,6 +62,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(len(prefix_id), 16) self.assertEqual(len(prefix_id), 16)
self.assertTrue(prefix_id.startswith("Test")) self.assertTrue(prefix_id.startswith("Test"))
# Test that wait can wait on multiple pipes
def testWaitPipes(self)->None: def testWaitPipes(self)->None:
pipe_one_reader, pipe_one_writer = Pipe() pipe_one_reader, pipe_one_writer = Pipe()
pipe_two_reader, pipe_two_writer = Pipe() pipe_two_reader, pipe_two_writer = Pipe()
@ -92,6 +94,7 @@ class CorrectnessTests(unittest.TestCase):
msg = readable.recv() msg = readable.recv()
self.assertEqual(msg, 2) self.assertEqual(msg, 2)
# Test that wait can wait on multiple queues
def testWaitQueues(self)->None: def testWaitQueues(self)->None:
queue_one = Queue() queue_one = Queue()
queue_two = Queue() queue_two = Queue()
@ -124,6 +127,7 @@ class CorrectnessTests(unittest.TestCase):
msg = readable.get() msg = readable.get()
self.assertEqual(msg, 2) self.assertEqual(msg, 2)
# Test that wait can wait on multiple pipes and queues
def testWaitPipesAndQueues(self)->None: def testWaitPipesAndQueues(self)->None:
pipe_one_reader, pipe_one_writer = Pipe() pipe_one_reader, pipe_one_writer = Pipe()
pipe_two_reader, pipe_two_writer = Pipe() pipe_two_reader, pipe_two_writer = Pipe()
@ -197,6 +201,7 @@ class CorrectnessTests(unittest.TestCase):
msg = readable.recv() msg = readable.recv()
self.assertEqual(msg, 1) self.assertEqual(msg, 1)
# Test that get_file_hash produces the expected hash
def testGetFileHashSha256(self)->None: def testGetFileHashSha256(self)->None:
file_path = os.path.join(TEST_MONITOR_BASE, "hased_file.txt") file_path = os.path.join(TEST_MONITOR_BASE, "hased_file.txt")
with open(file_path, 'w') as hashed_file: with open(file_path, 'w') as hashed_file:
@ -207,12 +212,14 @@ class CorrectnessTests(unittest.TestCase):
hash = get_file_hash(file_path, SHA256) hash = get_file_hash(file_path, SHA256)
self.assertEqual(hash, expected_hash) self.assertEqual(hash, expected_hash)
# Test that get_file_hash raises on a missing file
def testGetFileHashSha256NoFile(self)->None: def testGetFileHashSha256NoFile(self)->None:
file_path = os.path.join(TEST_MONITOR_BASE, "file.txt") file_path = os.path.join(TEST_MONITOR_BASE, "file.txt")
with self.assertRaises(FileNotFoundError): with self.assertRaises(FileNotFoundError):
get_file_hash(file_path, SHA256) get_file_hash(file_path, SHA256)
# Test that parameterize_jupyter_notebook parameterises given notebook
def testParameteriseNotebook(self)->None: def testParameteriseNotebook(self)->None:
pn = parameterize_jupyter_notebook( pn = parameterize_jupyter_notebook(
COMPLETE_NOTEBOOK, {}) COMPLETE_NOTEBOOK, {})
@ -232,6 +239,7 @@ class CorrectnessTests(unittest.TestCase):
pn["cells"][0]["source"], pn["cells"][0]["source"],
"# The first cell\n\ns = 4\nnum = 1000") "# The first cell\n\ns = 4\nnum = 1000")
# Test that create_event produces valid event dictionary
def testCreateEvent(self)->None: def testCreateEvent(self)->None:
event = create_event("test", "path") event = create_event("test", "path")
@ -250,6 +258,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(event2[EVENT_PATH], "path2") self.assertEqual(event2[EVENT_PATH], "path2")
self.assertEqual(event2["a"], 1) self.assertEqual(event2["a"], 1)
# Test that create_job produces valid job dictionary
def testCreateJob(self)->None: def testCreateJob(self)->None:
pattern = FileEventPattern( pattern = FileEventPattern(
"pattern", "pattern",
@ -311,6 +320,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(JOB_REQUIREMENTS, job_dict) self.assertIn(JOB_REQUIREMENTS, job_dict)
self.assertEqual(job_dict[JOB_REQUIREMENTS], {}) self.assertEqual(job_dict[JOB_REQUIREMENTS], {})
# Test that replace_keywords replaces MEOW keywords in a given dictionary
def testReplaceKeywords(self)->None: def testReplaceKeywords(self)->None:
test_dict = { test_dict = {
"A": f"--{KEYWORD_PATH}--", "A": f"--{KEYWORD_PATH}--",
@ -359,6 +369,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(replaced["M"], "A") self.assertEqual(replaced["M"], "A")
self.assertEqual(replaced["N"], 1) self.assertEqual(replaced["N"], 1)
# Test that write_notebook can read jupyter notebooks to files
def testWriteNotebook(self)->None: def testWriteNotebook(self)->None:
notebook_path = os.path.join(TEST_MONITOR_BASE, "test_notebook.ipynb") notebook_path = os.path.join(TEST_MONITOR_BASE, "test_notebook.ipynb")
self.assertFalse(os.path.exists(notebook_path)) self.assertFalse(os.path.exists(notebook_path))
@ -402,6 +413,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(data, expected_bytes) self.assertEqual(data, expected_bytes)
# Test that read_notebook can read jupyter notebooks from files
def testReadNotebook(self)->None: def testReadNotebook(self)->None:
notebook_path = os.path.join(TEST_MONITOR_BASE, "test_notebook.ipynb") notebook_path = os.path.join(TEST_MONITOR_BASE, "test_notebook.ipynb")
write_notebook(APPENDING_NOTEBOOK, notebook_path) write_notebook(APPENDING_NOTEBOOK, notebook_path)
@ -409,7 +421,6 @@ class CorrectnessTests(unittest.TestCase):
notebook = read_notebook(notebook_path) notebook = read_notebook(notebook_path)
self.assertEqual(notebook, APPENDING_NOTEBOOK) self.assertEqual(notebook, APPENDING_NOTEBOOK)
with self.assertRaises(FileNotFoundError): with self.assertRaises(FileNotFoundError):
read_notebook("doesNotExist.ipynb") read_notebook("doesNotExist.ipynb")
@ -427,6 +438,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(json.decoder.JSONDecodeError): with self.assertRaises(json.decoder.JSONDecodeError):
read_notebook(filepath) read_notebook(filepath)
# Test that write_yaml can write dicts to yaml files
def testWriteYaml(self)->None: def testWriteYaml(self)->None:
yaml_dict = { yaml_dict = {
"A": "a", "A": "a",
@ -461,6 +473,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(data, expected_bytes) self.assertEqual(data, expected_bytes)
# Test that read_yaml can read yaml files
def testReadYaml(self)->None: def testReadYaml(self)->None:
yaml_dict = { yaml_dict = {
"A": "a", "A": "a",
@ -489,6 +502,7 @@ class CorrectnessTests(unittest.TestCase):
data = read_yaml(filepath) data = read_yaml(filepath)
self.assertEqual(data, "Data") self.assertEqual(data, "Data")
# Test that make_dir creates a directory and path to it
def testMakeDir(self)->None: def testMakeDir(self)->None:
testDir = os.path.join(TEST_MONITOR_BASE, "Test") testDir = os.path.join(TEST_MONITOR_BASE, "Test")
self.assertFalse(os.path.exists(testDir)) self.assertFalse(os.path.exists(testDir))
@ -516,6 +530,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertTrue(os.path.exists(halfway)) self.assertTrue(os.path.exists(halfway))
self.assertEqual(len(os.listdir(halfway)), 0) self.assertEqual(len(os.listdir(halfway)), 0)
# Test that rmtree removes a directory, its content, and subdirectory
def testRemoveTree(self)->None: def testRemoveTree(self)->None:
nested = os.path.join(TEST_MONITOR_BASE, "A", "B") nested = os.path.join(TEST_MONITOR_BASE, "A", "B")
self.assertFalse(os.path.exists(os.path.join(TEST_MONITOR_BASE, "A"))) self.assertFalse(os.path.exists(os.path.join(TEST_MONITOR_BASE, "A")))

View File

@ -30,6 +30,7 @@ class MeowTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test that BaseRecipe instantiation
def testBaseRecipe(self)->None: def testBaseRecipe(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BaseRecipe("name", "") BaseRecipe("name", "")
@ -48,6 +49,7 @@ class MeowTests(unittest.TestCase):
pass pass
FullRecipe("name", "") FullRecipe("name", "")
# Test that BaseRecipe instantiation
def testBasePattern(self)->None: def testBasePattern(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BasePattern("name", "", "", "") BasePattern("name", "", "", "")
@ -66,6 +68,7 @@ class MeowTests(unittest.TestCase):
pass pass
FullPattern("name", "", "", "") FullPattern("name", "", "", "")
# Test that BaseRecipe instantiation
def testBaseRule(self)->None: def testBaseRule(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BaseRule("name", "", "") BaseRule("name", "", "")
@ -84,6 +87,7 @@ class MeowTests(unittest.TestCase):
pass pass
FullRule("name", "", "") FullRule("name", "", "")
# Test that create_rule creates a rule from pattern and recipe
def testCreateRule(self)->None: def testCreateRule(self)->None:
rule = create_rule(valid_pattern_one, valid_recipe_one) rule = create_rule(valid_pattern_one, valid_recipe_one)
@ -92,11 +96,13 @@ class MeowTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
rule = create_rule(valid_pattern_one, valid_recipe_two) rule = create_rule(valid_pattern_one, valid_recipe_two)
# Test that create_rules creates nothing from nothing
def testCreateRulesMinimum(self)->None: def testCreateRulesMinimum(self)->None:
rules = create_rules({}, {}) rules = create_rules({}, {})
self.assertEqual(len(rules), 0) self.assertEqual(len(rules), 0)
# Test that create_rules creates rules from patterns and recipes
def testCreateRulesPatternsAndRecipesDicts(self)->None: def testCreateRulesPatternsAndRecipesDicts(self)->None:
patterns = { patterns = {
valid_pattern_one.name: valid_pattern_one, valid_pattern_one.name: valid_pattern_one,
@ -114,6 +120,7 @@ class MeowTests(unittest.TestCase):
self.assertIsInstance(rule, BaseRule) self.assertIsInstance(rule, BaseRule)
self.assertEqual(k, rule.name) self.assertEqual(k, rule.name)
# Test that create_rules creates nothing from invalid pattern inputs
def testCreateRulesMisindexedPatterns(self)->None: def testCreateRulesMisindexedPatterns(self)->None:
patterns = { patterns = {
valid_pattern_two.name: valid_pattern_one, valid_pattern_two.name: valid_pattern_one,
@ -122,6 +129,7 @@ class MeowTests(unittest.TestCase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
create_rules(patterns, {}) create_rules(patterns, {})
# Test that create_rules creates nothing from invalid recipe inputs
def testCreateRulesMisindexedRecipes(self)->None: def testCreateRulesMisindexedRecipes(self)->None:
recipes = { recipes = {
valid_recipe_two.name: valid_recipe_one, valid_recipe_two.name: valid_recipe_one,
@ -130,6 +138,7 @@ class MeowTests(unittest.TestCase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
create_rules({}, recipes) create_rules({}, recipes)
# Test that BaseMonitor instantiation
def testBaseMonitor(self)->None: def testBaseMonitor(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BaseMonitor({}, {}) BaseMonitor({}, {})
@ -170,6 +179,7 @@ class MeowTests(unittest.TestCase):
FullTestMonitor({}, {}) FullTestMonitor({}, {})
# Test that BaseHandler instantiation
def testBaseHandler(self)->None: def testBaseHandler(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BaseHandler() BaseHandler()
@ -194,6 +204,7 @@ class MeowTests(unittest.TestCase):
FullTestHandler() FullTestHandler()
# Test that BaseConductor instantiation
def testBaseConductor(self)->None: def testBaseConductor(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
BaseConductor() BaseConductor()

View File

@ -45,57 +45,70 @@ class CorrectnessTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test FileEventPattern created
def testFileEventPatternCreationMinimum(self)->None: def testFileEventPatternCreationMinimum(self)->None:
FileEventPattern("name", "path", "recipe", "file") FileEventPattern("name", "path", "recipe", "file")
# Test FileEventPattern not created with empty name
def testFileEventPatternCreationEmptyName(self)->None: def testFileEventPatternCreationEmptyName(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("", "path", "recipe", "file") FileEventPattern("", "path", "recipe", "file")
# Test FileEventPattern not created with empty path
def testFileEventPatternCreationEmptyPath(self)->None: def testFileEventPatternCreationEmptyPath(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("name", "", "recipe", "file") FileEventPattern("name", "", "recipe", "file")
# Test FileEventPattern not created with empty recipe
def testFileEventPatternCreationEmptyRecipe(self)->None: def testFileEventPatternCreationEmptyRecipe(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("name", "path", "", "file") FileEventPattern("name", "path", "", "file")
# Test FileEventPattern not created with empty file
def testFileEventPatternCreationEmptyFile(self)->None: def testFileEventPatternCreationEmptyFile(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("name", "path", "recipe", "") FileEventPattern("name", "path", "recipe", "")
# Test FileEventPattern not created with invalid name
def testFileEventPatternCreationInvalidName(self)->None: def testFileEventPatternCreationInvalidName(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("@name", "path", "recipe", "file") FileEventPattern("@name", "path", "recipe", "file")
# Test FileEventPattern not created with invalid recipe
def testFileEventPatternCreationInvalidRecipe(self)->None: def testFileEventPatternCreationInvalidRecipe(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("name", "path", "@recipe", "file") FileEventPattern("name", "path", "@recipe", "file")
# Test FileEventPattern not created with invalid file
def testFileEventPatternCreationInvalidFile(self)->None: def testFileEventPatternCreationInvalidFile(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventPattern("name", "path", "recipe", "@file") FileEventPattern("name", "path", "recipe", "@file")
# Test FileEventPattern created with valid name
def testFileEventPatternSetupName(self)->None: def testFileEventPatternSetupName(self)->None:
name = "name" name = "name"
fep = FileEventPattern(name, "path", "recipe", "file") fep = FileEventPattern(name, "path", "recipe", "file")
self.assertEqual(fep.name, name) self.assertEqual(fep.name, name)
# Test FileEventPattern created with valid path
def testFileEventPatternSetupPath(self)->None: def testFileEventPatternSetupPath(self)->None:
path = "path" path = "path"
fep = FileEventPattern("name", path, "recipe", "file") fep = FileEventPattern("name", path, "recipe", "file")
self.assertEqual(fep.triggering_path, path) self.assertEqual(fep.triggering_path, path)
# Test FileEventPattern created with valid recipe
def testFileEventPatternSetupRecipe(self)->None: def testFileEventPatternSetupRecipe(self)->None:
recipe = "recipe" recipe = "recipe"
fep = FileEventPattern("name", "path", recipe, "file") fep = FileEventPattern("name", "path", recipe, "file")
self.assertEqual(fep.recipe, recipe) self.assertEqual(fep.recipe, recipe)
# Test FileEventPattern created with valid file
def testFileEventPatternSetupFile(self)->None: def testFileEventPatternSetupFile(self)->None:
file = "file" file = "file"
fep = FileEventPattern("name", "path", "recipe", file) fep = FileEventPattern("name", "path", "recipe", file)
self.assertEqual(fep.triggering_file, file) self.assertEqual(fep.triggering_file, file)
# Test FileEventPattern created with valid parameters
def testFileEventPatternSetupParementers(self)->None: def testFileEventPatternSetupParementers(self)->None:
parameters = { parameters = {
"a": 1, "a": 1,
@ -105,6 +118,7 @@ class CorrectnessTests(unittest.TestCase):
"name", "path", "recipe", "file", parameters=parameters) "name", "path", "recipe", "file", parameters=parameters)
self.assertEqual(fep.parameters, parameters) self.assertEqual(fep.parameters, parameters)
# Test FileEventPattern created with valid outputs
def testFileEventPatternSetupOutputs(self)->None: def testFileEventPatternSetupOutputs(self)->None:
outputs = { outputs = {
"a": "a", "a": "a",
@ -114,6 +128,7 @@ class CorrectnessTests(unittest.TestCase):
"name", "path", "recipe", "file", outputs=outputs) "name", "path", "recipe", "file", outputs=outputs)
self.assertEqual(fep.outputs, outputs) self.assertEqual(fep.outputs, outputs)
# Test FileEventPattern created with valid event mask
def testFileEventPatternEventMask(self)->None: def testFileEventPatternEventMask(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
self.assertEqual(fep.event_mask, _DEFAULT_MASK) self.assertEqual(fep.event_mask, _DEFAULT_MASK)
@ -130,6 +145,7 @@ class CorrectnessTests(unittest.TestCase):
fep = FileEventPattern("name", "path", "recipe", "file", fep = FileEventPattern("name", "path", "recipe", "file",
event_mask=[FILE_CREATE_EVENT, "nope"]) event_mask=[FILE_CREATE_EVENT, "nope"])
# Test FileEventPattern created with valid parameter sweep
def testFileEventPatternSweep(self)->None: def testFileEventPatternSweep(self)->None:
sweeps = { sweeps = {
'first':{ 'first':{
@ -168,10 +184,12 @@ class CorrectnessTests(unittest.TestCase):
fep = FileEventPattern("name", "path", "recipe", "file", fep = FileEventPattern("name", "path", "recipe", "file",
sweep=bad_sweep) sweep=bad_sweep)
# Test WatchdogMonitor created
def testWatchdogMonitorMinimum(self)->None: def testWatchdogMonitorMinimum(self)->None:
from_monitor = Pipe() from_monitor = Pipe()
WatchdogMonitor(TEST_MONITOR_BASE, {}, {}, from_monitor[1]) WatchdogMonitor(TEST_MONITOR_BASE, {}, {}, from_monitor[1])
# Test WatchdogMonitor identifies expected events in base directory
def testWatchdogMonitorEventIdentificaion(self)->None: def testWatchdogMonitorEventIdentificaion(self)->None:
from_monitor_reader, from_monitor_writer = Pipe() from_monitor_reader, from_monitor_writer = Pipe()
@ -210,7 +228,8 @@ class CorrectnessTests(unittest.TestCase):
self.assertTrue(WATCHDOG_BASE in event.keys()) self.assertTrue(WATCHDOG_BASE in event.keys())
self.assertTrue(WATCHDOG_RULE in event.keys()) self.assertTrue(WATCHDOG_RULE in event.keys())
self.assertEqual(event[EVENT_TYPE], WATCHDOG_TYPE) self.assertEqual(event[EVENT_TYPE], WATCHDOG_TYPE)
self.assertEqual(event[EVENT_PATH], os.path.join(TEST_MONITOR_BASE, "A")) self.assertEqual(event[EVENT_PATH],
os.path.join(TEST_MONITOR_BASE, "A"))
self.assertEqual(event[WATCHDOG_BASE], TEST_MONITOR_BASE) self.assertEqual(event[WATCHDOG_BASE], TEST_MONITOR_BASE)
self.assertEqual(event[WATCHDOG_RULE].name, rule.name) self.assertEqual(event[WATCHDOG_RULE].name, rule.name)
@ -223,6 +242,7 @@ class CorrectnessTests(unittest.TestCase):
wm.stop() wm.stop()
# Test WatchdogMonitor identifies expected events in sub directories
def testMonitoring(self)->None: def testMonitoring(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -237,15 +257,10 @@ class CorrectnessTests(unittest.TestCase):
recipe.name: recipe, recipe.name: recipe,
} }
monitor_debug_stream = io.StringIO("")
wm = WatchdogMonitor( wm = WatchdogMonitor(
TEST_MONITOR_BASE, TEST_MONITOR_BASE,
patterns, patterns,
recipes, recipes,
print=monitor_debug_stream,
logging=3,
settletime=1
) )
rules = wm.get_rules() rules = wm.get_rules()
@ -286,6 +301,7 @@ class CorrectnessTests(unittest.TestCase):
wm.stop() wm.stop()
# Test WatchdogMonitor identifies fake events for retroactive patterns
def testMonitoringRetroActive(self)->None: def testMonitoringRetroActive(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -349,6 +365,7 @@ class CorrectnessTests(unittest.TestCase):
wm.stop() wm.stop()
# Test WatchdogMonitor get_patterns function
def testMonitorGetPatterns(self)->None: def testMonitorGetPatterns(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -375,6 +392,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(pattern_two.name, patterns) self.assertIn(pattern_two.name, patterns)
patterns_equal(self, patterns[pattern_two.name], pattern_two) patterns_equal(self, patterns[pattern_two.name], pattern_two)
# Test WatchdogMonitor add_pattern function
def testMonitorAddPattern(self)->None: def testMonitorAddPattern(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -419,6 +437,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(pattern_two.name, patterns) self.assertIn(pattern_two.name, patterns)
patterns_equal(self, patterns[pattern_two.name], pattern_two) patterns_equal(self, patterns[pattern_two.name], pattern_two)
# Test WatchdogMonitor update_patterns function
def testMonitorUpdatePattern(self)->None: def testMonitorUpdatePattern(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -480,6 +499,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(pattern_one.name, patterns) self.assertIn(pattern_one.name, patterns)
patterns_equal(self, patterns[pattern_one.name], pattern_one) patterns_equal(self, patterns[pattern_one.name], pattern_one)
# Test WatchdogMonitor remove_patterns function
def testMonitorRemovePattern(self)->None: def testMonitorRemovePattern(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -518,6 +538,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIsInstance(patterns, dict) self.assertIsInstance(patterns, dict)
self.assertEqual(len(patterns), 0) self.assertEqual(len(patterns), 0)
# Test WatchdogMonitor get_recipes function
def testMonitorGetRecipes(self)->None: def testMonitorGetRecipes(self)->None:
recipe_one = JupyterNotebookRecipe( recipe_one = JupyterNotebookRecipe(
"recipe_one", BAREBONES_NOTEBOOK) "recipe_one", BAREBONES_NOTEBOOK)
@ -542,6 +563,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(recipe_two.name, recipes) self.assertIn(recipe_two.name, recipes)
recipes_equal(self, recipes[recipe_two.name], recipe_two) recipes_equal(self, recipes[recipe_two.name], recipe_two)
# Test WatchdogMonitor add_recipe function
def testMonitorAddRecipe(self)->None: def testMonitorAddRecipe(self)->None:
recipe_one = JupyterNotebookRecipe( recipe_one = JupyterNotebookRecipe(
"recipe_one", BAREBONES_NOTEBOOK) "recipe_one", BAREBONES_NOTEBOOK)
@ -587,6 +609,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(recipe_two.name, recipes) self.assertIn(recipe_two.name, recipes)
recipes_equal(self, recipes[recipe_two.name], recipe_two) recipes_equal(self, recipes[recipe_two.name], recipe_two)
# Test WatchdogMonitor update_recipe function
def testMonitorUpdateRecipe(self)->None: def testMonitorUpdateRecipe(self)->None:
recipe_one = JupyterNotebookRecipe( recipe_one = JupyterNotebookRecipe(
"recipe_one", BAREBONES_NOTEBOOK) "recipe_one", BAREBONES_NOTEBOOK)
@ -642,6 +665,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIn(recipe_one.name, recipes) self.assertIn(recipe_one.name, recipes)
recipes_equal(self, recipes[recipe_one.name], recipe_one) recipes_equal(self, recipes[recipe_one.name], recipe_one)
# Test WatchdogMonitor remove_recipe function
def testMonitorRemoveRecipe(self)->None: def testMonitorRemoveRecipe(self)->None:
recipe_one = JupyterNotebookRecipe( recipe_one = JupyterNotebookRecipe(
"recipe_one", BAREBONES_NOTEBOOK) "recipe_one", BAREBONES_NOTEBOOK)
@ -680,6 +704,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertIsInstance(recipes, dict) self.assertIsInstance(recipes, dict)
self.assertEqual(len(recipes), 0) self.assertEqual(len(recipes), 0)
# Test WatchdogMonitor get_rules function
def testMonitorGetRules(self)->None: def testMonitorGetRules(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",

View File

@ -30,44 +30,54 @@ class CorrectnessTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test JupyterNotebookRecipe can be created
def testJupyterNotebookRecipeCreationMinimum(self)->None: def testJupyterNotebookRecipeCreationMinimum(self)->None:
JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK) JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK)
# Test JupyterNotebookRecipe can be created with source
def testJupyterNotebookRecipeCreationSource(self)->None: def testJupyterNotebookRecipeCreationSource(self)->None:
JupyterNotebookRecipe( JupyterNotebookRecipe(
"test_recipe", BAREBONES_NOTEBOOK, source="notebook.ipynb") "test_recipe", BAREBONES_NOTEBOOK, source="notebook.ipynb")
# Test JupyterNotebookRecipe cannot be created without name
def testJupyterNotebookRecipeCreationNoName(self)->None: def testJupyterNotebookRecipeCreationNoName(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
JupyterNotebookRecipe("", BAREBONES_NOTEBOOK) JupyterNotebookRecipe("", BAREBONES_NOTEBOOK)
# Test JupyterNotebookRecipe cannot be created with invalid name
def testJupyterNotebookRecipeCreationInvalidName(self)->None: def testJupyterNotebookRecipeCreationInvalidName(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
JupyterNotebookRecipe("@test_recipe", BAREBONES_NOTEBOOK) JupyterNotebookRecipe("@test_recipe", BAREBONES_NOTEBOOK)
# Test JupyterNotebookRecipe cannot be created with invalid recipe
def testJupyterNotebookRecipeCreationInvalidRecipe(self)->None: def testJupyterNotebookRecipeCreationInvalidRecipe(self)->None:
with self.assertRaises(jsonschema.exceptions.ValidationError): with self.assertRaises(jsonschema.exceptions.ValidationError):
JupyterNotebookRecipe("test_recipe", {}) JupyterNotebookRecipe("test_recipe", {})
# Test JupyterNotebookRecipe cannot be created with invalid source
def testJupyterNotebookRecipeCreationInvalidSourceExtension(self)->None: def testJupyterNotebookRecipeCreationInvalidSourceExtension(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
JupyterNotebookRecipe( JupyterNotebookRecipe(
"test_recipe", BAREBONES_NOTEBOOK, source="notebook") "test_recipe", BAREBONES_NOTEBOOK, source="notebook")
# Test JupyterNotebookRecipe cannot be created with invalid source name
def testJupyterNotebookRecipeCreationInvalidSoureChar(self)->None: def testJupyterNotebookRecipeCreationInvalidSoureChar(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
JupyterNotebookRecipe( JupyterNotebookRecipe(
"test_recipe", BAREBONES_NOTEBOOK, source="@notebook.ipynb") "test_recipe", BAREBONES_NOTEBOOK, source="@notebook.ipynb")
# Test JupyterNotebookRecipe name setup correctly
def testJupyterNotebookRecipeSetupName(self)->None: def testJupyterNotebookRecipeSetupName(self)->None:
name = "name" name = "name"
jnr = JupyterNotebookRecipe(name, BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe(name, BAREBONES_NOTEBOOK)
self.assertEqual(jnr.name, name) self.assertEqual(jnr.name, name)
# Test JupyterNotebookRecipe recipe setup correctly
def testJupyterNotebookRecipeSetupRecipe(self)->None: def testJupyterNotebookRecipeSetupRecipe(self)->None:
jnr = JupyterNotebookRecipe("name", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("name", BAREBONES_NOTEBOOK)
self.assertEqual(jnr.recipe, BAREBONES_NOTEBOOK) self.assertEqual(jnr.recipe, BAREBONES_NOTEBOOK)
# Test JupyterNotebookRecipe parameters setup correctly
def testJupyterNotebookRecipeSetupParameters(self)->None: def testJupyterNotebookRecipeSetupParameters(self)->None:
parameters = { parameters = {
"a": 1, "a": 1,
@ -77,6 +87,7 @@ class CorrectnessTests(unittest.TestCase):
"name", BAREBONES_NOTEBOOK, parameters=parameters) "name", BAREBONES_NOTEBOOK, parameters=parameters)
self.assertEqual(jnr.parameters, parameters) self.assertEqual(jnr.parameters, parameters)
# Test JupyterNotebookRecipe requirements setup correctly
def testJupyterNotebookRecipeSetupRequirements(self)->None: def testJupyterNotebookRecipeSetupRequirements(self)->None:
requirements = { requirements = {
"a": 1, "a": 1,
@ -86,18 +97,21 @@ class CorrectnessTests(unittest.TestCase):
"name", BAREBONES_NOTEBOOK, requirements=requirements) "name", BAREBONES_NOTEBOOK, requirements=requirements)
self.assertEqual(jnr.requirements, requirements) self.assertEqual(jnr.requirements, requirements)
# Test JupyterNotebookRecipe source setup correctly
def testJupyterNotebookRecipeSetupSource(self)->None: def testJupyterNotebookRecipeSetupSource(self)->None:
source = "source.ipynb" source = "source.ipynb"
jnr = JupyterNotebookRecipe( jnr = JupyterNotebookRecipe(
"name", BAREBONES_NOTEBOOK, source=source) "name", BAREBONES_NOTEBOOK, source=source)
self.assertEqual(jnr.source, source) self.assertEqual(jnr.source, source)
# Test PapermillHandler can be created
def testPapermillHanderMinimum(self)->None: def testPapermillHanderMinimum(self)->None:
PapermillHandler( PapermillHandler(
TEST_HANDLER_BASE, TEST_HANDLER_BASE,
TEST_JOB_OUTPUT TEST_JOB_OUTPUT
) )
# Test PapermillHandler will handle given events
def testPapermillHandlerHandling(self)->None: def testPapermillHandlerHandling(self)->None:
from_handler_reader, from_handler_writer = Pipe() from_handler_reader, from_handler_writer = Pipe()
ph = PapermillHandler( ph = PapermillHandler(
@ -147,6 +161,7 @@ class CorrectnessTests(unittest.TestCase):
valid_job(job) valid_job(job)
# Test jobFunc performs as expected
def testJobFunc(self)->None: def testJobFunc(self)->None:
file_path = os.path.join(TEST_MONITOR_BASE, "test") file_path = os.path.join(TEST_MONITOR_BASE, "test")
result_path = os.path.join(TEST_MONITOR_BASE, "output", "test") result_path = os.path.join(TEST_MONITOR_BASE, "output", "test")
@ -209,6 +224,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertTrue(os.path.exists(result_path)) self.assertTrue(os.path.exists(result_path))
# Test jobFunc doesn't execute with no args
def testJobFuncBadArgs(self)->None: def testJobFuncBadArgs(self)->None:
try: try:
job_func({}) job_func({})

View File

@ -16,12 +16,14 @@ class CorrectnessTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test FileEventJupyterNotebookRule created from valid pattern and recipe
def testFileEventJupyterNotebookRuleCreationMinimum(self)->None: def testFileEventJupyterNotebookRuleCreationMinimum(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
FileEventJupyterNotebookRule("name", fep, jnr) FileEventJupyterNotebookRule("name", fep, jnr)
# Test FileEventJupyterNotebookRule not created with empty name
def testFileEventJupyterNotebookRuleCreationNoName(self)->None: def testFileEventJupyterNotebookRuleCreationNoName(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
@ -29,6 +31,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventJupyterNotebookRule("", fep, jnr) FileEventJupyterNotebookRule("", fep, jnr)
# Test FileEventJupyterNotebookRule not created with invalid name
def testFileEventJupyterNotebookRuleCreationInvalidName(self)->None: def testFileEventJupyterNotebookRuleCreationInvalidName(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
@ -36,18 +39,21 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
FileEventJupyterNotebookRule(1, fep, jnr) FileEventJupyterNotebookRule(1, fep, jnr)
# Test FileEventJupyterNotebookRule not created with invalid pattern
def testFileEventJupyterNotebookRuleCreationInvalidPattern(self)->None: def testFileEventJupyterNotebookRuleCreationInvalidPattern(self)->None:
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
FileEventJupyterNotebookRule("name", "pattern", jnr) FileEventJupyterNotebookRule("name", "pattern", jnr)
# Test FileEventJupyterNotebookRule not created with invalid recipe
def testFileEventJupyterNotebookRuleCreationInvalidRecipe(self)->None: def testFileEventJupyterNotebookRuleCreationInvalidRecipe(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
FileEventJupyterNotebookRule("name", fep, "recipe") FileEventJupyterNotebookRule("name", fep, "recipe")
# Test FileEventJupyterNotebookRule not created with mismatched recipe
def testFileEventJupyterNotebookRuleCreationMissmatchedRecipe(self)->None: def testFileEventJupyterNotebookRuleCreationMissmatchedRecipe(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("test_recipe", BAREBONES_NOTEBOOK)
@ -55,6 +61,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
FileEventJupyterNotebookRule("name", fep, jnr) FileEventJupyterNotebookRule("name", fep, jnr)
# Test FileEventJupyterNotebookRule created with valid name
def testFileEventJupyterNotebookRuleSetupName(self)->None: def testFileEventJupyterNotebookRuleSetupName(self)->None:
name = "name" name = "name"
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
@ -64,6 +71,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(fejnr.name, name) self.assertEqual(fejnr.name, name)
# Test FileEventJupyterNotebookRule not created with valid pattern
def testFileEventJupyterNotebookRuleSetupPattern(self)->None: def testFileEventJupyterNotebookRuleSetupPattern(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)
@ -72,6 +80,7 @@ class CorrectnessTests(unittest.TestCase):
self.assertEqual(fejnr.pattern, fep) self.assertEqual(fejnr.pattern, fep)
# Test FileEventJupyterNotebookRule not created with valid recipe
def testFileEventJupyterNotebookRuleSetupRecipe(self)->None: def testFileEventJupyterNotebookRuleSetupRecipe(self)->None:
fep = FileEventPattern("name", "path", "recipe", "file") fep = FileEventPattern("name", "path", "recipe", "file")
jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK) jnr = JupyterNotebookRecipe("recipe", BAREBONES_NOTEBOOK)

View File

@ -26,6 +26,7 @@ class MeowTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test MeowRunner creation
def testMeowRunnerSetup(self)->None: def testMeowRunnerSetup(self)->None:
monitor_one = WatchdogMonitor(TEST_MONITOR_BASE, {}, {}) monitor_one = WatchdogMonitor(TEST_MONITOR_BASE, {}, {})
@ -166,6 +167,7 @@ class MeowTests(unittest.TestCase):
for rc in relevent_conductors: for rc in relevent_conductors:
self.assertIn(rc, runner.conductors[job_type]) self.assertIn(rc, runner.conductors[job_type])
# Test single meow job execution
def testMeowRunnerExecution(self)->None: def testMeowRunnerExecution(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",
@ -251,6 +253,7 @@ class MeowTests(unittest.TestCase):
self.assertEqual(data, "Initial Data\nA line from a test Pattern") self.assertEqual(data, "Initial Data\nA line from a test Pattern")
# Test meow job chaining within runner
def testMeowRunnerLinkedExecution(self)->None: def testMeowRunnerLinkedExecution(self)->None:
pattern_one = FileEventPattern( pattern_one = FileEventPattern(
"pattern_one", "start/A.txt", "recipe_one", "infile", "pattern_one", "start/A.txt", "recipe_one", "infile",

View File

@ -25,105 +25,130 @@ class CorrectnessTests(unittest.TestCase):
super().tearDown() super().tearDown()
teardown() teardown()
# Test check_type accepts valid types
def testCheckTypeValid(self)->None: def testCheckTypeValid(self)->None:
check_type(1, int) check_type(1, int)
check_type(0, int) check_type(0, int)
check_type(False, bool) check_type(False, bool)
check_type(True, bool) check_type(True, bool)
# Test check_type accepts Any type
def testCheckTypeValidAny(self)->None: def testCheckTypeValidAny(self)->None:
check_type(1, Any) check_type(1, Any)
# Test check_type accepts Union of types
def testCheckTypeValidUnion(self)->None: def testCheckTypeValidUnion(self)->None:
check_type(1, Union[int,str]) check_type(1, Union[int,str])
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
check_type(Union[int, str], Union[int,str]) check_type(Union[int, str], Union[int,str])
# Test check_type raises on mismatched type
def testCheckTypeMistyped(self)->None: def testCheckTypeMistyped(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
check_type(1, str) check_type(1, str)
# Test or_none arg for check_type
def testCheckTypeOrNone(self)->None: def testCheckTypeOrNone(self)->None:
check_type(None, int, or_none=True) check_type(None, int, or_none=True)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
check_type(None, int, or_none=False) check_type(None, int, or_none=False)
# Test valid_string with valid chars
def testValidStringValid(self)->None: def testValidStringValid(self)->None:
valid_string("David_Marchant", VALID_NAME_CHARS) valid_string("David_Marchant", VALID_NAME_CHARS)
# Test valid_string with empty input
def testValidStringEmptyString(self)->None: def testValidStringEmptyString(self)->None:
valid_string("", VALID_NAME_CHARS, min_length=0) valid_string("", VALID_NAME_CHARS, min_length=0)
# Test valid_string with no valid chars
def testValidStringNoValidChars(self)->None: def testValidStringNoValidChars(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_string("David_Marchant", "") valid_string("David_Marchant", "")
# Test valid_string with wrong types
def testValidStringMistypedInput(self)->None: def testValidStringMistypedInput(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
valid_string(1, VALID_NAME_CHARS) valid_string(1, VALID_NAME_CHARS)
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
valid_string("David_Marchant", 1) valid_string("David_Marchant", 1)
# Test valid_string with invalid chars
def testValidStringMissingChars(self)->None: def testValidStringMissingChars(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_string("David Marchant", VALID_NAME_CHARS) valid_string("David Marchant", VALID_NAME_CHARS)
# Test valid_string with not long enough input
def testValidStringInsufficientLength(self)->None: def testValidStringInsufficientLength(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_string("", VALID_NAME_CHARS) valid_string("", VALID_NAME_CHARS)
valid_string("David Marchant", VALID_NAME_CHARS, min_length=50) valid_string("David Marchant", VALID_NAME_CHARS, min_length=50)
# Test valid_dict with not long enough input
def testValidDictMinimum(self)->None: def testValidDictMinimum(self)->None:
valid_dict({"a": 0, "b": 1}, str, int, strict=False) valid_dict({"a": 0, "b": 1}, str, int, strict=False)
# Test valid_dict with invalid key types
def testValidDictAnyKeyType(self)->None: def testValidDictAnyKeyType(self)->None:
valid_dict({"a": 0, "b": 1}, Any, int, strict=False) valid_dict({"a": 0, "b": 1}, Any, int, strict=False)
# Test valid_dict with invalid value types
def testValidDictAnyValueType(self)->None: def testValidDictAnyValueType(self)->None:
valid_dict({"a": 0, "b": 1}, str, Any, strict=False) valid_dict({"a": 0, "b": 1}, str, Any, strict=False)
# Test valid_dict with required keys
def testValidDictAllRequiredKeys(self)->None: def testValidDictAllRequiredKeys(self)->None:
valid_dict({"a": 0, "b": 1}, str, int, required_keys=["a", "b"]) valid_dict({"a": 0, "b": 1}, str, int, required_keys=["a", "b"])
# Test valid_dict with required and optional keys
def testValidDictAllRequiredOrOptionalKeys(self)->None: def testValidDictAllRequiredOrOptionalKeys(self)->None:
valid_dict( valid_dict(
{"a": 0, "b": 1}, str, int, required_keys=["a"], {"a": 0, "b": 1}, str, int, required_keys=["a"],
optional_keys=["b"]) optional_keys=["b"])
# Test valid_dict with extra keys
def testValidDictExtraKeys(self)->None: def testValidDictExtraKeys(self)->None:
valid_dict( valid_dict(
{"a": 0, "b": 1, "c": 2}, str, int, required_keys=["a"], {"a": 0, "b": 1, "c": 2}, str, int, required_keys=["a"],
optional_keys=["b"], strict=False) optional_keys=["b"], strict=False)
# Test valid_dict with missing required keys
def testValidDictMissingRequiredKeys(self)->None: def testValidDictMissingRequiredKeys(self)->None:
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
valid_dict( valid_dict(
{"a": 0, "b": 1}, str, int, required_keys=["a", "b", "c"]) {"a": 0, "b": 1}, str, int, required_keys=["a", "b", "c"])
# Test strict checking of valid_dict
def testValidDictOverlyStrict(self)->None: def testValidDictOverlyStrict(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_dict({"a": 0, "b": 1}, str, int) valid_dict({"a": 0, "b": 1}, str, int, strict=True)
# Test valid_list with sufficent lengths
def testValidListMinimum(self)->None: def testValidListMinimum(self)->None:
valid_list([1, 2, 3], int) valid_list([1, 2, 3], int)
valid_list(["1", "2", "3"], str) valid_list(["1", "2", "3"], str)
valid_list([1], int) valid_list([1], int)
# Test valid_list with alternate types
def testValidListAltTypes(self)->None: def testValidListAltTypes(self)->None:
valid_list([1, "2", 3], int, alt_types=[str]) valid_list([1, "2", 3], int, alt_types=[str])
# Test valid_list with wrong type
def testValidListMismatchedNotList(self)->None: def testValidListMismatchedNotList(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
valid_list((1, 2, 3), int) valid_list((1, 2, 3), int)
# Test valid_list with mismatch value types
def testValidListMismatchedType(self)->None: def testValidListMismatchedType(self)->None:
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
valid_list([1, 2, 3], str) valid_list([1, 2, 3], str)
# Test valid_list with insufficient length
def testValidListMinLength(self)->None: def testValidListMinLength(self)->None:
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_list([1, 2, 3], str, min_length=10) valid_list([1, 2, 3], str, min_length=10)
# Test check_implementation doesn't raise on implemented
def testCheckImplementationMinimum(self)->None: def testCheckImplementationMinimum(self)->None:
class Parent: class Parent:
def func(): def func():
@ -135,6 +160,7 @@ class CorrectnessTests(unittest.TestCase):
check_implementation(Child.func, Parent) check_implementation(Child.func, Parent)
# Test check_implementation does raise on not implemented
def testCheckImplementationUnaltered(self)->None: def testCheckImplementationUnaltered(self)->None:
class Parent: class Parent:
def func(): def func():
@ -146,6 +172,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(NotImplementedError): with self.assertRaises(NotImplementedError):
check_implementation(Child.func, Parent) check_implementation(Child.func, Parent)
# Test check_implementation does raise on differing signature
def testCheckImplementationDifferingSig(self)->None: def testCheckImplementationDifferingSig(self)->None:
class Parent: class Parent:
def func(): def func():
@ -158,6 +185,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(NotImplementedError): with self.assertRaises(NotImplementedError):
check_implementation(Child.func, Parent) check_implementation(Child.func, Parent)
# Test check_implementation doesn't raise on Any type in signature
def testCheckImplementationAnyType(self)->None: def testCheckImplementationAnyType(self)->None:
class Parent: class Parent:
def func(var:Any): def func(var:Any):
@ -169,6 +197,7 @@ class CorrectnessTests(unittest.TestCase):
check_implementation(Child.func, Parent) check_implementation(Child.func, Parent)
# Test valid_existing_file_path can find files, or not
def testValidExistingFilePath(self)->None: def testValidExistingFilePath(self)->None:
file_path = os.path.join(TEST_MONITOR_BASE, "file.txt") file_path = os.path.join(TEST_MONITOR_BASE, "file.txt")
with open(file_path, 'w') as hashed_file: with open(file_path, 'w') as hashed_file:
@ -185,6 +214,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_existing_file_path(dir_path, SHA256) valid_existing_file_path(dir_path, SHA256)
# Test valid_existing_dir_path can find directories, or not
def testValidExistingDirPath(self)->None: def testValidExistingDirPath(self)->None:
valid_existing_dir_path(TEST_MONITOR_BASE) valid_existing_dir_path(TEST_MONITOR_BASE)
@ -200,6 +230,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_existing_dir_path(file_path, SHA256) valid_existing_dir_path(file_path, SHA256)
# Test valid_non_existing_path can find existing paths, or not
def testValidNonExistingPath(self)->None: def testValidNonExistingPath(self)->None:
valid_non_existing_path("does_not_exist") valid_non_existing_path("does_not_exist")
@ -211,6 +242,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
valid_non_existing_path("first/second") valid_non_existing_path("first/second")
# Test valid_event can check given event dictionary
def testEventValidation(self)->None: def testEventValidation(self)->None:
valid_event({EVENT_TYPE: "test", EVENT_PATH: "path"}) valid_event({EVENT_TYPE: "test", EVENT_PATH: "path"})
valid_event({EVENT_TYPE: "anything", EVENT_PATH: "path", "a": 1}) valid_event({EVENT_TYPE: "anything", EVENT_PATH: "path", "a": 1})
@ -224,6 +256,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
valid_event({}) valid_event({})
# Test valid_job can check given job dictionary
def testJobValidation(self)->None: def testJobValidation(self)->None:
valid_job({ valid_job({
JOB_TYPE: "test", JOB_TYPE: "test",
@ -245,6 +278,7 @@ class CorrectnessTests(unittest.TestCase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
valid_job({}) valid_job({})
# Test setup_debugging will create writeable location
def testSetupDebugging(self)->None: def testSetupDebugging(self)->None:
stream = io.StringIO("") stream = io.StringIO("")