Skip to content

Commit

Permalink
Merge pull request #15 from thombashi/develop
Browse files Browse the repository at this point in the history
Fix failed to conversion
  • Loading branch information
thombashi authored Sep 19, 2016
2 parents de822d0 + 0bd3067 commit a36484e
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 14 deletions.
16 changes: 16 additions & 0 deletions docs/pages/usage/common.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
``sqlitebiter`` command help
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

::

Usage: sqlitebiter [OPTIONS] COMMAND [ARGS]...

Options:
--version Show the version and exit.
--debug for debug print.
--quiet suppress execution log messages.
-h, --help Show this message and exit.

Commands:
file Convert CSV/Excel/HTML/JSON file(s) to a...
gs Convert Google Sheets to a SQLite database...
2 changes: 1 addition & 1 deletion docs/pages/usage/file/header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Create a SQLite database from CSV/JSON/Excel
-----------------------------------------------------------

``sqlitebiter file`` is a subcommand to convert
CSV/JSON/Excel file(s) to a SQLite database file.
CSV/Excel/HTML/JSON file(s) to a SQLite database file.
1 change: 1 addition & 0 deletions docs/pages/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Usage
.. toctree::
:maxdepth: 3

common
file/index
gs/index
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
click
DataProperty>=0.8.1
DataProperty>=0.9.0
logbook
path.py
SimpleSQLite>=0.5.1
SimpleSQLite>=0.5.5
2 changes: 1 addition & 1 deletion sqlitebiter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "0.2.0"
VERSION = "0.2.1"
6 changes: 3 additions & 3 deletions sqlitebiter/sqlitebiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ def file(ctx, files, output_path):

try:
for tabledata in loader.load():
click.echo("convert '{:s}' to '{:s}' table".format(
file_path, tabledata.table_name))

try:
con.create_table_from_tabledata(tabledata)
result_counter.inc_success()
Expand All @@ -142,6 +139,9 @@ def file(ctx, files, output_path):
"path={:s}, message={:s}".format(file_path, e))
result_counter.inc_fail()
continue

click.echo("convert '{:s}' to '{:s}' table".format(
file_path, tabledata.table_name))
except OpenError as e:
logger.error(e)
except ValidationError as e:
Expand Down
1 change: 0 additions & 1 deletion test/test_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
"""


import pytest
from sqlitebiter._counter import ResultCounter

Expand Down
68 changes: 62 additions & 6 deletions test/test_sqlitebiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
"""


import click
from click.testing import CliRunner
import path
import pytest
import simplesqlite
import xlsxwriter

from sqlitebiter.sqlitebiter import cmd
from simplesqlite.loader.interface import TableLoader


def valid_json_single_file():
Expand Down Expand Up @@ -69,7 +68,7 @@ def invalid_json_multi_file():
return file_path


def csv_file():
def valid_csv_file():
file_path = "csv_a.csv"
with open(file_path, "w") as f:
f.write("\n".join([
Expand All @@ -82,6 +81,21 @@ def csv_file():
return file_path


def valid_csv_file2():
# reserved keywod of SQLite

file_path = "insert.csv"
with open(file_path, "w") as f:
f.write("\n".join([
'"attr_a","attr_b","attr_c"',
'1,4,"a"',
'2,2.1,"bb"',
'3,120.9,"ccc"',
]))

return file_path


def valid_excel_file():
file_path = "valid.xlsx"
workbook = xlsxwriter.Workbook(str(file_path))
Expand Down Expand Up @@ -225,6 +239,9 @@ def invalid_html_file():

class Test_sqlitebiter:

def setup_method(self, method):
TableLoader.clear_table_count()

@pytest.mark.parametrize(["option_list", "expected"], [
[["-h"], 0],
[["file", "-h"], 0],
Expand All @@ -235,7 +252,44 @@ def test_help(self, option_list, expected):
result = runner.invoke(cmd, option_list)
assert result.exit_code == 0

def test_normal(self):
def test_normal_smoke(self):
db_path = "test.sqlite"
runner = CliRunner()

with runner.isolated_filesystem():
file_list = [
valid_json_single_file(),
valid_json_multi_file(),
valid_csv_file(),
valid_csv_file2(),
valid_excel_file(),
valid_html_file(),
]

for file_path in file_list:
result = runner.invoke(
cmd, ["file", file_path, "-o", db_path])
assert result.exit_code == 0, file_path

def test_abnormal_smoke(self):
db_path = "test.sqlite"
runner = CliRunner()

with runner.isolated_filesystem():
file_list = [
invalid_json_single_file(),
invalid_json_multi_file(),
invalid_excel_file(),
invalid_excel_file2(),
invalid_html_file(),
]

for file_path in file_list:
result = runner.invoke(
cmd, ["file", file_path, "-o", db_path])
assert result.exit_code != 0, file_path

def test_normal_multi(self):
db_path = "test.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
Expand All @@ -246,7 +300,8 @@ def test_normal(self):
valid_json_multi_file(),
invalid_json_multi_file(),

csv_file(),
valid_csv_file(),
valid_csv_file2(),

valid_excel_file(),
invalid_excel_file(),
Expand All @@ -262,7 +317,7 @@ def test_normal(self):
con = simplesqlite.SimpleSQLite(db_path, "r")
expected_tables = [
'singlejson_json1', 'multijson_table1', 'multijson_table2',
'csv_a',
'csv_a', "insert_csv",
'excel_sheet_a', 'excel_sheet_c', 'excel_sheet_d',
'htmltable_tablename', 'htmltable_html2',
]
Expand All @@ -280,6 +335,7 @@ def test_normal(self):
"multijson_table2":
[(1, '4'), (2, 'NULL'), (3, '120.9')],
"csv_a": [(1, 4.0, 'a'), (2, 2.1, 'bb'), (3, 120.9, 'ccc')],
"insert_csv": [(1, 4.0, 'a'), (2, 2.1, 'bb'), (3, 120.9, 'ccc')],
"excel_sheet_a":
[(1.0, 1.1, 'a'), (2.0, 2.2, 'bb'), (3.0, 3.3, 'cc')],
"excel_sheet_c":
Expand Down

0 comments on commit a36484e

Please sign in to comment.