forked from dbcli/mssql-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed broken unit tests in 'test_sqlcompletion.py' and made non-class…
… type unit tests into class type (dbcli#261)
- Loading branch information
Gene Lee
authored
Aug 7, 2019
1 parent
34278ab
commit bb5c459
Showing
5 changed files
with
987 additions
and
944 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
from mssqlcli.packages.prioritization import PrevalenceCounter | ||
import unittest | ||
|
||
class PrioritizationTests(unittest.TestCase): | ||
|
||
def test_prevalence_counter(): | ||
counter = PrevalenceCounter() | ||
sql = '''SELECT * FROM foo WHERE bar GROUP BY baz; | ||
select * from foo; | ||
SELECT * FROM foo WHERE bar GROUP | ||
BY baz''' | ||
counter.update(sql) | ||
def test_prevalence_counter(self): | ||
counter = PrevalenceCounter() | ||
sql = '''SELECT * FROM foo WHERE bar GROUP BY baz; | ||
select * from foo; | ||
SELECT * FROM foo WHERE bar GROUP | ||
BY baz''' | ||
counter.update(sql) | ||
|
||
keywords = ['SELECT', 'FROM', 'GROUP BY'] | ||
expected = [3, 3, 2] | ||
kw_counts = [counter.keyword_count(x) for x in keywords] | ||
assert kw_counts == expected | ||
assert counter.keyword_count('NOSUCHKEYWORD') == 0 | ||
keywords = ['SELECT', 'FROM', 'GROUP BY'] | ||
expected = [3, 3, 2] | ||
kw_counts = [counter.keyword_count(x) for x in keywords] | ||
assert kw_counts == expected | ||
assert counter.keyword_count('NOSUCHKEYWORD') == 0 | ||
|
||
names = ['foo', 'bar', 'baz'] | ||
name_counts = [counter.name_count(x) for x in names] | ||
assert name_counts == [3, 2, 2] | ||
names = ['foo', 'bar', 'baz'] | ||
name_counts = [counter.name_count(x) for x in names] | ||
assert name_counts == [3, 2, 2] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,44 @@ | ||
import unittest | ||
from mssqlcli.mssql_cli import MssqlCli | ||
from mssqltestutils import create_mssql_cli_options | ||
|
||
|
||
DEFAULT_OPTIONS = create_mssql_cli_options() | ||
DEFAULT = MssqlCli(DEFAULT_OPTIONS).row_limit | ||
LIMIT = DEFAULT + 1000 | ||
|
||
low_count = 1 | ||
over_default = DEFAULT + 1 | ||
over_limit = LIMIT + 1 | ||
|
||
|
||
def test_default_row_limit(): | ||
cli = MssqlCli(DEFAULT_OPTIONS) | ||
stmt = "SELECT * FROM students" | ||
result = cli._should_show_limit_prompt(stmt, ['row']*low_count) | ||
assert result is False | ||
|
||
result = cli._should_show_limit_prompt(stmt, ['row']*over_default) | ||
assert result is True | ||
|
||
|
||
def test_set_row_limit(): | ||
cli_options = create_mssql_cli_options(row_limit=LIMIT) | ||
cli = MssqlCli(cli_options) | ||
stmt = "SELECT * FROM students" | ||
result = cli._should_show_limit_prompt(stmt, ['row']*over_default) | ||
assert result is False | ||
|
||
result = cli._should_show_limit_prompt(stmt, ['row']*over_limit) | ||
assert result is True | ||
|
||
|
||
def test_no_limit(): | ||
cli_options = create_mssql_cli_options(row_limit=0) | ||
cli = MssqlCli(cli_options) | ||
assert cli.row_limit is 0 | ||
stmt = "SELECT * FROM students" | ||
|
||
result = cli._should_show_limit_prompt(stmt, ['row']*over_limit) | ||
assert result is False | ||
|
||
|
||
def test_row_limit_on_non_select(): | ||
cli = MssqlCli(DEFAULT_OPTIONS) | ||
stmt = "UPDATE students set name='Boby'" | ||
result = cli._should_show_limit_prompt(stmt, None) | ||
assert result is False | ||
|
||
cli_options = create_mssql_cli_options(row_limit=0) | ||
assert cli_options.row_limit is 0 | ||
cli = MssqlCli(cli_options) | ||
result = cli._should_show_limit_prompt(stmt, ['row']*over_default) | ||
assert cli.row_limit is 0 | ||
assert result is False | ||
class RowLimitTests(unittest.TestCase): | ||
|
||
DEFAULT_OPTIONS = create_mssql_cli_options() | ||
DEFAULT = MssqlCli(DEFAULT_OPTIONS).row_limit | ||
LIMIT = DEFAULT + 1000 | ||
|
||
low_count = 1 | ||
over_default = DEFAULT + 1 | ||
over_limit = LIMIT + 1 | ||
|
||
def test_default_row_limit(self): | ||
cli = MssqlCli(self.DEFAULT_OPTIONS) | ||
stmt = "SELECT * FROM students" | ||
result = cli._should_show_limit_prompt(stmt, ['row']*self.low_count) | ||
assert result is False | ||
|
||
result = cli._should_show_limit_prompt(stmt, ['row']*self.over_default) | ||
assert result is True | ||
|
||
def test_no_limit(self): | ||
cli_options = create_mssql_cli_options(row_limit=0) | ||
cli = MssqlCli(cli_options) | ||
assert cli.row_limit is 0 | ||
stmt = "SELECT * FROM students" | ||
|
||
result = cli._should_show_limit_prompt(stmt, ['row']*self.over_limit) | ||
assert result is False | ||
|
||
def test_row_limit_on_non_select(self): | ||
cli = MssqlCli(self.DEFAULT_OPTIONS) | ||
stmt = "UPDATE students set name='Boby'" | ||
result = cli._should_show_limit_prompt(stmt, None) | ||
assert result is False | ||
|
||
cli_options = create_mssql_cli_options(row_limit=0) | ||
assert cli_options.row_limit is 0 | ||
cli = MssqlCli(cli_options) | ||
result = cli._should_show_limit_prompt(stmt, ['row']*self.over_default) | ||
assert cli.row_limit is 0 | ||
assert result is False |
Oops, something went wrong.