forked from markdrago/pgsanity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_ecpg.py
30 lines (24 loc) · 1.12 KB
/
test_ecpg.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
import unittest
from pgsanity import ecpg
class TestEcpg(unittest.TestCase):
def test_simple_success(self):
text = u"EXEC SQL select a from b;"
(success, msg) = ecpg.check_syntax(text)
self.assertTrue(success)
def test_simple_failure(self):
text = u"EXEC SQL garbage select a from b;"
(success, msg) = ecpg.check_syntax(text)
self.assertFalse(success)
self.assertEqual('line 1: ERROR: unrecognized data type name "garbage"', msg)
def test_empty_sql_okay(self):
text = u"EXEC SQL ;"
(success, msg) = ecpg.check_syntax(text)
self.assertTrue(success)
def test_parse_error_simple(self):
error = '/tmp/tmpLBKZo5.pgc:1: ERROR: unrecognized data type name "garbage"'
expected = 'line 1: ERROR: unrecognized data type name "garbage"'
self.assertEqual(expected, ecpg.parse_error(error))
def test_parse_error_comments(self):
error = '/tmp/tmpLBKZo5.pgc:5: ERROR: syntax error at or near "//"'
expected = 'line 5: ERROR: syntax error at or near "--"'
self.assertEqual(expected, ecpg.parse_error(error))