Ejemplo n.º 1
0
 def test_types(self):
     catsql([
         self.workspace.number_db, "--types", "--json",
         self.workspace.output_file
     ])
     result = self.workspace.output_json()
     assert result['results'][0]['DIGIT'] == 'INTEGER'
Ejemplo n.º 2
0
 def test_csv_output(self):
     catsql([
         self.workspace.number_db, "--output", self.workspace.output_file,
         "--csv"
     ])
     assert self.workspace.output_lines() == 6
     assert len(self.workspace.output_rows()) == 5
Ejemplo n.º 3
0
 def test_json_filtered(self):
     catsql([
         self.workspace.number_db, "--column", "DIGIT", "--json",
         self.workspace.output_file
     ])
     result = self.workspace.output_json()
     assert result['count'] == 5
Ejemplo n.º 4
0
 def test_row_condition(self):
     catsql([self.workspace.number_db, "--sql", "NAME = 'one' or NAME = 'two'",
             "--output", self.workspace.output_file, "--csv"])
     result = self.workspace.output_rows()
     assert len(result) == 2
     assert result[0]['NAME'] == 'one'
     assert result[1]['NAME'] == 'two'
Ejemplo n.º 5
0
 def test_integrated(self):
     catsql([self.workspace.number_db, '--edit', '--quiet'])
     catsql([self.workspace.number_db, "--json", self.workspace.output_file,
             '--NAME', 'two'])
     result = self.workspace.output_json()
     self.assertEquals(len(result['results']), 1)
     self.assertEquals(result['results'][0]['DIGIT'], 22)
Ejemplo n.º 6
0
 def test_excel_basic(self):
     catsql([
         self.workspace.number_db, "--excel",
         self.workspace.output_file_excel
     ])
     result = self.workspace.output_excel()
     assert len(list(result.active)) == 5 + 1
Ejemplo n.º 7
0
 def test_grep(self):
     catsql([
         self.workspace.number_db, "--grep", "three", "--output",
         self.workspace.output_file, "--csv"
     ])
     result = self.workspace.output_rows()
     assert len(result) == 1
     assert result[0]['DIGIT'] == '3'
Ejemplo n.º 8
0
 def test_column_value(self):
     catsql([self.workspace.number_db, "--NAME", "one", "--output", self.workspace.output_file, "--csv"])
     assert self.workspace.output_lines() == 2
     result = self.workspace.output_rows()
     assert len(result) == 1
     result = result[0]
     assert result['NAME'] == 'one'
     assert result['DIGIT'] == '1'
Ejemplo n.º 9
0
 def test_terse_direct(self):
     catsql([self.workspace.number_db, "--terse",
             "--DIGIT", "4",
             "--json", self.workspace.output_file])
     result = self.workspace.output_json()
     assert result['count'] == 1
     assert 'NAME' in result['results'][0]
     assert 'DIGIT' not in result['results'][0]
Ejemplo n.º 10
0
 def test_row_condition(self):
     catsql([
         self.workspace.number_db, "--sql", "NAME = 'one' or NAME = 'two'",
         "--output", self.workspace.output_file, "--csv"
     ])
     result = self.workspace.output_rows()
     assert len(result) == 2
     assert result[0]['NAME'] == 'one'
     assert result[1]['NAME'] == 'two'
Ejemplo n.º 11
0
 def test_terse_kv(self):
     catsql([
         self.workspace.number_db, "--terse", "--value", "DIGIT=4",
         "--json", self.workspace.output_file
     ])
     result = self.workspace.output_json()
     assert result['count'] == 1
     assert 'NAME' in result['results'][0]
     assert 'DIGIT' not in result['results'][0]
Ejemplo n.º 12
0
 def test_sqlite_basic(self):
     catsql([
         self.workspace.number_db, "--sqlite",
         self.workspace.output_file_sql
     ])
     catsql([
         self.workspace.output_file_sql, "--json",
         self.workspace.output_file
     ])
     result = self.workspace.output_json()
     assert result['count'] == 5
Ejemplo n.º 13
0
 def test_basic(self):
     patch = self.workspace.filename('patch.diff')
     with open(patch, 'w') as fout:
         fout.write("@@,NAME,DIGIT\n"
                    "->,two,2->22\n")
     patchsql([self.workspace.number_db, '--table', 'sheet', '--patch', patch])
     catsql([self.workspace.number_db, "--json", self.workspace.output_file,
             '--NAME', 'two'])
     result = self.workspace.output_json()
     self.assertEquals(len(result['results']), 1)
     self.assertEquals(result['results'][0]['DIGIT'], 22)
