Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
spark_cmd = spark_cmd_v2 + ' --hostfile ' + hostfile_path
pid = subprocess.Popen(spark_cmd_v2, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE);
stdout_string, stderr_string = pid.communicate()
if(pid.returncode != 0):
sys.stderr.write('Query test V2: '+test_name+' with query file '+query_json_filename+' failed\n');
sys.stderr.write('Spark command was: '+spark_cmd_v2+'\n');
sys.stderr.write('Spark stdout was: '+stdout_string+'\n');
sys.stderr.write('Spark stderr was: '+stderr_string+'\n');
sys.stderr.write('Query file was: '+json.dumps(test_query_dict)+'\n');
cleanup_and_exit(namenode, tmpdir, -1);
stdout_list = stdout_string.splitlines(True);
stdout_filter = "".join(stdout_list);
stdout_json = json.loads(stdout_filter);
if('golden_output' in query_param_dict and 'spark' in query_param_dict['golden_output']):
json_golden = get_json_from_file(query_param_dict['golden_output']['spark']+'_v2');
checkdiff = jsondiff.diff(stdout_json, json_golden);
if (not checkdiff):
sys.stdout.write('Query test V2: '+test_name+' with column ranges: '+str(query_param_dict['query_column_ranges'])+' and loaded with '+str(len(col_part))+' partitions passed\n');
else:
sys.stdout.write('Mismatch in query test V2: '+test_name+' with column ranges: '+str(query_param_dict['query_column_ranges'])+' and loaded with '+str(len(col_part))+' partitions\n');
print(checkdiff);
sys.stderr.write('Spark stdout was: '+stdout_string+'\n');
sys.stderr.write('Spark stderr was: '+stderr_string+'\n');
cleanup_and_exit(namenode, tmpdir, -1);
rc = common.report_jacoco_coverage(jacoco_report_cmd)
if (rc != 0):
cleanup_and_exit(namenode, tmpdir, -1)
cleanup_and_exit(namenode, tmpdir, 0)
def test_long_arrays(self):
size = 100
a = [{'a': i, 'b': 2 * i} for i in range(1, size)]
b = [{'a': i, 'b': 3 * i} for i in range(1, size)]
r = sys.getrecursionlimit()
sys.setrecursionlimit(size - 1)
try:
diff(a, b)
except RecursionError:
self.fail('cannot diff long arrays')
finally:
sys.setrecursionlimit(r)
else:
data_b = read_json(args.filename_b)
# Ignore keys that we don't want to diff, in addition to the ones removed that change on every commit
remove_keys(data_a, KEYS_REMOVE.union(KEYS_IGNORE))
remove_keys(data_b, KEYS_REMOVE.union(KEYS_IGNORE))
remove_specifics(data_a)
remove_specifics(data_b)
sort_hostvar_arrays(data_a)
sort_hostvar_arrays(data_b)
# Perform the diff
# syntax='symmetric' will produce output that prints both the before and after as "$insert" and "$delete"
# marshal=True removes any special types, allowing to be dumped as json
result = diff(data_a, data_b, marshal=True, syntax="symmetric")
if result:
# Dictionary is not empty - print differences
print(json.dumps(result, sort_keys=True, indent=4))
sys.exit(1)
else:
# Success, no differences
sys.exit(0)
},
"tool-avrdude": {
"type": "uploader",
"optional": true,
"version": "~1.60300.0"
}
}
}
"""
raw_data = parser.ManifestParserFactory.new(
contents, parser.ManifestFileType.PLATFORM_JSON
).as_dict()
raw_data["frameworks"] = sorted(raw_data["frameworks"])
data = ManifestSchema().load_manifest(raw_data)
assert not jsondiff.diff(
data,
{
"name": "atmelavr",
"title": "Atmel AVR",
"description": (
"Atmel AVR 8- and 32-bit MCUs deliver a unique combination of "
"performance, power efficiency and design flexibility. Optimized to "
"speed time to market-and easily adapt to new ones-they are based "
"on the industrys most code-efficient architecture for C and "
"assembly programming."
),
"homepage": "http://platformio.org/platforms/atmelavr",
"license": "Apache-2.0",
"repository": {
"url": "https://github.com/platformio/platform-atmelavr.git",
"type": "git",
self.assertEqual({}, diff('abc', 'abc'))
self.assertEqual({}, diff([1, 2], [1, 2]))
self.assertEqual({}, diff((1, 2), (1, 2)))
self.assertEqual({}, diff({1, 2}, {1, 2}))
self.assertEqual({}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2}))
self.assertEqual({}, diff([], []))
self.assertEqual({}, diff(None, None))
self.assertEqual({}, diff({}, {}))
self.assertEqual({}, diff(set(), set()))
self.assertEqual(2, diff(1, 2))
self.assertEqual(False, diff(True, False))
self.assertEqual('def', diff('abc', 'def'))
self.assertEqual([3, 4], diff([1, 2], [3, 4]))
self.assertEqual((3, 4), diff((1, 2), (3, 4)))
self.assertEqual({3, 4}, diff({1, 2}, {3, 4}))
self.assertEqual({replace: {'c': 3, 'd': 4}}, diff({'a': 1, 'b': 2}, {'c': 3, 'd': 4}))
self.assertEqual({replace: {'c': 3, 'd': 4}}, diff([1, 2], {'c': 3, 'd': 4}))
self.assertEqual(123, diff({'a': 1, 'b': 2}, 123))
self.assertEqual({delete: ['b']}, diff({'a': 1, 'b': 2}, {'a': 1}))
self.assertEqual({'b': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 3}))
self.assertEqual({'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'b': 2, 'c': 3}))
self.assertEqual({delete: ['b'], 'c': 3}, diff({'a': 1, 'b': 2}, {'a': 1, 'c': 3}))
self.assertEqual({add: {3}}, diff({1, 2}, {1, 2, 3}))
self.assertEqual({add: {3}, discard: {4}}, diff({1, 2, 4}, {1, 2, 3}))
self.assertEqual({discard: {4}}, diff({1, 2, 4}, {1, 2}))
self.assertEqual({insert: [(1, 'b')]}, diff(['a', 'c'], ['a', 'b', 'c']))
self.assertEqual({insert: [(1, 'b')], delete: [3, 0]}, diff(['x', 'a', 'c', 'x'], ['a', 'b', 'c']))
def sync_apis(self, apis):
"""
synchronizes the API definition defined on this machine with Kong.
"""
self.load_apis()
for name in apis:
definition = apis[name]
if name in self.apis:
# api with the same name already exists, check
# for update
current = self.apis[name]
differences = diff(current, definition, syntax='explicit')
has_update = filter(lambda k: k.label == 'update', differences.keys())
if len(has_update) > 0:
log.info('updating API definition %s.', name)
r = requests.patch(
'%s/apis/%s' % (self.admin_url, name),
json=definition, verify=self.verify_ssl)
if r.status_code == 200 or r.status_code == 201:
self.apis[name] = r.json()
else:
log.error('failed to update %s at %s, %s',
name, self.admin_url, r.text)
else:
log.info('API definition %s is up-to-date.', name)
else:
log.info('creating API definition %s.', name)
r = requests.put('%s/apis/' % self.admin_url,
module.fail_json(msg="compose element '%s' must be a " +
"string or a dictionary" % compose_def)
before_stack_services = docker_stack_inspect(module, name)
rc, out, err = docker_stack_deploy(module, name, compose_files)
after_stack_services = docker_stack_inspect(module, name)
if rc != 0:
module.fail_json(msg="docker stack up deploy command failed",
rc=rc,
out=out, err=err, # Deprecated
stdout=out, stderr=err)
before_after_differences = json_diff(before_stack_services,
after_stack_services)
for k in before_after_differences.keys():
if isinstance(before_after_differences[k], dict):
before_after_differences[k].pop('UpdatedAt', None)
before_after_differences[k].pop('Version', None)
if not list(before_after_differences[k].keys()):
before_after_differences.pop(k)
if not before_after_differences:
module.exit_json(
changed=False,
rc=rc,
stdout=out,
stderr=err)
else:
module.exit_json(
def run(self, items: List[dict], **kwargs) -> List[dict]:
"""Run simple difference calculation on results based on a baseline."""
logger.debug("Performing simple local baseline analysis.")
if not kwargs.get("baseline"):
raise BadArguments("Cannot run simple analysis. No baseline found.")
for i in items:
i["diff"] = diff(kwargs["baseline"]["stdout"], i["stdout"])
return items