Skip to content

Commit 9ac69b3

Browse files
committed
more CI test
.output, .separator, .headers, .print
1 parent f479df0 commit 9ac69b3

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

sqlite_bro/tests/test_general.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@
33
import pathlib
44
import tempfile
55

6-
6+
import io
7+
from sqlite_bro import sqlite_bro
8+
app = sqlite_bro.App()
79
def test_DeBase():
810
"learning the ropes"
911
assert 1 == 1
1012

1113

1214
def test_Basics():
1315
"create script, run script, output result, check result"
14-
# import os
15-
import io
16-
from sqlite_bro import sqlite_bro
17-
app = sqlite_bro.App()
1816
app.new_db(":memory:")
1917
with tempfile.TemporaryDirectory(prefix='.tmp') as tmp_dir:
2018
print(tmp_dir)
21-
# use temp_dir, and when done:
22-
# tmp_dir.cleanup()
2319
tmp_file = str(pathlib.PurePath(tmp_dir, 'sqlite_bro_test_Basics.tmp'))
2420
welcome_text = """
2521
create table item (ItemNo, Description,Kg , PRIMARY KEY (ItemNo));
@@ -37,4 +33,36 @@ def test_Basics():
3733
result = f.readlines()
3834
assert len(result) == 4
3935
assert result[-1] == "A,Merced,1250000\n"
40-
# os.remove(tmp_file)
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)