Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def compare(expected, actual): # type: (Any, Any) -> None
if expected == "Any":
return
if expected is not None and actual is None:
raise CompareFail.format(expected, actual)
try:
if isinstance(expected, dict):
if not isinstance(actual, dict):
raise CompareFail.format(expected, actual)
if expected.get("class") == "File":
compare_file(expected, actual)
elif expected.get("class") == "Directory":
compare_directory(expected, actual)
else:
compare_dict(expected, actual)
elif isinstance(expected, list):
if not isinstance(actual, list):
raise CompareFail.format(expected, actual)
if not isinstance(actual, list):
raise CompareFail.format(expected, actual)
if len(expected) != len(actual):
raise CompareFail.format(expected, actual, u"lengths don't match")
for c in range(0, len(expected)):
try:
compare(expected[c], actual[c])
except CompareFail as e:
raise CompareFail.format(expected, actual, e)
else:
if expected != actual:
raise CompareFail.format(expected, actual)
except Exception as e:
raise CompareFail(str(e))
fail_message = ""
if test.get("should_fail", False):
_logger.warning(
u"""Test %i failed: %s""",
test_number,
u" ".join([quote(tc) for tc in test_command]),
)
_logger.warning(test.get("doc"))
_logger.warning(u"Returned zero but it should be non-zero")
return TestResult(1, outstr, outerr, duration, args.classname)
try:
compare(test.get("output"), out)
except CompareFail as ex:
_logger.warning(
u"""Test %i failed: %s""",
test_number,
u" ".join([quote(tc) for tc in test_command]),
)
_logger.warning(test.get("doc"))
_logger.warning(u"Compare failure %s", ex)
fail_message = str(ex)
if outdir:
shutil.rmtree(outdir, True)
return TestResult(
(1 if fail_message else 0),
outstr,
outerr,
if actual.get("class") != "Directory":
raise CompareFail.format(
expected, actual, u"expected object with a class 'Directory'"
)
if "listing" not in actual:
raise CompareFail.format(
expected, actual, u"'listing' is mandatory field in Directory object"
)
for i in expected["listing"]:
found = False
for j in actual["listing"]:
try:
compare(i, j)
found = True
break
except CompareFail:
pass
if not found:
raise CompareFail.format(
expected,
actual,
u"%s not found" % json.dumps(i, indent=4, sort_keys=True),
)
compare_file(expected, actual)