Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with pytest.raises(Ref.InvalidRefError):
ref(input)
ref('a').components() == [Ref.Dereference('a')]
ref('.a').components() == [Ref.Dereference('a')]
ref('a.b').components() == [Ref.Dereference('a'), Ref.Dereference('b')]
ref('[a]').components() == [Ref.Index('a')]
ref('[a-]').components() == [Ref.Index('a-')]
ref('[0].a').components() == [Ref.Index('0'), Ref.Dereference('a')]
ref('[0][a]').components() == [Ref.Index('0'), Ref.Index('a')]
ref('[.]').components() == [Ref.Index('.')]
ref('[/]').components() == [Ref.Index('/')]
ref('[_]').components() == [Ref.Index('_')]
ref('[-]').components() == [Ref.Index('-')]
ref('[a.b]').components() == [Ref.Index('a.b')]
ref('[a/b]').components() == [Ref.Index('a/b')]
ref('[a_b]').components() == [Ref.Index('a_b')]
ref('[a-b]').components() == [Ref.Index('a-b')]
ref('[a/b/c/d]').components() == [Ref.Index('a/b/c/d')]
ref('[2.0.a_c/d-e]').components() == [Ref.Index('2.0.a_c/d-e')]
for refstr in ('[a]b', '[]', '[[a]', 'b[[[', 'a.1', '1.a', '.[a]', '0'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for refstr in ('a-b', '-b', 'a-'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for input in ['', None, type, 1, 3.0, 'hork bork']:
with pytest.raises(Ref.InvalidRefError):
ref(input)
ref('a').components() == [Ref.Dereference('a')]
ref('.a').components() == [Ref.Dereference('a')]
ref('a.b').components() == [Ref.Dereference('a'), Ref.Dereference('b')]
ref('[a]').components() == [Ref.Index('a')]
ref('[a-]').components() == [Ref.Index('a-')]
ref('[0].a').components() == [Ref.Index('0'), Ref.Dereference('a')]
ref('[0][a]').components() == [Ref.Index('0'), Ref.Index('a')]
ref('[.]').components() == [Ref.Index('.')]
ref('[/]').components() == [Ref.Index('/')]
ref('[_]').components() == [Ref.Index('_')]
ref('[-]').components() == [Ref.Index('-')]
ref('[a.b]').components() == [Ref.Index('a.b')]
ref('[a/b]').components() == [Ref.Index('a/b')]
ref('[a_b]').components() == [Ref.Index('a_b')]
ref('[a-b]').components() == [Ref.Index('a-b')]
ref('[a/b/c/d]').components() == [Ref.Index('a/b/c/d')]
ref('[2.0.a_c/d-e]').components() == [Ref.Index('2.0.a_c/d-e')]
for refstr in ('[a]b', '[]', '[[a]', 'b[[[', 'a.1', '1.a', '.[a]', '0'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for refstr in ('a-b', '-b', 'a-'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
ref('.a').components() == [Ref.Dereference('a')]
ref('a.b').components() == [Ref.Dereference('a'), Ref.Dereference('b')]
ref('[a]').components() == [Ref.Index('a')]
ref('[a-]').components() == [Ref.Index('a-')]
ref('[0].a').components() == [Ref.Index('0'), Ref.Dereference('a')]
ref('[0][a]').components() == [Ref.Index('0'), Ref.Index('a')]
ref('[.]').components() == [Ref.Index('.')]
ref('[/]').components() == [Ref.Index('/')]
ref('[_]').components() == [Ref.Index('_')]
ref('[-]').components() == [Ref.Index('-')]
ref('[a.b]').components() == [Ref.Index('a.b')]
ref('[a/b]').components() == [Ref.Index('a/b')]
ref('[a_b]').components() == [Ref.Index('a_b')]
ref('[a-b]').components() == [Ref.Index('a-b')]
ref('[a/b/c/d]').components() == [Ref.Index('a/b/c/d')]
ref('[2.0.a_c/d-e]').components() == [Ref.Index('2.0.a_c/d-e')]
for refstr in ('[a]b', '[]', '[[a]', 'b[[[', 'a.1', '1.a', '.[a]', '0'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for refstr in ('a-b', '-b', 'a-'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
def test_ref_parsing():
for input in ['', None, type, 1, 3.0, 'hork bork']:
with pytest.raises(Ref.InvalidRefError):
ref(input)
ref('a').components() == [Ref.Dereference('a')]
ref('.a').components() == [Ref.Dereference('a')]
ref('a.b').components() == [Ref.Dereference('a'), Ref.Dereference('b')]
ref('[a]').components() == [Ref.Index('a')]
ref('[a-]').components() == [Ref.Index('a-')]
ref('[0].a').components() == [Ref.Index('0'), Ref.Dereference('a')]
ref('[0][a]').components() == [Ref.Index('0'), Ref.Index('a')]
ref('[.]').components() == [Ref.Index('.')]
ref('[/]').components() == [Ref.Index('/')]
ref('[_]').components() == [Ref.Index('_')]
ref('[-]').components() == [Ref.Index('-')]
ref('[a.b]').components() == [Ref.Index('a.b')]
ref('[a/b]').components() == [Ref.Index('a/b')]
ref('[a_b]').components() == [Ref.Index('a_b')]
ref('[a-b]').components() == [Ref.Index('a-b')]
ref('[a/b/c/d]').components() == [Ref.Index('a/b/c/d')]
ref('[2.0.a_c/d-e]').components() == [Ref.Index('2.0.a_c/d-e')]
for refstr in ('[a]b', '[]', '[[a]', 'b[[[', 'a.1', '1.a', '.[a]', '0'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for refstr in ('a-b', '-b', 'a-'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
def test_ref_parsing():
for input in ['', None, type, 1, 3.0, 'hork bork']:
with pytest.raises(Ref.InvalidRefError):
ref(input)
ref('a').components() == [Ref.Dereference('a')]
ref('.a').components() == [Ref.Dereference('a')]
ref('a.b').components() == [Ref.Dereference('a'), Ref.Dereference('b')]
ref('[a]').components() == [Ref.Index('a')]
ref('[a-]').components() == [Ref.Index('a-')]
ref('[0].a').components() == [Ref.Index('0'), Ref.Dereference('a')]
ref('[0][a]').components() == [Ref.Index('0'), Ref.Index('a')]
ref('[.]').components() == [Ref.Index('.')]
ref('[/]').components() == [Ref.Index('/')]
ref('[_]').components() == [Ref.Index('_')]
ref('[-]').components() == [Ref.Index('-')]
ref('[a.b]').components() == [Ref.Index('a.b')]
ref('[a/b]').components() == [Ref.Index('a/b')]
ref('[a_b]').components() == [Ref.Index('a_b')]
ref('[a-b]').components() == [Ref.Index('a-b')]
ref('[a/b/c/d]').components() == [Ref.Index('a/b/c/d')]
ref('[2.0.a_c/d-e]').components() == [Ref.Index('2.0.a_c/d-e')]
for refstr in ('[a]b', '[]', '[[a]', 'b[[[', 'a.1', '1.a', '.[a]', '0'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
for refstr in ('a-b', '-b', 'a-'):
with pytest.raises(Ref.InvalidRefError):
ref(refstr)
def map_to_namable(component):
if (component.startswith('[') and component.endswith(']') and
Ref.Index.RE.match(component[1:-1])):
return Ref.Index(component[1:-1])
elif component.startswith('.') and Ref.Dereference.RE.match(component[1:]):
return Ref.Dereference(component[1:])
else:
raise Ref.InvalidRefError('Address %s has bad component %s' % (address, component))
splits = Ref._REF_RE.split(address)
def map_to_namable(component):
if (component.startswith('[') and component.endswith(']') and
Ref.Index.RE.match(component[1:-1])):
return Ref.Index(component[1:-1])
elif component.startswith('.') and Ref.Dereference.RE.match(component[1:]):
return Ref.Dereference(component[1:])
else:
raise Ref.InvalidRefError('Address %s has bad component %s' % (address, component))
splits = Ref._REF_RE.split(address)
def is_index(self):
return isinstance(self.action(), Ref.Index)
def __getitem__(self, pattern):
if pattern is Any:
return self.__extend(Ref.Index(self.escape('.*')))
else:
return self.__extend(Ref.Index(self.escape(pattern)))