Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_error_noisy_nonexit(self, capsys):
args = SimpleNamespace(verbose=False, quiet=False, debug=False)
logger = ConsolePrinter(args)
logger.error("Test")
console = capsys.readouterr()
assert console.err == "ERROR: Test\n"
def test_critical_quiet(self, capsys):
args = SimpleNamespace(verbose=False, quiet=True, debug=False)
logger = ConsolePrinter(args)
with pytest.raises(SystemExit):
logger.critical("Test")
console = capsys.readouterr()
assert console.err == "CRITICAL: Test\n"
def test_info_quiet(self, capsys):
args = SimpleNamespace(verbose=False, quiet=True, debug=False)
logger = ConsolePrinter(args)
logger.info("Test")
console = capsys.readouterr()
assert not console.out
def test_debug_noisy(self, capsys):
args = SimpleNamespace(verbose=False, quiet=False, debug=True)
logger = ConsolePrinter(args)
anchoredkey = PlainScalarString("TestKey", anchor="KeyAnchor")
anchoredval = PlainScalarString("TestVal", anchor="Anchor")
logger.debug(anchoredval)
console = capsys.readouterr()
assert "\n".join([
"DEBUG: TestVal; &Anchor",
]) + "\n" == console.out
logger.debug(["test", anchoredval])
console = capsys.readouterr()
assert "\n".join([
"DEBUG: [0]=test ",
"DEBUG: [1]=TestVal; &Anchor ",
]) + "\n" == console.out
def test_debug_quiet(self, capsys):
args = SimpleNamespace(verbose=False, quiet=True, debug=True)
logger = ConsolePrinter(args)
logger.debug("Test")
console = capsys.readouterr()
assert not console.out
def quiet_logger():
args = SimpleNamespace(verbose=False, quiet=True, debug=False)
return ConsolePrinter(args)
def main():
"""Main code."""
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
yaml_path = YAMLPath(args.query, pathsep=args.pathsep)
# Prep the YAML parser
yaml = get_yaml_editor()
# Attempt to open the YAML file; check for parsing errors
yaml_data = get_yaml_data(yaml, log, args.yaml_file)
if yaml_data is None:
# An error message has already been logged
sys.exit(1)
# Seek the queried value(s)
discovered_nodes = []
processor = EYAMLProcessor(
log, yaml_data, binary=args.eyaml,
def main():
"""Main code."""
# Process any command-line arguments
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
processor = EYAMLProcessor(log, None, binary=args.eyaml)
# Prep the YAML parser
yaml = get_yaml_editor()
# Process the input file(s)
in_file_count = len(args.yaml_files)
exit_state = 0
for yaml_file in args.yaml_files:
file_changed = False
backup_file = yaml_file + ".bak"
seen_anchors = []
# Each YAML_FILE must actually be a file
if not isfile(yaml_file):
def main():
"""Main code."""
# Process any command-line arguments
args = processcli()
log = ConsolePrinter(args)
validateargs(args, log)
search_values = True
search_keys = False
include_key_aliases = False
include_value_aliases = False
if args.onlykeynames:
search_values = False
search_keys = True
elif args.keynames:
search_keys = True
if args.include_aliases is IncludeAliases.INCLUDE_ALL_ALIASES:
include_key_aliases = True
include_value_aliases = True
elif args.include_aliases is IncludeAliases.INCLUDE_KEY_ALIASES: