File: expanded.py

package info (click to toggle)
pgcli 1.9.1-3%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 912 kB
  • sloc: python: 7,364; makefile: 6
file content (60 lines) | stat: -rw-r--r-- 1,854 bytes parent folder | download
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
# -*- coding: utf-8
"""Steps for behavioral style tests are defined in this module.

Each step is defined by the string decorating it. This string is used
to call the step in "*.feature" file.

"""
from __future__ import unicode_literals

import wrappers
from behave import when, then
from textwrap import dedent


@when('we prepare the test data')
def step_prepare_data(context):
    """Create table, insert a record."""
    context.cli.sendline('drop table if exists a;')
    wrappers.wait_prompt(context)
    context.cli.sendline(
        'create table a(x integer, y real, z numeric(10, 4));')
    wrappers.expect_pager(context, 'CREATE TABLE\r\n', timeout=2)
    context.cli.sendline('''insert into a(x, y, z) values(1, 1.0, 1.0);''')
    wrappers.expect_pager(context, 'INSERT 0 1\r\n', timeout=2)


@when('we set expanded {mode}')
def step_set_expanded(context, mode):
    """Set expanded to mode."""
    context.cli.sendline('\\' + 'x {}'.format(mode))
    wrappers.expect_exact(context, 'Expanded display is', timeout=2)
    wrappers.wait_prompt(context)


@then('we see {which} data selected')
def step_see_data(context, which):
    """Select data from expanded test table."""
    if which == 'expanded':
        wrappers.expect_pager(
            context,
            dedent('''\
                -[ RECORD 1 ]-------------------------\r
                x | 1\r
                y | 1.0\r
                z | 1.0000\r
                SELECT 1\r
            '''),
            timeout=1)
    else:
        wrappers.expect_pager(
            context,
            dedent('''\
                +-----+-----+--------+\r
                | x   | y   | z      |\r
                |-----+-----+--------|\r
                | 1   | 1.0 | 1.0000 |\r
                +-----+-----+--------+\r
                SELECT 1\r
            '''),
            timeout=1)