-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_malloy.py
40 lines (34 loc) · 993 Bytes
/
test_malloy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import ast
import random
import textwrap
import unittest
from .mock_user import UserQuery
class MalloyTests(unittest.TestCase):
def setUp(self):
random.seed(100)
self.maxDiff = None
def test_project(self):
malloy_q = (
UserQuery(range(1, 10))
.project([":id", "name"])
.where(ast.Expr("user.age >= 16"))
.order_by(ast.Expr("user.age"))
.take(3)
.to_malloy()
)
expected = textwrap.dedent(
"""\
run: duckdb.table('user') -> {
select: id, name
where: user.age >= 16
order_by: user.age
limit: 3
}"""
)
self.assertEqual(expected, malloy_q)
if __name__ == "__main__":
unittest.main()