-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* start of analyser tests * analyser error handling and testing
- Loading branch information
1 parent
e366b90
commit 76cf367
Showing
12 changed files
with
167 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,7 @@ def __run_lib_tests(): | |
"python", | ||
"-m", | ||
"pytest", | ||
"test", | ||
] | ||
) | ||
if returncode is 1: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from lib.common.analyser import Analyser | ||
import os | ||
import unittest | ||
from lib.common.exceptions import ( | ||
ElementShouldRetryError, | ||
ElementShouldSkipError, | ||
InvalidAnalyserConfigError, | ||
MTriageStorageCorruptedError, | ||
) | ||
from test.utils import ( | ||
TEMP_ELEMENT_DIR, | ||
scaffold_empty, | ||
scaffold_elementmap, | ||
cleanup, | ||
get_element_path, | ||
) | ||
import pandas | ||
|
||
|
||
class ErrorThrowingAnalyser(Analyser): | ||
def __init__(self, *args): | ||
super().__init__(*args) | ||
self.retryCount = 0 | ||
|
||
def analyse_element(self, element, config): | ||
if element["id"] == "skip": | ||
raise ElementShouldSkipError("test") | ||
elif element["id"] == "retry3" and self.retryCount < 3: | ||
self.retryCount += 1 | ||
raise ElementShouldRetryError("test") | ||
elif element["id"] == "retryN": | ||
raise ElementShouldRetryError("test") | ||
else: | ||
pass | ||
|
||
|
||
class TestAnalyserErrors(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(self): | ||
self.selname = "stub_sel" | ||
|
||
scaffold_empty(self.selname, elements=["skip", "retry3", "retryN", "pass"]) | ||
good = {"elements_in": [self.selname]} | ||
|
||
self.an = ErrorThrowingAnalyser(good, "analyserErrorSelector", TEMP_ELEMENT_DIR) | ||
|
||
@classmethod | ||
def tearDownClass(self): | ||
cleanup() | ||
|
||
def test_analyse_skip_error(self): | ||
with self.assertRaisesRegex(ElementShouldSkipError, "test - skipping element"): | ||
self.an.analyse_element({"id": "skip"}, {}) | ||
|
||
def test_analyse_retry_error(self): | ||
with self.assertRaisesRegex(ElementShouldRetryError, "test - attempt retry"): | ||
self.an.analyse_element({"id": "retryN"}, {}) | ||
|
||
def test_bad_init_error(self): | ||
bad0 = {} | ||
bad1 = {"elements_in": []} | ||
bad2 = {"elements_in": None} | ||
good = {"elements_in": ["selname"]} | ||
|
||
with self.assertRaisesRegex( | ||
InvalidAnalyserConfigError, "must contain an 'elements_in' whitelist" | ||
): | ||
no_elements_in = ErrorThrowingAnalyser(bad0, "stub", TEMP_ELEMENT_DIR) | ||
|
||
with self.assertRaisesRegex( | ||
InvalidAnalyserConfigError, | ||
"The 'elements_in' whitelist must be a list containing at least one string", | ||
): | ||
empty_elements_in = ErrorThrowingAnalyser(bad1, "stub", TEMP_ELEMENT_DIR) | ||
|
||
with self.assertRaisesRegex( | ||
InvalidAnalyserConfigError, | ||
"The 'elements_in' whitelist must be a list containing at least one string", | ||
): | ||
empty_elements_in = ErrorThrowingAnalyser(bad2, "stub", TEMP_ELEMENT_DIR) | ||
|
||
with self.assertRaisesRegex( | ||
InvalidAnalyserConfigError, "You must provide a name for your analyser" | ||
): | ||
badan2 = ErrorThrowingAnalyser(good, "", TEMP_ELEMENT_DIR) | ||
|
||
def test_integration(self): | ||
self.assertEqual(self.an.retryCount, 0) | ||
self.an.start_analysing() | ||
|
||
skip_path = get_element_path(self.selname, "skip", analyser=self.an.NAME) | ||
self.assertFalse(os.path.exists(skip_path)) | ||
|
||
retryn_path = get_element_path(self.selname, "retryN", analyser=self.an.NAME) | ||
self.assertFalse(os.path.exists(retryn_path)) | ||
|
||
retry3_path = get_element_path(self.selname, "retry3", analyser=self.an.NAME) | ||
self.assertEqual(self.an.retryCount, 3) | ||
self.assertTrue(os.path.exists(retry3_path)) | ||
|
||
pass_path = get_element_path(self.selname, "pass", analyser=self.an.NAME) | ||
self.assertTrue(os.path.exists(pass_path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters