コード例 #1
0
def test_entry_extraction():
    text = open('sample.toml').read()
    elements = parser.parse_tokens(lexer.tokenize(text))

    e = tuple(toplevels.identify(elements))

    assert len(e) == 13
    assert isinstance(e[0], toplevels.AnonymousTable)
コード例 #2
0
def test_structure():
    tokens = lexer.tokenize(open('sample.toml').read())
    elements = elementsanitizer.sanitize(parser.parse_tokens(tokens))
    entries_ = tuple(toplevels.identify(elements))

    s = structure(entries_)

    assert s['']['title'] == 'TOML Example'
    assert s['owner']['name'] == 'Tom Preston-Werner'
    assert s['database']['ports'][1] == 8001
    assert s['servers']['alpha']['dc'] == 'eqdc10'
    assert s['clients']['data'][1][0] == 1
    assert s['clients']['key3'] == 'The quick brown fox jumps over the lazy dog.'

    assert s['fruit'][0]['name'] == 'apple'
    assert s['fruit'][0]['physical']['color'] == 'red'
    assert s['fruit'][0]['physical']['shape'] == 'round'
    assert s['fruit'][0]['variety'][0]['name'] == 'red delicious'
    assert s['fruit'][0]['variety'][1]['name'] == 'granny smith'

    assert s['fruit'][1]['name'] == 'banana'
    assert s['fruit'][1]['variety'][0]['name'] == 'plantain'
    assert s['fruit'][1]['variety'][0]['points'][2]['y'] == 4
コード例 #3
0
ファイル: file.py プロジェクト: jtorresyap/learning-flask
 def _recreate_navigable(self):
     if self._elements:
         self._navigable = structurer.structure(
             toplevels.identify(self._elements))
コード例 #4
0
ファイル: file.py プロジェクト: jtorresyap/learning-flask
 def _detect_toplevels(self):
     """
     Returns a sequence of TopLevel instances for the current state of this table.
     """
     return tuple(e for e in toplevels.identify(self.elements)
                  if isinstance(e, toplevels.Table))
コード例 #5
0
 def _recreate_navigable(self):
     if self._elements:
         self._navigable = structurer.structure(toplevels.identify(self._elements))
コード例 #6
0
 def _detect_toplevels(self):
     """
     Returns a sequence of TopLevel instances for the current state of this table.
     """
     return tuple(e for e in toplevels.identify(self.elements) if isinstance(e, toplevels.Table))