-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_gadwall.py
77 lines (61 loc) · 1.61 KB
/
test_gadwall.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
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
from unittest.mock import MagicMock
import gadwall
def test_init():
file_name = ':memory:'
cmd = gadwall.Gadwall(file_name)
assert file_name == cmd.file_name
assert cmd.conn
def test_eof():
cmd = gadwall.Gadwall(':memory:')
cmd.do_quit = MagicMock()
cmd.do_EOF('')
assert cmd.do_quit.called
def test_quit():
cmd = gadwall.Gadwall(':memory:')
cmd.conn = MagicMock()
cmd.do_quit('')
assert cmd.conn.close.called
def test_schema(capsys):
cmd = gadwall.Gadwall(':memory:')
cmd.conn.execute('''
CREATE TABLE points (
x INTEGER,
y INTEGER
);
CREATE TABLE users (
login TEXT,
id INTEGER
);
''')
cmd.conn.commit()
cmd.do_schema('')
captured = capsys.readouterr()
for table in ('points', 'users'):
assert table in captured.out
cmd.do_schema('users')
captured = capsys.readouterr()
for col in ('login', 'id'):
assert col in captured.out
def test_default(capsys):
cmd = gadwall.Gadwall(':memory:')
cmd.conn.execute('''
CREATE TABLE points (
x INTEGER,
y INTEGER
);
''')
n = 10
cmd.conn.executemany(
'INSERT INTO points (x, y) VALUES (?, ?)',
((i, i) for i in range(n)),
)
cmd.default('SELECT * FROM points')
captured = capsys.readouterr()
expected = [f'{i} {i}' for i in range(n)]
assert expected == captured.out.splitlines()
def test_db(capsys):
file_name = ':memory:'
cmd = gadwall.Gadwall(file_name)
cmd.do_db('')
captured = capsys.readouterr()
assert file_name == captured.out.strip()