File: test_errors.py

package info (click to toggle)
duckdb 1.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 564
file content (99 lines) | stat: -rw-r--r-- 3,694 bytes parent folder | download | duplicates (4)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# fmt: off

import pytest
import subprocess
import sys
from typing import List
from conftest import ShellTest
import os

lineitem_ddl = 'CREATE TABLE lineitem(l_orderkey BIGINT NOT NULL, l_partkey BIGINT NOT NULL, l_suppkey BIGINT NOT NULL, l_linenumber BIGINT NOT NULL, l_quantity DECIMAL(15,2) NOT NULL, l_extendedprice DECIMAL(15,2) NOT NULL, l_discount DECIMAL(15,2) NOT NULL, l_tax DECIMAL(15,2) NOT NULL, l_returnflag VARCHAR NOT NULL, l_linestatus VARCHAR NOT NULL, l_shipdate DATE NOT NULL, l_commitdate DATE NOT NULL, l_receiptdate DATE NOT NULL, l_shipinstruct VARCHAR NOT NULL, l_shipmode VARCHAR NOT NULL, l_comment VARCHAR NOT NULL);'

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_incorrect_column(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement(lineitem_ddl)
        .statement('select * from lineitem where l_extendedpric=5;')
    )
    result = test.run()
    result.check_stderr('\x1b[31ml_extendedprice')

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_missing_table(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement(lineitem_ddl)
        .statement('select * from lineite where l_extendedprice=5;')
    )
    result = test.run()
    result.check_stderr('\x1b[31mlineitem')

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_long_error(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement(lineitem_ddl)
        .statement('''SELECT
      l_returnflag,
      l_linestatus,
      sum(l_quantity) AS sum_qty,
      sum(l_extendedprice) AS sum_base_price,
      sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price,
      sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge,
      avg(l_quantity) AS avg_qty,
      avg(l_extendedprice) AS avg_price,
      avg(l_discount) AS avg_disc,
      count(*) AS count_order
  FROM
      lineitem
  WHERE
      l_shipdate <= CAST('1998-09-02' AS date) + timestamp '2020-01-01'
  GROUP BY
      l_returnflag,
      l_linestatus
  ORDER BY
      l_returnflag,
      l_linestatus;''')
    )
    result = test.run()
    result.check_stderr('\x1b[31m')

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_single_quotes_in_error(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement("select \"I'm an error\"")
    )
    result = test.run()
    result.check_stderr('\x1b[31m')

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_double_quotes_in_error(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement("select error('''I\"m an error''')")
    )
    result = test.run()
    result.check_stderr('\x1b[31m')

@pytest.mark.skipif(os.name == 'nt', reason="Windows highlighting does not use shell escapes")
def test_unterminated_quote(shell):
    test = (
        ShellTest(shell)
        .statement(".highlight_errors on")
        .statement(".highlight_color error red bold")
        .statement("select error('I''m an error')")
    )
    result = test.run()
    result.check_stderr('I\'m an error')