test_general.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. # from pyappveyordemo.extension import some_function
  2. from nose.tools import assert_equal
  3. def test_DeBase():
  4. "learning the ropes"
  5. assert_equal(1 , 1)
  6. def test_Basics():
  7. "create script, run script, output result, check result"
  8. import os
  9. import io
  10. from sqlite_bro import sqlite_bro
  11. app = sqlite_bro.App()
  12. app.new_db(":memory:")
  13. tmp_file = 'sqlite_bro_test_Basics.tmp'
  14. welcome_text = """
  15. create table item (ItemNo, Description,Kg , PRIMARY KEY (ItemNo));
  16. INSERT INTO item values("T","Ford",1000);
  17. INSERT INTO item select "A","Merced",1250 union all select "W","Wheel",9 ;
  18. .once '%s'
  19. select ItemNo, Description, 1000*Kg Gramm from item order by ItemNo desc;
  20. .import '%s' in_this_table""" % (tmp_file, tmp_file)
  21. app.n.new_query_tab("Welcome", welcome_text)
  22. app.run_tab()
  23. app.close_db
  24. file_encoding = sqlite_bro.guess_encoding(tmp_file)[0]
  25. with io.open(tmp_file, mode='rt', encoding=file_encoding) as f:
  26. result = f.readlines()
  27. assert_equal(len(result) , 4)
  28. assert_equal(result[-1] , "A,Merced,1250000\n")
  29. os.remove(tmp_file)