Exemplo n.º 1
0
def test_parse_set_query():
    """
    Parse a bunch of set queries and make sure that the expected result
    matches.
    """
    # Dict of tuples of (query: expected_result)
    set_tests = {
        'foo=bar': [
            ('intersection', 'foo', 'bar'),
        ],
        'foo=bar owner=jathan': [
            ('intersection', 'foo', 'bar'),
            ('intersection', 'owner', 'jathan'),
        ],
        '-owner=gary': [
            ('difference', 'owner', 'gary'),
        ],
        'cluster +foo=baz': [
            ('intersection', 'cluster', ''),
            ('union', 'foo', 'baz'),
        ],
        # Extra white space
        'cluster=lax   +foo=baz': [
            ('intersection', 'cluster', 'lax'),
            ('union', 'foo', 'baz'),
        ],
        # Single-quoted value w/ a space in it
        "usage='Internal Network'": [
            ('intersection', 'usage', 'Internal Network'),
        ],
        # Double-quoted value w/ a space in it
        'usage="Internal Network"': [
            ('intersection', 'usage', 'Internal Network'),
        ],
    }

    # Make sure that result matches expected_result
    for query, expected_result in set_tests.iteritems():
        result = parse_set_query(query)
        assert result == expected_result

    # Test bogus stuff
    with pytest.raises(TypeError):
        parse_set_query(None)

    # Test a bad string
    with pytest.raises(ValueError):
        parse_set_query('foo="bar')  # Unbalanced quotes
Exemplo n.º 2
0
def test_parse_set_query():
    """
    Parse a bunch of set queries and make sure that the expected result
    matches.
    """
    # Dict of tuples of (query: expected_result)
    set_tests = {
        'foo=bar': [
            ('intersection', 'foo', 'bar'),
        ],
        'foo=bar owner=jathan': [
            ('intersection', 'foo', 'bar'),
            ('intersection', 'owner', 'jathan'),
        ],
        '-owner=gary': [
            ('difference', 'owner', 'gary'),
        ],
        'cluster +foo=baz': [
            ('intersection', 'cluster', ''),
            ('union', 'foo', 'baz'),
        ],
        # Extra white space
        'cluster=lax   +foo=baz': [
            ('intersection', 'cluster', 'lax'),
            ('union', 'foo', 'baz'),
        ],
        # Single-quoted value w/ a space in it
        "usage='Internal Network'": [
            ('intersection', 'usage', 'Internal Network'),
        ],
        # Double-quoted value w/ a space in it
        'usage="Internal Network"': [
            ('intersection', 'usage', 'Internal Network'),
        ],
    }

    # Make sure that result matches expected_result
    for query, expected_result in set_tests.iteritems():
        result = parse_set_query(query)
        assert result == expected_result

    # Test bogus stuff
    with pytest.raises(TypeError):
        parse_set_query(None)

    # Test a bad string
    with pytest.raises(ValueError):
        parse_set_query('foo="bar')  # Unbalanced quotes
Exemplo n.º 3
0
def test_parse_set_query():
    """
    Parse a bunch of set queries and make sure that the expected result
    matches.
    """
    # List of 2-tuples of (query, expected_result)
    set_tests = {
        'foo=bar': [
            ('intersection', 'foo', 'bar'),
        ],
        'foo=bar owner=jathan': [
            ('intersection', 'foo', 'bar'),
            ('intersection', 'owner', 'jathan'),
        ],
        '-owner=gary': [
            ('difference', 'owner', 'gary'),
        ],
        'cluster +foo=baz': [
            ('intersection', 'cluster', ''),
            ('union', 'foo', 'baz'),
        ],
        # Extra white space
        'cluster=lax   +foo=baz': [
            ('intersection', 'cluster', 'lax'),
            ('union', 'foo', 'baz'),
        ],
    }

    # Make sure that result matches expected_result
    for query, expected_result in set_tests.iteritems():
        result = parse_set_query(query)
        assert result == expected_result
Exemplo n.º 4
0
def test_parse_set_query():
    """
    Parse a bunch of set queries and make sure that the expected result
    matches.
    """
    # List of 2-tuples of (query, expected_result)
    set_tests = {
        'foo=bar': [
            ('intersection', 'foo', 'bar'),
        ],
        'foo=bar owner=jathan': [
            ('intersection', 'foo', 'bar'),
            ('intersection', 'owner', 'jathan'),
        ],
        '-owner=gary': [
            ('difference', 'owner', 'gary'),
        ],
        'cluster +foo=baz': [
            ('intersection', 'cluster', ''),
            ('union', 'foo', 'baz'),
        ],
        # Extra white space
        'cluster=lax   +foo=baz': [
            ('intersection', 'cluster', 'lax'),
            ('union', 'foo', 'baz'),
        ],
    }

    # Make sure that result matches expected_result
    for query, expected_result in set_tests.iteritems():
        result = parse_set_query(query)
        assert result == expected_result
Exemplo n.º 5
0
def test_parse_set_query():
    """
    Parse a bunch of set queries and make sure that the expected result
    matches.
    """
    # List of 2-tuples of (query, expected_result)
    set_tests = {
        "foo=bar": [("intersection", "foo", "bar")],
        "foo=bar owner=jathan": [("intersection", "foo", "bar"), ("intersection", "owner", "jathan")],
        "-owner=gary": [("difference", "owner", "gary")],
        "cluster +foo=baz": [("intersection", "cluster", ""), ("union", "foo", "baz")],
        # Extra white space
        "cluster=lax   +foo=baz": [("intersection", "cluster", "lax"), ("union", "foo", "baz")],
    }

    # Make sure that result matches expected_result
    for query, expected_result in set_tests.iteritems():
        result = parse_set_query(query)
        assert result == expected_result