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_parse_double_inversion_error(self):
with pytest.raises(YAMLPathException) as ex:
str(Path("abc[!def!=ghi]"))
assert -1 < str(ex.value).find("Double search inversion is meaningless")
def test_parse_missing_operand_errors(self, input):
with pytest.raises(YAMLPathException) as ex:
str(Path(input))
assert -1 < str(ex.value).find("Missing search operand")
def test_parse_unmatched_regex_error(self):
with pytest.raises(YAMLPathException) as ex:
str(Path("abc[def=~/ghi]"))
assert -1 < str(ex.value).find("contains an unterminated Regular Expression")
def test_seperator_change(self):
# IMPORTANT: The YAML Path is only lazily parsed! This means parsing
# ONLY happens when the path is in some way used. Casting it to string
# qualifies as one form of use, so this test will instigate parsing via
# stringification. THIS MATTERS WHEN YOUR INTENTION IS TO **CHANGE**
# THE PATH SEPERATOR! So, if an original path uses dot-notation and
# you wish to change it to forward-slash-notation, you must first cause
# the original to become parsed, AND THEN change the seperator.
testpath = Path("abc.def")
dotted = str(testpath)
testpath.seperator = PathSeperators.FSLASH
assert "/abc/def" == str(testpath) != dotted
def test_parse_unmatched_collector_error(self):
with pytest.raises(YAMLPathException) as ex:
str(Path("(abc"))
assert -1 < str(ex.value).find("contains an unmatched () collector")
def test_repr(self):
assert repr(Path("abc.123")) == "Path('abc.123', '.')"
def test_parse_unmatched_demarcation_error(self):
with pytest.raises(YAMLPathException) as ex:
str(Path("abc.'def"))
assert -1 < str(ex.value).find("contains at least one unmatched demarcation mark")
def test_escaped(self):
testpath = Path(r"abc.def\.ghi")
assert list(testpath.escaped) == [
(PathSegmentTypes.KEY, "abc"),
(PathSegmentTypes.KEY, "def.ghi"),
]
def test_str(self, yamlpath, pathsep, output):
# Test twice to include cache hits
testpath = Path(yamlpath, pathsep)
assert output == str(testpath) == str(testpath)
def test_parse_bad_tilde_error(self):
with pytest.raises(YAMLPathException) as ex:
str(Path("abc[def~ghi]"))
assert -1 < str(ex.value).find("Unexpected use of ~ operator")