summaryrefslogtreecommitdiffstats
path: root/tests/test_serde.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-17 10:32:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-17 10:32:12 +0000
commit244a05de60c9417daab9528b51788c3d2a00dc5f (patch)
tree89a9c82aa41d397e1b81c320ad7a287b6c80f313 /tests/test_serde.py
parentAdding upstream version 10.4.2. (diff)
downloadsqlglot-244a05de60c9417daab9528b51788c3d2a00dc5f.tar.xz
sqlglot-244a05de60c9417daab9528b51788c3d2a00dc5f.zip
Adding upstream version 10.5.2.upstream/10.5.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_serde.py')
-rw-r--r--tests/test_serde.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_serde.py b/tests/test_serde.py
new file mode 100644
index 0000000..603a155
--- /dev/null
+++ b/tests/test_serde.py
@@ -0,0 +1,33 @@
+import json
+import unittest
+
+from sqlglot import exp, parse_one
+from sqlglot.optimizer.annotate_types import annotate_types
+from tests.helpers import load_sql_fixtures
+
+
+class CustomExpression(exp.Expression):
+ ...
+
+
+class TestSerDe(unittest.TestCase):
+ def dump_load(self, expression):
+ return exp.Expression.load(json.loads(json.dumps(expression.dump())))
+
+ def test_serde(self):
+ for sql in load_sql_fixtures("identity.sql"):
+ with self.subTest(sql):
+ before = parse_one(sql)
+ after = self.dump_load(before)
+ self.assertEqual(before, after)
+
+ def test_custom_expression(self):
+ before = CustomExpression()
+ after = self.dump_load(before)
+ self.assertEqual(before, after)
+
+ def test_type_annotations(self):
+ before = annotate_types(parse_one("CAST('1' AS INT)"))
+ after = self.dump_load(before)
+ self.assertEqual(before.type, after.type)
+ self.assertEqual(before.this.type, after.this.type)