Ejemplo n.º 14
0
 def test_column_value(self):
     catsql([
         self.workspace.number_db, "--NAME", "one", "--output",
         self.workspace.output_file, "--csv"
     ])
     assert self.workspace.output_lines() == 2
     result = self.workspace.output_rows()
     assert len(result) == 1
     result = result[0]
     assert result['NAME'] == 'one'
     assert result['DIGIT'] == '1'
Ejemplo n.º 15
0
 def rerun_with_csv(self, words):
     self.log("api supports single-table mode only - adapting...")
     csv = '_asql.csv'
     jcsv = '_asql.json'
     catsql([self.config['cached'], '--txt', csv])
     catsql([self.config['cached'], '--json', jcsv])
     with open(jcsv, 'r') as fin:
         table_name = json.load(fin)['meta']['name']
     self.config['cached_csv'] = csv
     self.get_service()['mode'] = 'csv'
     self.config['table_name'] = table_name
     self.store.save()
     self.run_words(words)
Ejemplo n.º 16
0
 def test_from_file_pair(self):
     f1 = self.workspace.filename('f1.csv')
     f2 = self.workspace.filename('f2.csv')
     with open(f1, 'w') as fout:
         fout.write("NAME,DIGIT\n"
                    "two,2\n")
     with open(f2, 'w') as fout:
         fout.write("NAME,DIGIT\n"
                    "two,22\n")
     patchsql([self.workspace.number_db, '--table', 'sheet', '--follow', f1, f2,
               '--quiet'])
     catsql([self.workspace.number_db, "--json", self.workspace.output_file,
             '--NAME', 'two'])
     result = self.workspace.output_json()
     self.assertEquals(len(result['results']), 1)
     self.assertEquals(result['results'][0]['DIGIT'], 22)
Ejemplo n.º 17
0
 def reconfigure(self, args):
     changed = False
     if args.verbose or not args.words:
         self.verbose = True
     self.log('settings stored in {}'.format(self.store.fname))
     if args.db or args.pull:
         reset = False
         for key in ["cached_csv", "table_name"]:
             if key in self.config:
                 del self.config[key]
                 reset = True
         if 'api' in self.config:
             for api in self.config['api'].values():
                 if 'mode' in api:
                     del api['mode']
         if args.db:
             self.config["db"] = args.db[0]
         if not self.config["db"]:
             print('Please specify database to analyze with --db')
             exit(1)
         if "cached" in self.config:
             del self.config["cached"]
             self.log('resetting cache')
         ldb = "_asql.db"
         try:
             os.remove(ldb)
         except:
             pass
         catsql([self.config['db'], '--sqlite', ldb])
         self.config["cached"] = ldb
         self.log('loaded {} to {}'.format(self.config['db'], ldb), True)
         changed = True
     if args.api or args.docker:
         if args.api:
             tag, url = args.api
         else:
             tag = args.docker[0]
             url = self.getUrlFromDocker(tag)
         if 'api' not in self.config:
             self.config['api'] = {}
         self.config['api'][tag] = {'tag': tag, 'url': url}
         self.config['tag'] = tag
         self.log('api set to {} and tagged as {}'.format(url, tag), True)
         changed = True
     if changed:
         self.store.save()
     return changed
Ejemplo n.º 18
0
 def test_sqlite_basic(self):
     catsql([self.workspace.number_db, "--sqlite", self.workspace.output_file_sql])
     catsql([self.workspace.output_file_sql, "--json", self.workspace.output_file])
     result = self.workspace.output_json()
     assert result['count'] == 5
Ejemplo n.º 19
0
 def test_types(self):
     catsql([self.workspace.number_db, "--types", "--json", self.workspace.output_file])
     result = self.workspace.output_json()
     assert result['results'][0]['DIGIT'] == 'INTEGER'
Ejemplo n.º 20
0
 def test_json_filtered(self):
     catsql([self.workspace.number_db, "--column", "DIGIT",
             "--json", self.workspace.output_file])
     result = self.workspace.output_json()
     assert result['count'] == 5
Ejemplo n.º 21
0
 def test_grep(self):
     catsql([self.workspace.number_db, "--grep", "three",
             "--output", self.workspace.output_file, "--csv"])
     result = self.workspace.output_rows()
     assert len(result) == 1
     assert result[0]['DIGIT'] == '3'
Ejemplo n.º 22
0
 def test_basic(self):
     catsql(
         [self.workspace.number_db, "--output", self.workspace.output_file])
     assert self.workspace.output_lines() == 8
Ejemplo n.º 23
0
 def test_csv_output(self):
     catsql([self.workspace.number_db, "--output", self.workspace.output_file, "--csv"])
     assert self.workspace.output_lines() == 6
     assert len(self.workspace.output_rows()) == 5
Ejemplo n.º 24
0
 def test_basic(self):
     catsql([self.workspace.number_db, "--output", self.workspace.output_file])
     assert self.workspace.output_lines() == 8