예제 #1
0
 def test_double_quoted_strings(self):
     out = self._parse('foo="bar"')
     expect = ast.Query(
         ast.Comparison('=', ast.IdentifierPath([
             ast.Identifier('foo'),
         ]), ast.Literal('bar')))
     self.assertEqual(repr(out), repr(expect))
예제 #2
0
 def test_negate_expression(self):
     out = self._parse('not foo=bar')
     expect = ast.Query(
         ast.NotExpression(
             ast.Comparison('=',
                            ast.IdentifierPath([ast.Identifier('foo')]),
                            ast.Literal('bar'))))
     self.assertEqual(repr(out), repr(expect))
예제 #3
0
 def test_resource_queries_with_type_title_and_parameters(self):
     out = self._parse('file[foo]{bar=baz}')
     expect = ast.Query(
         ast.Resource(
             'file', ast.Identifier('foo'), False,
             ast.BlockExpression(
                 ast.Comparison('=',
                                ast.IdentifierPath([ast.Identifier('bar')]),
                                ast.Literal('baz')))))
     self.assertEqual(repr(out), repr(expect))
예제 #4
0
 def test_dates_in_queries(self):
     out = self._parse('#node.report_timestamp<@"Sep 9, 2014"')
     expect = ast.Query(
         ast.Subquery(
             'node',
             ast.Comparison(
                 '<',
                 ast.IdentifierPath([ast.Identifier('report_timestamp')]),
                 ast.Date('Sep 9, 2014'))))
     self.assertEqual(repr(out), repr(expect))
예제 #5
0
 def test_node_subqueries(self):
     out = self._parse('#node.catalog_environment=production')
     expect = ast.Query(
         ast.Subquery(
             'node',
             ast.Comparison(
                 '=',
                 ast.IdentifierPath([ast.Identifier('catalog_environment')
                                     ]), ast.Literal('production'))))
     self.assertEqual(repr(out), repr(expect))
예제 #6
0
 def test_single_string_expressions(self):
     out = self._parse('foo.bar.com')
     expect = ast.Query(
         ast.RegexpNodeMatch(
             ast.IdentifierPath([
                 ast.Identifier('foo'),
                 ast.Identifier('bar'),
                 ast.Identifier('com')
             ])))
     self.assertEqual(repr(out), repr(expect))
예제 #7
0
 def test_structured_facts_with_wildcard_operator(self):
     out = self._parse('foo.bar.*=baz')
     expect = ast.Query(
         ast.Comparison(
             '=',
             ast.IdentifierPath([
                 ast.Identifier('foo'),
                 ast.Identifier('bar'),
                 ast.RegexpIdentifier('.*')
             ]), ast.Literal('baz')))
     self.assertEqual(repr(out), repr(expect))
예제 #8
0
 def test_node_subqueries_with_block_of_conditions(self):
     out = self._parse('#node { catalog_environment=production }')
     expect = ast.Query(
         ast.Subquery(
             'node',
             ast.BlockExpression(
                 ast.Comparison(
                     '=',
                     ast.IdentifierPath(
                         [ast.Identifier('catalog_environment')]),
                     ast.Literal('production')))))
     self.assertEqual(repr(out), repr(expect))
예제 #9
0
 def test_logical_operators(self):
     out = self._parse('foo=1 or (bar=2 and baz=3)')
     expect = ast.Query(
         ast.OrExpression(
             ast.Comparison('=',
                            ast.IdentifierPath([ast.Identifier('foo')]),
                            ast.Literal(1)),
             ast.ParenthesizedExpression(
                 ast.AndExpression(
                     ast.Comparison(
                         '=', ast.IdentifierPath([ast.Identifier('bar')]),
                         ast.Literal(2)),
                     ast.Comparison(
                         '=', ast.IdentifierPath([ast.Identifier('baz')]),
                         ast.Literal(3))))))
     self.assertEqual(repr(out), repr(expect))
예제 #10
0
 def test_resource_queries_with_type_and_regexp_identifier(self):
     out = self._parse('class[~foo]')
     expect = ast.Query(
         ast.Resource('class', ast.RegexpIdentifier('foo'), False, None))
     self.assertEqual(repr(out), repr(expect))
예제 #11
0
 def test_resource_queries_for_exported_resources(self):
     out = self._parse('@@file[foo]')
     expect = ast.Query(
         ast.Resource('file', ast.Identifier('foo'), True, None))
     self.assertEqual(repr(out), repr(expect))
예제 #12
0
 def test_float_values(self):
     out = self._parse('foo=1.024')
     expect = ast.Query(
         ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]),
                        ast.Literal(1.024)))
     self.assertEqual(repr(out), repr(expect))
예제 #13
0
 def test_boolean_values(self):
     out = self._parse('foo=true')
     expect = ast.Query(
         ast.Comparison('=', ast.IdentifierPath([ast.Identifier('foo')]),
                        ast.Literal(True)))
     self.assertEqual(repr(out), repr(expect))