Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_scan_literal():
text = "unquoted_literal"
token = lkml.Lexer(text).scan_literal()
assert token == tokens.LiteralToken("unquoted_literal", 1)
def test_parse_list_with_literals():
stream = (
tokens.LiteralToken("drill_fields", 1),
tokens.ValueToken(1),
tokens.ListStartToken(1),
tokens.LiteralToken("view_name.field_one", 1),
tokens.CommaToken(1),
tokens.LiteralToken("view_name.field_two", 1),
tokens.CommaToken(1),
tokens.LiteralToken("view_name.field_three", 1),
tokens.ListEndToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_list()
assert result == {
"drill_fields": [
"view_name.field_one",
"view_name.field_two",
def test_parse_pair_without_value_token():
stream = (
tokens.LiteralToken("hidden", 1),
tokens.LiteralToken("yes", 1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_pair()
assert result is None
def test_parse_block_with_no_expression():
stream = (
tokens.LiteralToken("dimension", 1),
tokens.ValueToken(1),
tokens.LiteralToken("dimension_name", 1),
tokens.BlockStartToken(1),
tokens.BlockEndToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_block()
assert result == {"dimension": {"name": "dimension_name"}}
def test_parse_value_quoted_literal_with_leftovers():
quoted_literal = "This is a quoted literal."
literal = "Some other tokens following."
stream = (
tokens.QuotedLiteralToken(quoted_literal, 1),
tokens.LiteralToken(literal, 1),
tokens.ValueToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_value()
assert result == quoted_literal
assert parser.index == 1
def test_parse_list_with_trailing_comma():
stream = (
tokens.LiteralToken("drill_fields", 1),
tokens.ValueToken(1),
tokens.ListStartToken(1),
tokens.LiteralToken("view_name.field_one", 1),
tokens.CommaToken(1),
tokens.ListEndToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_list()
assert result == {"drill_fields": ["view_name.field_one"]}
def test_parse_pair_with_sql_block():
sql = "SELECT * FROM schema.table"
stream = (
tokens.LiteralToken("sql", 1),
tokens.ValueToken(1),
tokens.LiteralToken(sql, 1),
tokens.ExpressionBlockEndToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_pair()
assert result == {"sql": sql}
def test_parse_list_with_no_opening_bracket():
stream = (
tokens.LiteralToken("drill_fields", 1),
tokens.ValueToken(1),
tokens.LiteralToken("view_name.field_one", 1),
tokens.CommaToken(1),
tokens.LiteralToken("view_name.field_two", 1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_list()
assert result is None
def test_parse_value_literal_with_sql_block():
literal = "SELECT * FROM tablename"
stream = (
tokens.LiteralToken(literal, 1),
tokens.ExpressionBlockEndToken(1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_value()
assert result == literal
def test_parse_list_with_no_opening_bracket():
stream = (
tokens.LiteralToken("drill_fields", 1),
tokens.ValueToken(1),
tokens.LiteralToken("view_name.field_one", 1),
tokens.CommaToken(1),
tokens.LiteralToken("view_name.field_two", 1),
tokens.StreamEndToken(1),
)
parser = lkml.parser.Parser(stream)
result = parser.parse_list()
assert result is None