Exemplo n.º 1
0
 def test_2(self):
     '''Test that is_mapping is false if we check from the second token in this "key": "value"} '''
     self.assertFalse(
         is_mapping(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
         ],
                    start=1))
Exemplo n.º 2
0
 def test_1(self):
     '''Test that is_mapping is true if we check from the first token in this {"key": "value"} '''
     self.assertTrue(
         is_mapping(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
         ],
                    start=0))
Exemplo n.º 3
0
 def test_3(self):
     '''test that sequence_node_from_tokens works with more than one item'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='value'),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(
             items=[ScalarNode(data='value'),
                    ScalarNode(data='value')]), 5))
Exemplo n.º 4
0
 def test_1(self):
     '''test that mapping_node_from_tokens works for the simplest case'''
     self.assertEqual(
         mapping_node_from_tokens(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
         ],
                                  start=0),
         (MappingNode(
             mapping={ScalarNode(data='key'): ScalarNode(data='value')}),
          5))
Exemplo n.º 5
0
 def test_2(self):
     '''Test that mapping get converted to expected token'''
     self.assertEqual(
         tokenize(string='{"key": "value", "key2":"value"}'),
         [
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='key2'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd()
         ]
     )
Exemplo n.º 6
0
 def test_3(self):
     '''Test that a sequence is converted to the expected token'''
     self.assertEqual(
         tokenize(string='["key", "value", "key2","value"]'),
         [
             SequenceStart(),
             ScalarValue(data='key'),
             Delimiter(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='key2'),
             Delimiter(),
             ScalarValue(data='value'),
             SequenceEnd()
         ]
     )
Exemplo n.º 7
0
 def test_5(self):
     '''test that sequence_node_from_tokens works with it contains a mapping'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(items=[
             MappingNode(
                 mapping={ScalarNode(data='key'): ScalarNode(data='value')})
         ]), 7))
Exemplo n.º 8
0
 def test_is_sequence(self):
     self.assertTrue(
         is_sequence(tokens=[
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
         ],
                     start=0))
Exemplo n.º 9
0
 def test_4(self):
     '''test that mapping_node_from_tokens works when the value is a sequence'''
     self.assertEqual(
         mapping_node_from_tokens(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
             MappingEnd(),
         ],
                                  start=0),
         (MappingNode(
             mapping={
                 ScalarNode(data='key'):
                 SequenceNode(items=[ScalarNode(data='value')]),
             }), 7))
Exemplo n.º 10
0
 def test_1(self):
     '''test that sequence_node_from_tokens works for the simplest case'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(items=[ScalarNode(data='value')]), 3))
Exemplo n.º 11
0
 def test_2(self):
     '''test that mapping_node_from_tokens works when there are two items'''
     self.assertEqual(
         mapping_node_from_tokens(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='key1'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
         ],
                                  start=0),
         (MappingNode(
             mapping={
                 ScalarNode(data='key'): ScalarNode(data='value'),
                 ScalarNode(data='key1'): ScalarNode(data='value'),
             }), 9))
Exemplo n.º 12
0
 def test_4(self):
     '''Test that a string is converted to its expected tokens when it spans more than one line'''
     self.assertEqual(
         tokenize(string='''[
             "key",
             "value",
             "key2",
             "value"
             ]'''
         ),
         [
             SequenceStart(),
             ScalarValue(data='key'),
             Delimiter(),
             ScalarValue(data='value'),
             Delimiter(),
             ScalarValue(data='key2'),
             Delimiter(),
             ScalarValue(data='value'),
             SequenceEnd()
         ]
     )
Exemplo n.º 13
0
 def test_4(self):
     '''test that sequence_node_from_tokens works with there is a nested sequence'''
     self.assertEqual(
         sequence_node_from_tokens(tokens=[
             SequenceStart(),
             SequenceStart(),
             ScalarValue(data='value'),
             SequenceEnd(),
             SequenceEnd(),
         ],
                                   start=0),
         (SequenceNode(
             items=[SequenceNode(items=[ScalarNode(data='value')])]), 5))
Exemplo n.º 14
0
 def test_3(self):
     '''test that mapping_node_from_tokens works when there is a nested mapping'''
     self.assertEqual(
         mapping_node_from_tokens(tokens=[
             MappingStart(),
             ScalarValue(data='key'),
             Separator(),
             MappingStart(),
             ScalarValue(data='key1'),
             Separator(),
             ScalarValue(data='value'),
             MappingEnd(),
             MappingEnd(),
         ],
                                  start=0),
         (MappingNode(
             mapping={
                 ScalarNode(data='key'):
                 MappingNode(
                     mapping={
                         ScalarNode(data='key1'): ScalarNode(data='value')
                     }),
             }), 9))
Exemplo n.º 15
0
 def test_1(self):
     '''Test that string get converted to expected token'''
     self.assertEqual(
         tokenize(string='"string"'),
         [ScalarValue(data='string')]
     )
Exemplo n.º 16
0
 def test_is_scalar(self):
     self.assertTrue(is_scalar(tokens=[ScalarValue(data='value')], start=0))
Exemplo n.º 17
0
 def test_scalar_node_from_tokens(self):
     self.assertEqual(
         scalar_node_from_tokens(tokens=[ScalarValue(data='value')],
                                 start=0),
         (ScalarNode(data='value'), 1),
     )