def test_warn_when_rules_matches_zero_nodes(self, capsys, info_warn_logger, tmp_path_factory): config_file = create_temp_yaml_file( tmp_path_factory, """ [rules] /does_not_exist = left /array_of_hashes[name = "Does Not Compute"] = right """) lhs_yaml_file = create_temp_yaml_file( tmp_path_factory, """--- hash: lhs_exclusive: lhs value 1 diff_targets: subkey: lhs value 2 subarray: - one - two array_of_hashes: - name: LHS Record 1 id: 1 prop: LHS value AoH 1 - name: LHS Record 2 id: 2 prop: LHS value AoH 2 """) lhs_yaml = get_yaml_editor() lhs_data = get_yaml_data(lhs_yaml, info_warn_logger, lhs_yaml_file) mc = DifferConfig(info_warn_logger, SimpleNamespace(config=config_file)) mc.prepare(lhs_data) console = capsys.readouterr() assert "YAML Path matches no nodes" in console.out
def test_aoh_diff_key_default(self, quiet_logger, tmp_path_factory): lhs_yaml_file = create_temp_yaml_file( tmp_path_factory, """--- hash: lhs_exclusive: lhs value 1 diff_targets: subkey: lhs value 2 subarray: - one - two array_of_hashes: - name: LHS Record 1 id: 1 prop: LHS value AoH 1 - name: LHS Record 2 id: 2 prop: LHS value AoH 2 """) lhs_yaml = get_yaml_editor() (lhs_data, lhs_loaded) = get_yaml_data(lhs_yaml, quiet_logger, lhs_yaml_file) mc = DifferConfig(quiet_logger, SimpleNamespace()) mc.prepare(lhs_data) parent = lhs_data["array_of_hashes"] parentref = 0 node = parent[parentref] nc = NodeCoords(node, parent, parentref) (key_attr, is_user_defined) = mc.aoh_diff_key(nc) assert key_attr == "name" and is_user_defined == False
def test_array_diff_mode_cli_overrides_ini_defaults( self, quiet_logger, tmp_path_factory, cli, ini, mode): config_file = create_temp_yaml_file( tmp_path_factory, """ [defaults] arrays = {} """.format(ini)) mc = DifferConfig(quiet_logger, SimpleNamespace(config=config_file, arrays=cli)) assert mc.array_diff_mode(NodeCoords(None, None, None)) == mode
def test_array_diff_mode_ini(self, quiet_logger, tmp_path_factory, setting, mode): config_file = create_temp_yaml_file( tmp_path_factory, """ [defaults] arrays = {} """.format(setting)) mc = DifferConfig(quiet_logger, SimpleNamespace(config=config_file, arrays=None)) assert mc.array_diff_mode(NodeCoords(None, None, None)) == mode
def test_array_diff_mode_ini_rule_overrides_cli(self, quiet_logger, tmp_path_factory, cli, ini_default, ini_rule, mode): config_file = create_temp_yaml_file( tmp_path_factory, """ [defaults] arrays = {} [rules] /hash/diff_targets/subarray = {} """.format(ini_default, ini_rule)) lhs_yaml_file = create_temp_yaml_file( tmp_path_factory, """--- hash: lhs_exclusive: lhs value 1 diff_targets: subkey: lhs value 2 subarray: - one - two array_of_hashes: - name: LHS Record 1 id: 1 prop: LHS value AoH 1 - name: LHS Record 2 id: 2 prop: LHS value AoH 2 """) lhs_yaml = get_yaml_editor() (lhs_data, lhs_loaded) = get_yaml_data(lhs_yaml, quiet_logger, lhs_yaml_file) mc = DifferConfig(quiet_logger, SimpleNamespace(config=config_file, arrays=cli)) mc.prepare(lhs_data) node = lhs_data["hash"]["diff_targets"]["subarray"] parent = lhs_data["hash"]["diff_targets"] parentref = "subarray" assert mc.array_diff_mode(NodeCoords(node, parent, parentref)) == mode
def main(): """Main code.""" args = processcli() log = ConsolePrinter(args) validateargs(args, log) exit_state = 0 lhs_file = args.yaml_files[0] rhs_file = args.yaml_files[1] lhs_yaml = Parsers.get_yaml_editor() rhs_yaml = Parsers.get_yaml_editor() (lhs_docs, lhs_loaded) = get_docs(log, lhs_yaml, lhs_file) (rhs_docs, rhs_loaded) = get_docs(log, rhs_yaml, rhs_file) lhs_doc_count = len(lhs_docs) if lhs_loaded else 0 rhs_doc_count = len(rhs_docs) if rhs_loaded else 0 lhs_idx_set = (hasattr(args, "left_document_index") and args.left_document_index is not None) rhs_idx_set = (hasattr(args, "right_document_index") and args.right_document_index is not None) if not (lhs_loaded and rhs_loaded): # An error message has already been logged sys.exit(1) if lhs_doc_count > 1 and not lhs_idx_set: log.critical( ("--left-document-index|-L must be set; the source contains {}" " documents.").format(lhs_doc_count), 1) lhs_index = args.left_document_index if lhs_idx_set else 0 lhs_document = get_doc(log, lhs_docs, lhs_index) if rhs_doc_count > 1 and not rhs_idx_set: log.critical( ("--right-document-index|-R must be set; the source contains {}" " documents.").format(rhs_doc_count), 1) rhs_index = args.right_document_index if rhs_idx_set else 0 rhs_document = get_doc(log, rhs_docs, rhs_index) diff = Differ(DifferConfig(log, args), log, lhs_document, ignore_eyaml_values=args.ignore_eyaml_values, binary=args.eyaml, publickey=args.publickey, privatekey=args.privatekey) try: diff.compare_to(rhs_document) except EYAMLCommandException as ex: log.critical(ex, 1) exit_state = 1 if print_report(log, args, diff) else 0 sys.exit(exit_state)
def main(): """Main code.""" args = processcli() log = ConsolePrinter(args) validateargs(args, log) exit_state = 0 lhs_file = args.yaml_files[0] rhs_file = args.yaml_files[1] lhs_yaml = Parsers.get_yaml_editor() rhs_yaml = Parsers.get_yaml_editor() (lhs_document, doc_loaded) = Parsers.get_yaml_data(lhs_yaml, log, lhs_file) if not doc_loaded: # An error message has already been logged sys.exit(1) (rhs_document, doc_loaded) = Parsers.get_yaml_data(rhs_yaml, log, rhs_file) if not doc_loaded: # An error message has already been logged sys.exit(1) diff = Differ(DifferConfig(log, args), log, lhs_document, ignore_eyaml_values=args.ignore_eyaml_values, binary=args.eyaml, publickey=args.publickey, privatekey=args.privatekey) try: diff.compare_to(rhs_document) except EYAMLCommandException as ex: log.critical(ex, 1) exit_state = 1 if print_report(log, args, diff) else 0 sys.exit(exit_state)
def test_array_diff_mode_cli(self, quiet_logger, setting, mode): mc = DifferConfig(quiet_logger, SimpleNamespace(arrays=setting)) assert mc.array_diff_mode(NodeCoords(None, None, None)) == mode
def test_array_diff_mode_default(self, quiet_logger): mc = DifferConfig(quiet_logger, SimpleNamespace(arrays=None)) assert mc.array_diff_mode(NodeCoords(None, None, None)) == ArrayDiffOpts.POSITION