Skip to content

Commit 80812a9

Browse files
committed
Create test_general_no_gui.py
1 parent e10747f commit 80812a9

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# from pyappveyordemo.extension import some_function
2+
import pytest
3+
import pathlib
4+
import tempfile
5+
6+
import io
7+
from sqlite_bro import sqlite_bro
8+
app = sqlite_bro.App(use_gui=False)
9+
def test_DeBase():
10+
"learning the ropes"
11+
assert 1 == 1
12+
13+
14+
def test_Basics():
15+
"create script, run script, output result, check result"
16+
app.new_db(":memory:")
17+
with tempfile.TemporaryDirectory(prefix='.tmp') as tmp_dir:
18+
print(tmp_dir)
19+
tmp_file = str(pathlib.PurePath(tmp_dir, 'sqlite_bro_test_Basics.tmp'))
20+
welcome_text = """
21+
create table item (ItemNo, Description,Kg , PRIMARY KEY (ItemNo));
22+
INSERT INTO item values("T","Ford",1000);
23+
INSERT INTO item select "A","Merced",1250 union all select "W","Wheel",9 ;
24+
.once %s
25+
select ItemNo, Description, 1000*Kg Gramm from item order by ItemNo desc;
26+
.import %s in_this_table""" % (tmp_file, tmp_file)
27+
app.n.new_query_tab("Welcome", welcome_text)
28+
app.run_tab()
29+
app.close_db
30+
31+
file_encoding = sqlite_bro.guess_encoding(tmp_file)[0]
32+
with io.open(tmp_file, mode='rt', encoding=file_encoding) as f:
33+
result = f.readlines()
34+
assert len(result) == 4
35+
assert result[-1] == "A,Merced,1250000\n"
36+
37+
def test_Outputs():
38+
"testing .output, .print, .header, .separator"
39+
40+
app.new_db(":memory:")
41+
with tempfile.TemporaryDirectory(prefix='.tmp') as tmp_dir:
42+
print(tmp_dir)
43+
tmp_file = str(pathlib.PurePath(tmp_dir, 'sqlite_bro_test_Output.tmp'))
44+
welcome_text = """
45+
create table item (ItemNo, Description , PRIMARY KEY (ItemNo));
46+
INSERT INTO item values("DS","Citroën");
47+
.output %s
48+
.separator ;
49+
.headers off
50+
.print a;b
51+
select * from item;
52+
.headers on
53+
.separator !
54+
select * from item;
55+
.import %s in_this_table""" % (tmp_file, tmp_file)
56+
app.n.new_query_tab("Welcome", welcome_text)
57+
app.run_tab()
58+
app.close_db
59+
60+
file_encoding = sqlite_bro.guess_encoding(tmp_file)[0]
61+
with io.open(tmp_file, mode='rt', encoding=file_encoding) as f:
62+
result = f.readlines()
63+
print(result)
64+
assert len(result) == 4
65+
assert result[0] == "a;b\n"
66+
assert result[1] == "DS;Citroën\n"
67+
assert result[2] == "ItemNo!Description\n"
68+
assert result[3] == "DS!Citroën\n"

0 commit comments

Comments
 (0)