def test_order_json_sorts_list(): l = list(range(10)) random.shuffle(l) data = {'a': l} gold_data = {'a': list(range(10))} res = order_json(data) assert res == gold_data
def hash_outputs(outputs: Dict[str, Union[str, List[str]]]) -> str: """Hash the outputs of a task. :param outputs: The list of output files to hash. :returns: The hash of the outputs. """ LOGGER.debug("Hashing %s", outputs) output_hashes = {k: hash_files(listify(v)) for k, v in outputs.items()} LOGGER.debug(output_hashes) out_hash = sha1(json.dumps( order_json(output_hashes)).encode('utf-8')).hexdigest() LOGGER.debug("Output hash: %s", out_hash) return out_hash
def test_sorts_subdict(): gold = [random.random() in range(random.randint(5, 10))] gold_dict = { random.randint(0, 100): random.random() for _ in range(random.randint(10, 20)) } index = random.randint(0, len(gold) - 1) gold[index] = gold_dict mixed = deepcopy(gold) mixed[index] = shuffle_dict(mixed[index]) data = {'a': mixed} res = order_json(data) assert res['a'] == gold
def test_order_json_doesnt_sorts_list(): gold = list(range(10)) random.shuffle(gold) data = {'a': gold} res = order_json(data) assert res['a'] == gold
def test_order_json_e2e(data, mixed): res = order_json(mixed) assert res == data