-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from zope.testrunner to stock unittest
- Loading branch information
1 parent
e10d0c2
commit 6c897f4
Showing
13 changed files
with
202 additions
and
283 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
This file was deleted.
Oops, something went wrong.
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
# vim: set fileencodings=utf-8 | ||
|
||
from unittest import TestCase | ||
|
||
from crate.crash.command import ( | ||
Result, | ||
host_and_port, | ||
stmt_type, | ||
get_information_schema_query | ||
) | ||
from crate.crash.outputs import OutputWriter | ||
from distutils.version import StrictVersion | ||
|
||
|
||
class OutputWriterTest(TestCase): | ||
|
||
def setUp(self): | ||
self.ow = OutputWriter(writer=None, is_tty=False) | ||
|
||
def test_mixed_format_float_precision(self): | ||
expected = 'foo | 152462.70754934277' | ||
result = Result(cols=['foo'], | ||
rows=[[152462.70754934277]], | ||
rowcount=1, | ||
duration=1, | ||
output_width=80) | ||
self.assertEqual( | ||
next(self.ow.mixed(result)).rstrip(), expected) | ||
|
||
def test_mixed_format_utf8(self): | ||
expected = 'name | Großvenediger' | ||
result = Result(cols=['name'], | ||
rows=[['Großvenediger']], | ||
rowcount=1, | ||
duration=1, | ||
output_width=80) | ||
self.assertEqual( | ||
next(self.ow.mixed(result)).rstrip(), expected) | ||
|
||
def test_tabular_format_float_precision(self): | ||
expected = '152462.70754934277' | ||
|
||
result = Result(cols=['foo'], | ||
rows=[[152462.70754934277]], | ||
rowcount=1, | ||
duration=1, | ||
output_width=80) | ||
|
||
# output is | ||
# +--- | ||
# | header | ||
# +---- | ||
# | value | ||
# get the row with the value in it | ||
output = self.ow.tabular(result).split('\n')[3] | ||
self.assertEqual( | ||
output.strip('|').strip(' '), expected) | ||
|
||
|
||
class CommandLineArgumentsTest(TestCase): | ||
|
||
def test_short_hostnames(self): | ||
# both host and port are provided | ||
self.assertEqual(host_and_port('localhost:4321'), 'localhost:4321') | ||
# only host is provided | ||
# default port is used | ||
self.assertEqual(host_and_port('localhost'), 'localhost:4200') | ||
# only port is provided | ||
# localhost is used | ||
self.assertEqual(host_and_port(':4000'), 'localhost:4000') | ||
# neither host nor port are provided | ||
# default host and default port are used | ||
self.assertEqual(host_and_port(':'), 'localhost:4200') | ||
|
||
|
||
class CommandUtilsTest(TestCase): | ||
|
||
def test_stmt_type(self): | ||
# regular multi word statement | ||
self.assertEqual(stmt_type('SELECT 1;'), 'SELECT') | ||
# regular single word statement | ||
self.assertEqual(stmt_type('BEGIN;'), 'BEGIN') | ||
# statements with trailing or leading spaces/tabs/linebreaks | ||
self.assertEqual(stmt_type(' SELECT 1 ;'), 'SELECT') | ||
self.assertEqual(stmt_type('\nSELECT\n1\n;\n'), 'SELECT') | ||
|
||
|
||
class TestGetInformationSchemaQuery(TestCase): | ||
|
||
def test_low_version(self): | ||
lowest_server_version = StrictVersion("0.56.4") | ||
query = get_information_schema_query(lowest_server_version) | ||
self.assertEqual(""" select count(distinct(table_name)) | ||
as number_of_tables | ||
from information_schema.tables | ||
where schema_name | ||
not in ('information_schema', 'sys', 'pg_catalog') """, query) | ||
|
||
def test_high_version(self): | ||
lowest_server_version = StrictVersion("1.0.4") | ||
query = get_information_schema_query(lowest_server_version) | ||
self.assertEqual(""" select count(distinct(table_name)) | ||
as number_of_tables | ||
from information_schema.tables | ||
where table_schema | ||
not in ('information_schema', 'sys', 'pg_catalog') """, query) |
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
Oops, something went wrong.