Skip to content

Commit

Permalink
Switch from zope.testrunner to stock unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 1, 2019
1 parent e10d0c2 commit 6c897f4
Show file tree
Hide file tree
Showing 13 changed files with 202 additions and 283 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ before_install:

install:
- python bootstrap.py
- bin/buildout install scripts crate test linter
- bin/buildout install scripts crate linter

script:
- bin/flake8
- bin/coverage run bin/test
- bin/coverage run bin/py -m unittest

after_success:
- PATH=$PATH:bin/ bin/codecov # codecov executes coverage which needs to be in $PATH
Expand Down
4 changes: 2 additions & 2 deletions DEVELOP.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Then to run your local crash, use::
Running Tests
=============

The tests are run using the `zope.testrunner`_::
The tests are run using the `unittest`_::

$ ./bin/test
$ ./bin/py -m unittest

This will run all tests using the Python interpreter that was used to bootstrap
buildout.
Expand Down
12 changes: 2 additions & 10 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ develop = .
extends = versions.cfg
versions = versions
show-picked-versions = true
parts = test
scripts
parts = scripts
crate
omelette
tox
Expand All @@ -14,7 +13,7 @@ parts = test
[scripts]
recipe = zc.recipe.egg:script
interpreter = py
eggs = crash
eggs = crash [test]
wheel
codecov
coverage
Expand All @@ -26,13 +25,6 @@ url = https://cdn.crate.io/downloads/releases/crate-${versions:crate_server}.tar
strip-top-level-dir = true
ignore-existing = true

[test]
relative-paths=true
recipe = zc.recipe.testrunner
working-directory = ${buildout:directory}/docs
defaults = ['--auto-color']
eggs = crash [test]

[linter]
recipe = zc.recipe.egg:script
eggs = flake8
Expand Down
129 changes: 0 additions & 129 deletions crate/crash/tests.py

This file was deleted.

8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def read(path):
]
},
extras_require=dict(
test=['crate[test]',
'zc.customdoctests',
'zope.testing',
],
test=[
'crate[test]',
'zc.customdoctests'
],
argcompletion=['argcomplete']
),
python_requires='>=3.4',
Expand Down
Empty file added tests/__init__.py
Empty file.
107 changes: 107 additions & 0 deletions tests/test_command.py
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)
15 changes: 10 additions & 5 deletions crate/crash/test_commands.py → tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@

from unittest import TestCase
from unittest.mock import patch, MagicMock
from .commands import ReadFileCommand, \
ToggleAutocompleteCommand, ToggleAutoCapitalizeCommand, ToggleVerboseCommand, \
NodeCheckCommand, ClusterCheckCommand, CheckCommand

from .command import CrateShell
from distutils.version import StrictVersion
from crate.crash.commands import (
ReadFileCommand,
ToggleAutocompleteCommand,
ToggleAutoCapitalizeCommand,
ToggleVerboseCommand,
NodeCheckCommand,
ClusterCheckCommand,
CheckCommand
)
from crate.crash.command import CrateShell


class ReadFileCommandTest(TestCase):
Expand Down
9 changes: 3 additions & 6 deletions crate/crash/test_config.py → tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@

import os
import tempfile
import configparser
from unittest import TestCase
try:
import configparser
except ImportError:
import ConfigParser as configparser
from .config import Configuration, ConfigurationError
from .command import parse_config_path, CONFIG_PATH
from crate.crash.config import Configuration, ConfigurationError
from crate.crash.command import parse_config_path, CONFIG_PATH


class ConfigurationTest(TestCase):
Expand Down
Loading

0 comments on commit 6c897f4

Please sign in to comment.