How to use the pystachio.naming.Ref.Index function in pystachio

To help you get started, we’ve selected a few pystachio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wickman / pystachio / tests / test_naming.py View on Github external
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)
github wickman / pystachio / tests / test_naming.py View on Github external
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)
github wickman / pystachio / tests / test_naming.py View on Github external
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)
github wickman / pystachio / tests / test_naming.py View on Github external
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)
github wickman / pystachio / tests / test_naming.py View on Github external
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)
github wickman / pystachio / pystachio / naming.py View on Github external
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)
github wickman / pystachio / pystachio / naming.py View on Github external
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)
github wickman / pystachio / pystachio / naming.py View on Github external
def is_index(self):
    return isinstance(self.action(), Ref.Index)
github wickman / pystachio / pystachio / matcher.py View on Github external
def __getitem__(self, pattern):
    if pattern is Any:
      return self.__extend(Ref.Index(self.escape('.*')))
    else:
      return self.__extend(Ref.Index(self.escape(pattern)))